Skip to main content

swiss-truth-llamaindex

LlamaIndex ToolSpec & Retriever for Swiss Truth — certified knowledge base for AI agents.

PyPI Python LlamaIndex LlamaHub EU AI Act License: MIT

Stop your LlamaIndex agents from hallucinating. Ground every response in 3,000+ certified facts across 38 domains in 10 languages — verified by Swiss Truth.


Installation

pip install swiss-truth-llamaindex

Quick Start

Option 1 — ToolSpec (LlamaHub-compatible, recommended)

from swiss_truth_llamaindex import SwissTruthToolSpec
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

# Create the ToolSpec and convert to LlamaIndex tools
spec = SwissTruthToolSpec()
tools = spec.to_tool_list()

# Build a ReAct agent with Swiss Truth grounding
agent = ReActAgent.from_tools(
    tools,
    llm=OpenAI(model="gpt-4o"),
    verbose=True,
)

response = agent.chat("Is health insurance mandatory in Switzerland?")
print(response)

Option 2 — Individual FunctionTools

from swiss_truth_llamaindex import get_all_tools
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

tools = get_all_tools()
agent = ReActAgent.from_tools(tools, llm=OpenAI(model="gpt-4o"), verbose=True)
response = agent.chat("What is the EU AI Act risk classification?")
print(response)

Option 3 — RAG Retriever

from swiss_truth_llamaindex import SwissTruthRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.llms.openai import OpenAI

# Domain-scoped retriever
retriever = SwissTruthRetriever(domain="swiss-law", limit=8)

# Use directly
nodes = retriever.retrieve("Is health insurance mandatory in Switzerland?")
for node in nodes:
    print(f"[{node.score:.2f}] {node.node.text}")

# Or plug into a query engine
engine = RetrieverQueryEngine.from_args(
    retriever,
    llm=OpenAI(model="gpt-4o"),
)
response = engine.query("What are the Swiss health insurance rules?")
print(response)

Available Tools

All 9 tools are available via SwissTruthToolSpec and as individual FunctionTool instances:

Tool Description
search Search the certified knowledge base for verified facts
verify Verify a single factual claim (VERIFIED / UNVERIFIED / CONTRADICTED)
submit Submit a new claim for expert review
list_domains List all 38 available knowledge domains
claim_status Get the verification status of a claim by UUID
batch_verify Verify multiple claims in a single API call
verify_response Fact-check an entire LLM response, get hallucination risk score
find_contradictions Detect internal contradictions in a block of text
get_compliance Generate an EU AI Act compliance report

API Key

No API key is required for public endpoints. For higher rate limits or private domains, pass your key:

spec = SwissTruthToolSpec(api_key="your-key")
retriever = SwissTruthRetriever(api_key="your-key")

Advanced Usage

Custom client

from swiss_truth_llamaindex import SwissTruthClient, get_all_tools

client = SwissTruthClient(api_key="your-key", timeout=60.0)
tools = get_all_tools(client=client)

Hallucination guard for LLM responses

from swiss_truth_llamaindex import SwissTruthToolSpec

spec = SwissTruthToolSpec()

# After your LLM generates a response, fact-check it:
result = spec.verify_response(
    response_text="Switzerland has 9 million inhabitants and joined the EU in 2002.",
    domain="swiss-facts",
)
print(result)
# → {"hallucination_risk": "HIGH", "claims": [...], "contradicted": [...]}

EU AI Act compliance report

from swiss_truth_llamaindex import SwissTruthToolSpec

spec = SwissTruthToolSpec()
report = spec.get_compliance(domain="ai-ml")
print(report)

LlamaHub

This package is listed on LlamaHub as a Tool Spec integration. You can also load it via the LlamaHub loader:

from llama_index.core import download_loader

SwissTruthToolSpec = download_loader("SwissTruthToolSpec")
spec = SwissTruthToolSpec()
tools = spec.to_tool_list()

Links


Related Packages

Framework Package
LangChain swiss-truth-langchain
CrewAI swiss-truth-crewai
AutoGen swiss-truth-autogen
LlamaIndex swiss-truth-llamaindex ← you are here

License

MIT © Swiss Truth

Metadata

Release files for swiss-truth-llamaindex 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for swiss-truth-llamaindex 0.1.0
File Interpreter ABI Platform
swiss_truth_llamaindex-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / swiss_truth_llamaindex-0.1.0-py3-none-any.whl

Download URL swiss_truth_llamaindex-0.1.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e0b977ed1db6d73adc32e0400bfa6f9d3a7d973ee225fb6c35cb3aab7a6257c
BLAKE2b-256 checksum
How to use checksums
119169567fb4390c0072e9a9d883e288b432ebe8ff6f9c2d52dcc775c8765172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page