hallucination-gate
RAG evaluation + conservative release gate for RAG and fine-tuned LLMs.
- Eval: RAGAS-class metrics (
faithfulness,answer_relevancy,context_precision,context_recall) on claim↔chunk grounding — not whole-answer NLI only. - Gate: pass / rewrite / abstain so production only ships supported text.
Author: Shreyas G.
Install
pip install -U hallucination-gate
pip install "hallucination-gate[ocr]" # optional OCR
RAG eval (RAGAS replacement path)
from hallucination_gate import RAGEval
evaler = RAGEval() # neural; use_heuristic=True for CI
report = evaler.evaluate(
[
{
"query": "What is the warranty?",
"answer": "The Titan watch has a 2-year warranty.",
"contexts": [
"The Titan watch has a 2-year warranty covering defects.",
"Shipping takes 3-5 days.",
],
"ground_truth": "2-year warranty for manufacturing defects.",
# optional labeled retrieval:
# "relevant_contexts": ["The Titan watch has a 2-year warranty covering defects."],
}
]
)
print(report.aggregate)
# {'faithfulness': ..., 'answer_relevancy': ..., 'context_precision': ..., ...}
report.to_json("report.json")
hallucination-gate eval-dataset samples.jsonl --out report.json
| Metric | How this package scores it |
|---|---|
| faithfulness | Fraction of answer claims supported by individual chunks (contradictions penalize) |
| answer_relevancy | Query↔answer embedding relevance |
| context_precision | Labeled relevant_contexts if provided; else claim-aligned chunk proxy |
| context_recall | Requires ground_truth — fraction of reference facts covered by contexts |
| groundedness / hallucination_risk / release_safety | BN posteriors from the same evidence stack |
Why this beats typical RAGAS setups for grounding: claim-level soft-OR against neighbors, false-release oriented gate, multimodal/OCR evidence, and a production safe_answer path — not only a mean score.
Production gate
from hallucination_gate import HallucinationGate, Evidence
gate = HallucinationGate()
result = gate.check(query, answer, context=retrieved_docs)
return result.text
report = gate.evaluate(samples) # same backends as the gate
OCR
from hallucination_gate import Evidence, ocr_available
ev = Evidence.from_image(path="warranty_card.jpg")
ev = Evidence.from_ocr(path="scanned_policy.pdf")
Drawbacks (honest)
- Latency & cost — neural path adds inference time / GPU·CPU load per sample.
- Over-refusal — conservative gate can abstain on good extractive answers.
- Only as good as evidence — checks support, not world truth; bad retrieval still hurts.
- Hard cases — subtle math/code/reasoning can fool or over-block NLI.
- Heuristic ≠ quality gate —
use_heuristic=Trueis for CI smoke, not calibrated faithfulness. - Ops surface — HF downloads, torch/sentence-transformers weight, Windows symlink quirks.
- Not magic — still not a full substitute for domain-labeled regression + human review; it is a stronger grounding-first eval+gate stack than score-only RAGAS defaults.
Eval (gate safety)
pip install -e ".[dev]"
set RAG_EVAL_HEURISTIC=1
pytest -q -m "not neural"
hallucination-gate eval-heldout
License
MIT © Shreyas G
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 hallucination_gate-0.7.0.tar.gz.
File metadata
- Download URL: hallucination_gate-0.7.0.tar.gz
- Upload date:
- Size: 60.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1b07a90212b0597b0f2d5093967cbb61adb0d0f1a8f3162da7199cda1af27f0
|
|
| MD5 |
bcaa739c65669a34059c9629acea06e4
|
|
| BLAKE2b-256 |
847b5030133dce3e21ca41bbf6991415b749f85e7444fbaf233e39355f815c40
|
Provenance
The following attestation bundles were made for hallucination_gate-0.7.0.tar.gz:
Publisher:
publish.yml on shrey315/hallucination-gate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hallucination_gate-0.7.0.tar.gz -
Subject digest:
d1b07a90212b0597b0f2d5093967cbb61adb0d0f1a8f3162da7199cda1af27f0 - Sigstore transparency entry: 2484294134
- Sigstore integration time:
-
Permalink:
shrey315/hallucination-gate@5abeb20fb627f0c690674135acd2c9b15daefc7d -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/shrey315
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5abeb20fb627f0c690674135acd2c9b15daefc7d -
Trigger Event:
release
-
Statement type:
File details
Details for the file hallucination_gate-0.7.0-py3-none-any.whl.
File metadata
- Download URL: hallucination_gate-0.7.0-py3-none-any.whl
- Upload date:
- Size: 66.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0a18c25abbf6e918e901f2754c33fc78a0fc9c3d4b409fd060919918d44ae61
|
|
| MD5 |
935c5065bc04827e8e8038371f38f485
|
|
| BLAKE2b-256 |
12fe611d4ad3b7a13903af0cbd9fd340912536e540192331d32a5ff059a28b59
|
Provenance
The following attestation bundles were made for hallucination_gate-0.7.0-py3-none-any.whl:
Publisher:
publish.yml on shrey315/hallucination-gate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hallucination_gate-0.7.0-py3-none-any.whl -
Subject digest:
c0a18c25abbf6e918e901f2754c33fc78a0fc9c3d4b409fd060919918d44ae61 - Sigstore transparency entry: 2484294168
- Sigstore integration time:
-
Permalink:
shrey315/hallucination-gate@5abeb20fb627f0c690674135acd2c9b15daefc7d -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/shrey315
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5abeb20fb627f0c690674135acd2c9b15daefc7d -
Trigger Event:
release
-
Statement type: