Prompt
hallucination testing for RAG
Latest observation
Oct 21, 2026
OpenAI APIWeb search: off
Hallucination testing for RAG usually means evaluating whether the model:
- Sticks to retrieved evidence
- Avoids inventing unsupported facts
- Answers “I don’t know” or cites missing info when retrieval is insufficient
Here’s a practical way to test it.
1) Define what counts as a hallucination
Common categories:
- Unsupported answer: claim not present in retrieved documents
- Wrong synthesis: combines facts incorrectly
- Citation mismatch: cites a passage that doesn’t support the claim
- Overconfident answer: answers definitively despite weak retrieval
- Context omission: ignores a crucial retrieved detail and answers incorrectly
2) Build a test set
Create questions with known ground truth, ideally across:
- Answerable from context
- Partially answerable
- Unanswerable / not in corpus
- Ambiguous
- Adversarial retrieval: retrieved docs contain distractors
Include:
- Simple factual questions
- Multi-hop questions
- Numerical questions
- Temporal/versioned questions
- Questions where the correct answer is “not found”
3) Evaluate retrieval separately from generation
A lot of “hallucinations” are actually retrieval failures.
Track:
- Recall@k: did the relevant document appear in top-k?
- MRR / nDCG: how highly ranked was it?
- Context precision: how much retrieved text is actually relevant?
Then evaluate generation only when the right evidence is present.
4) Measure hallucination rate
For each answer, label:
- Supported
- Partially supported
- Unsupported
- Incorrect despite support
A simple metric:
- Hallucination rate = unsupported answers / total answers
Better: score by claim.
- Split answer into atomic claims
- Verify each claim against retrieved context
- Hallucination rate = unsupported claims / total claims
5) Use automatic + human evaluation
Automatic methods
- NLI / entailment models: does context entail the answer?
- LLM-as-judge: ask a judge model whether each claim is supported
- Citation checks: verify cited spans contain the claimed fact
- String/regex checks for structured answers
Human review
Use humans for:
- Edge cases
- Ambiguous questions
- Safety-critical domains
- Calibration of automatic judges
6) Test refusal behavior
A good RAG system should say:
- “I don’t know”
- “I couldn’t find that in the provided documents”
- “The retrieved context doesn’t support a confident answer”
Measure:
- False answer rate on unanswerable queries
- Refusal precision/recall
7) Stress-test with adversarial prompts
Examples:
- “Answer even if you’re unsure.”
- “Ignore the context and use general knowledge.”
- Conflicting docs
- Irrelevant but persuasive passages
- Long context with distractors
8) Recommended rubric
Score each response from 0–3:
- 3 = Fully supported, correct, concise
- 2 = Mostly supported, minor issue
- 1 = Weakly supported or partially incorrect
- 0 = Unsupported/hallucinated
Track:
- Average score
- % of 0s
- % of unsafe confident answers
9) Minimal evaluation pipeline
- Retrieve top-k documents
- Generate answer with citations
- Break answer into claims
- Verify claims against context
- Label supported/unsupported
- Aggregate metrics by question type and by retrieval quality
10) Useful tools/frameworks
- RAGAS: retrieval/generation metrics for RAG
- TruLens: feedback functions and groundedness checks
- DeepEval: RAG evaluation and hallucination metrics
- LangSmith: tracing and evaluation
- Arize Phoenix: observability and evals
If you want, I can also provide:
- a Python evaluation script
- a rubric/template for human labeling
- or a RAG hallucination test suite design for your specific use case.