Skip to main content

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swiss_truth_llamaindex-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file swiss_truth_llamaindex-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for swiss_truth_llamaindex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e0b977ed1db6d73adc32e0400bfa6f9d3a7d973ee225fb6c35cb3aab7a6257c
MD5 cdbc4474e16126a91041d3a1def1b72d
BLAKE2b-256 119169567fb4390c0072e9a9d883e288b432ebe8ff6f9c2d52dcc775c8765172

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page