Haystack components for Swiss Truth — certified knowledge base for AI agents
Project description
swiss-truth-haystack
Haystack 2.x components for Swiss Truth — the certified, hallucination-free knowledge base for AI agents.
Stop your Haystack pipelines from hallucinating. Ground every LLM response in 3000+ certified Swiss and EU facts, verified by a 5-stage validation pipeline.
Features
- 🔍
SwissTruthRetriever— Drop-in Haystack Retriever component. Plug into any RAG pipeline. - ✅
SwissTruthFactChecker— Verify LLM outputs against certified facts. Returnssupported/contradicted/unverified. - 🌍 3000+ certified claims across 38 domains (Swiss law, EU health, AI/ML, finance, climate, …)
- 🗣️ 10 languages — DE, EN, FR, IT, ES, ZH, AR, RU, JA, KO
- 🔒 EU AI Act compliant — SHA256 integrity hashes + weekly blockchain anchoring
- ⚡ Zero config — no API key required for public endpoints
Installation
pip install swiss-truth-haystack
Quick Start
RAG Pipeline with Certified Facts
from swiss_truth_haystack import SwissTruthRetriever
from haystack import Pipeline
from haystack.components.builders import PromptBuilder
from haystack.components.generators import OpenAIGenerator
retriever = SwissTruthRetriever(domain="swiss-law", top_k=5)
prompt = PromptBuilder(template="""
Answer the question using only the certified facts below.
Facts:
{% for doc in documents %}
- {{ doc.content }} (confidence: {{ doc.meta.confidence }})
{% endfor %}
Question: {{ query }}
Answer:
""")
pipeline = Pipeline()
pipeline.add_component("retriever", retriever)
pipeline.add_component("prompt", prompt)
pipeline.add_component("generator", OpenAIGenerator(model="gpt-4o"))
pipeline.connect("retriever.documents", "prompt.documents")
pipeline.connect("prompt.prompt", "generator.prompt")
result = pipeline.run({
"retriever": {"query": "Is health insurance mandatory in Switzerland?"},
"prompt": {"query": "Is health insurance mandatory in Switzerland?"},
})
print(result["generator"]["replies"][0])
Standalone Retriever
from swiss_truth_haystack import SwissTruthRetriever
retriever = SwissTruthRetriever(domain="ai-ml", top_k=8)
result = retriever.run(query="What are the EU AI Act risk categories?")
for doc in result["documents"]:
print(f"[{doc.meta['confidence']:.0%}] {doc.content}")
print(f" Source: {doc.meta['source_url']}")
Fact-Checking Pipeline
from swiss_truth_haystack import SwissTruthFactChecker
checker = SwissTruthFactChecker(domain="swiss-law")
result = checker.run(claim="Health insurance is optional in Switzerland.")
print(f"Verdict: {result['verdict']}") # "contradicted"
for doc in result["documents"]:
print(f" Certified fact: {doc.content}")
Post-Generation Fact Check
from swiss_truth_haystack import SwissTruthFactChecker
from haystack import Pipeline
from haystack.components.generators import OpenAIGenerator
pipeline = Pipeline()
pipeline.add_component("generator", OpenAIGenerator(model="gpt-4o"))
pipeline.add_component("checker", SwissTruthFactChecker(domain="swiss-law"))
# Note: connect generator output to checker input in your pipeline logic
result = pipeline.run({"generator": {"prompt": "Explain Swiss health insurance."}})
Components
SwissTruthRetriever
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str |
None |
Optional API key (not required for public endpoints) |
base_url |
str |
https://swisstruth.org |
API base URL |
timeout |
float |
30.0 |
HTTP timeout in seconds |
domain |
str |
None |
Domain filter (e.g. "swiss-law", "ai-ml") |
top_k |
int |
5 |
Max documents to retrieve (1-20) |
min_confidence |
float |
0.8 |
Minimum confidence threshold |
run() inputs:
| Input | Type | Description |
|---|---|---|
query |
str |
Search query |
domain |
str (optional) |
Per-call domain override |
top_k |
int (optional) |
Per-call result count override |
run() outputs:
| Output | Type | Description |
|---|---|---|
documents |
List[Document] |
Certified facts as Haystack Documents |
SwissTruthFactChecker
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str |
None |
Optional API key |
base_url |
str |
https://swisstruth.org |
API base URL |
timeout |
float |
30.0 |
HTTP timeout in seconds |
domain |
str |
None |
Domain hint for verification |
run() inputs:
| Input | Type | Description |
|---|---|---|
claim |
str |
Factual statement to verify |
domain |
str (optional) |
Per-call domain override |
run() outputs:
| Output | Type | Description |
|---|---|---|
documents |
List[Document] |
Matching certified claims |
verdict |
str |
"supported" / "contradicted" / "unverified" |
raw |
dict |
Raw API response |
Available Domains
| Domain | Description |
|---|---|
swiss-law |
Swiss federal and cantonal law |
eu-health |
EU health regulations |
ai-ml |
AI/ML facts and EU AI Act |
finance |
Swiss and EU financial regulations |
climate |
Climate science and Swiss policy |
quantum-computing |
Quantum computing facts |
swiss-history |
Swiss historical facts |
| … | 38 domains total — see swisstruth.org/domains |
Document Metadata
Every retrieved Document includes:
doc.meta = {
"claim_id": "uuid", # Unique claim identifier
"domain": "swiss-law", # Knowledge domain
"language": "en", # ISO 639-1 language code
"source_url": "https://...", # Primary source URL
"verified": True, # Verification status
"confidence": 0.97, # Confidence score 0.0-1.0
"swiss_truth": True, # Swiss Truth provenance marker
}
doc.score = 0.97 # Same as confidence (for Haystack ranking)
Serialization
Both components support Haystack's standard serialization for pipeline YAML export:
import yaml
from haystack import Pipeline
from swiss_truth_haystack import SwissTruthRetriever
pipeline = Pipeline()
pipeline.add_component("retriever", SwissTruthRetriever(domain="swiss-law"))
# Export
print(pipeline.dumps())
# Import
pipeline2 = Pipeline.loads(pipeline.dumps())
Links
- 🌐 API: swisstruth.org
- 📖 Docs: swisstruth.org/docs/integrations/haystack
- 🐙 GitHub: github.com/swisstruthorg/swiss-truth-mcp
- 📦 PyPI: pypi.org/project/swiss-truth-haystack
- 🤖 MCP Server: swisstruth.org/mcp
License
MIT — see LICENSE
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 Distribution
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_haystack-0.1.0.tar.gz.
File metadata
- Download URL: swiss_truth_haystack-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3adbea9c6744d239088d451de9d507136412d044b3d1dc887e8c3a01fc4f4f5
|
|
| MD5 |
f7dc19b6d65c4415b074148ba3228fc6
|
|
| BLAKE2b-256 |
c8e4715ef78054399bb4e4abec5efa9146501cb938dc7fd31698a7acbb52986f
|
File details
Details for the file swiss_truth_haystack-0.1.0-py3-none-any.whl.
File metadata
- Download URL: swiss_truth_haystack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 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 |
48c7f1e0d36219e32a1dd8a130d68d0ce3cc71723f89bc09cd54174020609dcc
|
|
| MD5 |
5903d502dc1589ea7038e840cd3e15c1
|
|
| BLAKE2b-256 |
9c193d6209e70fecfea9f02c21fa62977ee3d0d5168832b817d929e1b41397f1
|