AI Prompt to Evaluate RAG Answers for Hallucinations Against Retrieved Context
This RAG hallucination detection prompt checks a generated answer against the exact passages a retrieval-augmented generation system pulled back, flagging any claim the context doesn't actually support. It's built for engineers, prompt designers, and QA reviewers testing a RAG pipeline who need a repeatable way to catch unsupported claims before they reach an end user, rather than relying on a human skimming the output for anything that looks off.
The prompt works by treating the model as a fact-checker, not a writer: it is given the retrieved context and the generated answer side by side and asked to classify each claim in the answer as fully supported, partially supported, or unsupported, citing the exact passage (or lack of one) for each judgment. This separates groundedness checking from answer generation, which produces more consistent results than asking the same model to both answer and self-grade in one pass.
Used well, this becomes a repeatable evaluation step you run after retrieval and generation, not a one-off spot check. Before relying on the output for a go/no-go decision on a RAG release, it's worth running the detection prompt itself through Prompt Debugger to catch vague grading criteria or edge cases the rubric might be missing.
Prompt template
Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.
Example input
When to use it
- Before shipping a change to a RAG pipeline's retriever, chunking, or prompt template, to confirm answer quality hasn't regressed
- When building an automated eval suite that needs a consistent, repeatable way to score groundedness across many question-answer pairs
- When a RAG assistant is giving answers that sound confident but a reviewer suspects the retrieved context doesn't actually back them up
- When comparing two retrieval configurations (different chunk sizes, embeddings, or rerankers) and need an apples-to-apples hallucination rate for each
Best practices
- Feed the model the raw retrieved chunks verbatim, not a paraphrase or summary of them, so the comparison is against what the system actually had available
- Require a verdict and a cited passage (or explicit 'no supporting passage found') for every claim, not just an overall pass/fail score
- Run the same answer through the check twice with context shuffled or reworded slightly to see whether the verdicts stay consistent before trusting the rubric at scale
- Keep the fact-checking pass separate from the answer-generation pass; a model grading its own freshly written answer in the same turn is less reliable than a second, independent evaluation turn
Common mistakes
- Asking for a single overall hallucination score instead of a per-claim breakdown, which hides exactly which sentence is the problem
- Letting the checker use outside knowledge to decide if a claim is 'true' instead of strictly whether the provided context supports it
- Testing only obviously wrong answers instead of plausible-sounding ones, which is where most real hallucinations hide
- Reusing the exact same prompt and model turn that generated the answer to also grade it, which inherits the same blind spots
FAQs
What is hallucination detection in a RAG pipeline?
It's the process of checking whether a generated answer's claims are actually backed by the documents a retrieval step pulled back, rather than invented or extrapolated by the model during generation.
Can I use this prompt with any AI model?
Yes. The template works with ChatGPT, Claude, or Gemini since it only relies on standard instruction-following and doesn't require model-specific syntax, though results can vary slightly by model.
Why not just ask the same model that generated the answer to also check it?
A model grading its own answer in the same context window tends to inherit the same assumptions that produced the error in the first place. Running the check as a separate, independent evaluation turn with only the context and answer (not the original generation reasoning) tends to surface more genuine issues.
How is this different from a RAG source-citation prompt?
A citation prompt asks the model to generate an answer with citations attached as it writes. This prompt instead audits an answer that already exists, after the fact, specifically to catch claims that don't match the retrieved context.
Which Cuelara tool can help me strengthen this evaluation prompt?
Prompt Debugger — scans a prompt like this one for vague grading criteria, missing edge cases, and loopholes that could let a hallucinated claim slip through as "supported."