LlamaIndex tools & retriever for Swiss Truth — certified knowledge base for AI agents
Project description
swiss-truth-llamaindex
LlamaIndex ToolSpec & Retriever for Swiss Truth — certified knowledge base for AI agents.
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
- 🌐 Swiss Truth
- 📖 Documentation
- 🐍 PyPI
- 🦙 LlamaHub
- 🔗 MCP Endpoint
- 🐛 Issues
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swiss_truth_llamaindex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: swiss_truth_llamaindex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e0b977ed1db6d73adc32e0400bfa6f9d3a7d973ee225fb6c35cb3aab7a6257c
|
|
| MD5 |
cdbc4474e16126a91041d3a1def1b72d
|
|
| BLAKE2b-256 |
119169567fb4390c0072e9a9d883e288b432ebe8ff6f9c2d52dcc775c8765172
|