🔬 HallucinationBench
Detect hallucinations in your RAG pipeline output — in two lines of Python.
The problem
Your RAG pipeline retrieves documents and passes them to an LLM. The LLM generates a response that sounds correct. But is every claim actually grounded in your context — or did the model fabricate some of it?
HallucinationBench answers that question instantly.
Quickstart
Install dependencies:
pip install openai python-dotenv
Set your OpenAI API key:
# .env
OPENAI_API_KEY=your_key_here
Run your first evaluation:
from hallucinationbench import score
context = """
The Eiffel Tower is located in Paris, France. It was constructed between
1887 and 1889 as the entrance arch for the 1889 World's Fair.
The tower is 330 metres tall.
"""
response = """
The Eiffel Tower is in Paris. It was built in 1889 and stands 330 metres
tall. It was designed by Leonardo da Vinci and attracts over 7 million
visitors every year.
"""
result = score(context=context, response=response)
print(result)
Output:
Verdict : FAIL
Faithfulness : 0.40
Grounded claims (2):
✓ The Eiffel Tower is in Paris.
✓ It stands 330 metres tall.
Hallucinated claims (3):
✗ It was built in 1889.
✗ It was designed by Leonardo da Vinci.
✗ It attracts over 7 million visitors every year.
The result object
result.faithfulness_score # float 0.0 – 1.0
result.grounded_claims # list of supported statements
result.hallucinated_claims # list of fabricated statements
result.verdict # "PASS" | "WARN" | "FAIL"
result.model # judge model used
| Verdict | Faithfulness Score |
|---|---|
| ✅ PASS | >= 0.8 |
| ⚠️ WARN | >= 0.5 |
| ❌ FAIL | < 0.5 |
Streamlit demo
Run the interactive demo locally:
streamlit run app.py
Paste any context and LLM response — get an instant hallucination report.
How it works
- Your
contextandresponseare sent togpt-4o-minias a structured judge prompt. - The judge breaks the response into individual factual claims.
- Each claim is classified as grounded (supported by context) or hallucinated (absent or contradicted).
- A faithfulness score is calculated:
grounded_claims / total_claims. - A verdict of PASS, WARN, or FAIL is assigned.
The judge uses response_format: json_object to guarantee structured output.
Temperature is set to 0 for deterministic results.
Cost
Each evaluation uses gpt-4o-mini.
Typical cost: ~$0.001 per evaluation (well under a tenth of a cent).
Roadmap
- Batch evaluation across multiple context/response pairs
- CSV upload support in the Streamlit app
- Custom judge model selection
- LangChain and LlamaIndex integration hooks
- CI/CD integration example (GitHub Actions)
Project structure
hallucinationbench/
├── hallucinationbench/
│ ├── __init__.py # public API
│ ├── scorer.py # GPT-4o-mini judge
│ └── models.py # ScoreResult dataclass
├── app.py # Streamlit demo
├── example.py # quickstart example
├── requirements.txt
├── .env.example
└── README.md
License
MIT — free to use, modify, and distribute.
Contributing
Pull requests are welcome. Please open an issue first to discuss what you would like to change.
Built with OpenAI GPT-4o-mini as the hallucination judge.
Metadata
Release files for hallucinationbench 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hallucinationbench-0.1.0.tar.gz | 6.3 kB | Without provenance | Details for hallucinationbench-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hallucinationbench-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hallucinationbench-0.1.0-py3-none-any.whl |
Total release size: 13.3 kB
Release files / hallucinationbench-0.1.0.tar.gz
| Download URL | hallucinationbench-0.1.0.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09a1d356b7eb51e0d9dd8e5024e00bc6b3a3aeabe4e0845dd8f15f67c4e56c34
|
|
BLAKE2b-256 checksum How to use checksums |
c7b3df13358d62697f518416cf51b28151e75ca938bbe873a1add088a0b1f581
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / hallucinationbench-0.1.0-py3-none-any.whl
| Download URL | hallucinationbench-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
273e5a0abc7d545c87b8c2702a7e2a5aa6fb2eb257d6ea2e78bc4c084814c06f
|
|
BLAKE2b-256 checksum How to use checksums |
9c9555fa16cabb50e5c712a2758f127c789b669f45405856e299c5fa3f31cc88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Security for hallucinationbench 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.