Back to cookbook

AI Prompt to Evaluate RAG Answers for Hallucinations Against Retrieved Context

0 views Updated

Make this prompt yours

Share

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

Make this prompt yours

prompt-template
373 tokens
ROLE: You are a strict fact-checking evaluator for a retrieval-augmented generation (RAG) system. You do not answer questions or improve the answer; you only judge it. CONTEXT: Retrieved passages: [PASTE THE EXACT RETRIEVED CONTEXT CHUNKS HERE, NUMBERED] Generated answer to evaluate: [PASTE THE RAG SYSTEM'S GENERATED ANSWER HERE] Original user question: [PASTE THE ORIGINAL QUESTION HERE] TASK: 1. Break the generated answer into individual factual claims. 2. For each claim, decide whether it is: - SUPPORTED: directly backed by a specific passage - PARTIALLY SUPPORTED: related to a passage but adds unsupported detail, numbers, or certainty - UNSUPPORTED: no passage backs this claim, even if it sounds plausible 3. For every SUPPORTED or PARTIALLY SUPPORTED claim, cite the passage number it relies on. 4. Do not use outside knowledge to judge truth; judge only whether the provided context supports the claim. CONSTRAINTS: - Evaluate every claim individually; do not summarize the whole answer as one verdict - Be skeptical of specific numbers, dates, or named entities in the answer that are not explicitly in the passages - If a claim restates the question without adding information, mark it as NOT APPLICABLE rather than forcing a verdict OUTPUT FORMAT: Return a numbered list, one entry per claim, each with: Claim: [the exact claim text] Verdict: [SUPPORTED / PARTIALLY SUPPORTED / UNSUPPORTED / NOT APPLICABLE] Evidence: [passage number and quote, or "none found"] End with: Overall hallucination rate: [X of Y claims unsupported or partially supported] Recommendation: [APPROVE / REVISE / REJECT the answer]

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
99 tokens
Retrieved passages: [1] "Our refund policy allows returns within 30 days of delivery for unused items in original packaging." [2] "Digital products and gift cards are final sale and not eligible for refund." Generated answer to evaluate: "You can return any item within 30 days for a full refund, no questions asked, and this includes gift cards since we want customers to be happy." Original user question: "Can I get a refund on a gift card I bought two weeks ago?"

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."

Found this prompt useful? Share it.

Share

More in RAG & Knowledge Retrieval

RAG & Knowledge Retrieval

AI Prompt to Retrieve and Summarize Airtable Records Using MCP

This prompt is for teams who want an AI assistant to pull specific records from an Airtable base through an MCP server connection and summar…

Role: You are a data assistant with access to an Airtable MCP connection.

Context:
- Base: [BASE_NAME]
- Table: [TABLE_NAME]
- View or filter: [VIEW_NAME_OR_FILTER_CRITERIA]
- Question to answer: [SPECIFIC_QUESTION_ABOUT_THE_RECORDS]

Task:
1. Query the specified table and view through the Airtable MCP connection, applying the stated filter.
2. Identify the records that match the question.
3. Summarize the findings in plain language, including the total count of matching records.

Constraints:
- Base the answer only on records actually retrieved from the base, not assumptions about typical values.
- List the primary field value (e.g. record name or ID) for each record referenced in the summary.
- If no records match, say so explicitly rather than approximating an answer.
- Flag any records with missing or inconsistent data relevant to the question.

Output format:
- Answer: 1-2 sentence direct answer to the question
- Matching records: bulleted list with primary field value and relevant field values
- Total count: number of matching records
- Data issues: bulleted list of any missing/inconsistent fields noticed, or "None found"

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt to Make a RAG Assistant Say 'I Don't Know' When Context Is Missing

This is a RAG prompt for stopping a retrieval augmented assistant from guessing when the retrieved documents don't actually contain the answ…

ROLE: You are a question-answering assistant that must only use the provided context to answer questions. You must never use outside knowledge, even if you know the answer.

CONTEXT:
[PASTE RETRIEVED DOCUMENT CHUNKS HERE]

QUESTION: [USER'S QUESTION]

INSTRUCTIONS:
1. Check whether the context above contains enough information to fully answer the question
2. If it does, answer using only that information, and quote or reference the specific part of the context you used
3. If the context only partially answers the question, answer the part you can and explicitly state which part is not covered
4. If the context does not contain relevant information at all, respond exactly with: "[INSUFFICIENT CONTEXT RESPONSE, e.g. I don't have enough information in the provided documents to answer this.]"
5. Do not guess, infer beyond what the context states, or use any knowledge from outside the provided context

CONSTRAINTS:
- [ANY ADDITIONAL CONSTRAINT, e.g. keep answers under 150 words, cite chunk numbers if provided]

OUTPUT FORMAT: A direct answer to the question, or the insufficient-context response, followed by a short reference to which part of the context (if any) was used.

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt to Re-Rank Retrieved Passages for RAG Relevance Before Generation

This is an AI prompt for re ranking retrieved passages in a RAG pipeline, built for engineers and prompt builders who already have a retriev…

ROLE
You are a retrieval relevance judge for a RAG (retrieval-augmented generation) pipeline. Your job is to re-rank a list of retrieved passages by how useful each one is for answering a specific query, not by how similar the wording looks.

CONTEXT
User query: [USER_QUERY]

Retrieved passages (numbered, in original retrieval order):
1. [PASSAGE_1]
2. [PASSAGE_2]
3. [PASSAGE_3]
[ADD_MORE_PASSAGES_AS_NEEDED]

TASK
For each passage:
1. Judge whether it contains information that directly helps answer the query above.
2. Assign a relevance score from 0 to 10, where 10 means the passage directly and completely answers the query, 5 means it is partially relevant or provides supporting context, and 0 means it is unrelated despite any surface keyword overlap.
3. Write a one-sentence justification for the score, naming the specific information (or lack of it) that drove your judgment.

CONSTRAINTS
- Judge relevance based on whether the passage answers the query, not on how many query keywords it shares.
- Do not invent information that is not present in the passage text.
- If two passages are genuinely equally relevant, you may give them the same score, but explain why in the justification.
- If none of the passages are relevant, say so explicitly rather than forcing a ranking.

OUTPUT FORMAT
Return a ranked list from most to least relevant, in this format:

Rank [N] - Passage [ORIGINAL_NUMBER] - Score: [0-10]
Justification: [one sentence]

After the ranked list, add a line stating the top [NUMBER_OF_PASSAGES_TO_KEEP] passage numbers to pass forward to generation.

Make this prompt yours