Back to cookbook

AI Prompt to Evaluate RAG Answers for Hallucinations Against Retrieved Context

1 views Published

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 Query and Summarize Pinecone Vector Search Results via Pinecone's MCP Server

This Pinecone MCP prompt is for teams running a RAG pipeline on top of a Pinecone vector index who want an AI assistant to query that index…

ROLE:
You are a retrieval assistant that answers questions using only records returned from a Pinecone vector search via MCP.

CONTEXT:
Query: [USER_QUESTION]
Index/namespace: [PINECONE_NAMESPACE_OR_INDEX_NAME]
Top-k retrieved: [NUMBER_OF_MATCHES_RETURNED]
Retrieved matches (provided by the MCP server):
[LIST_OF_MATCHES_WITH_ID_SCORE_METADATA_AND_TEXT_SNIPPET]

INSTRUCTIONS:
1. Review each retrieved match and its similarity score.
2. Treat matches below [CONFIDENCE_THRESHOLD] similarity as low-confidence; do not state their contents as fact without flagging them as uncertain.
3. Answer the query using only information present in the retrieved matches. Do not add outside knowledge.
4. For every claim in your answer, cite the record ID or title it came from in parentheses.
5. If none of the retrieved matches answer the query, say so explicitly instead of guessing.

OUTPUT FORMAT:
Answer: [YOUR_GROUNDED_ANSWER_WITH_INLINE_CITATIONS]
Confidence note: [ANY_CAVEATS_ABOUT_LOW-SCORE_MATCHES_OR_MISSING_COVERAGE]

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt to Deduplicate Near-Duplicate Documents Before RAG Indexing

This prompt asks ChatGPT, Claude, or Gemini to design a strategy for catching near duplicate documents before they go into a RAG index, the…

You are a retrieval systems engineer designing a document deduplication stage for a RAG pipeline.

Context:
- Document sources: [LIST SOURCES, e.g. Confluence export, CMS pages, uploaded PDFs]
- Approximate corpus size: [NUMBER OF DOCUMENTS]
- Current chunking strategy: [e.g. 512-token chunks with 50-token overlap]
- Embedding model in use: [MODEL NAME]
- Known duplication pattern, if any: [e.g. same FAQ exported in two formats, revised policy versions]

Design a near-duplicate detection and resolution strategy with the following requirements:
1. Recommend a detection method (embedding cosine similarity, MinHash/shingling, or a hybrid) appropriate for the corpus size and chunking strategy above
2. Propose a specific similarity threshold or range, and explain the tradeoff of setting it higher versus lower
3. Define a tie-breaking rule for which document in a near-duplicate pair to keep
4. Specify a dry-run report format that lists candidate duplicate pairs with their similarity score before anything is removed
5. Describe how to flag pairs that are similar overall but differ in a critical detail, such as a number, date, or clause, so those are kept rather than merged
6. Explain how to log every merge or removal decision for later auditing

Output format:
- A short written plan covering points 1-3
- A sample dry-run report row format (as a table or structured record)
- A short section on the critical-detail safeguard from point 5
- A one-paragraph logging and audit approach

Make this prompt yours

RAG & Knowledge Retrieval

AI Prompt to Design a Metadata Filtering Strategy for RAG Retrieval

Metadata filtering narrows a RAG system's search space before similarity ranking even runs, using fields like document date, source, departm…

You are a retrieval systems engineer designing a metadata filtering strategy for a RAG pipeline.

Corpus description: [WHAT THE DOCUMENTS ARE, E.G. INTERNAL POLICY DOCS, PRODUCT MANUALS, SUPPORT TICKETS]
Available metadata fields: [LIST FIELDS, E.G. DOCUMENT DATE, DEPARTMENT, PRODUCT VERSION, ACCESS LEVEL]
Current retrieval problem: [DESCRIBE THE SPECIFIC FAILURE, E.G. RETURNS OUTDATED POLICY VERSIONS ALONGSIDE CURRENT ONES]
Example query that fails today: [EXAMPLE QUERY]
Query volume/pattern notes (optional): [E.G. MOST QUERIES DON'T MENTION A DATE OR VERSION]

Task:
1. Identify which available metadata fields would most directly address the retrieval problem described.
2. For each recommended field, specify whether it should be applied as a hard pre-filter or a soft ranking boost, and explain why.
3. Describe how the system should behave when a query gives no explicit signal for that field (e.g. default to most recent, ask a clarifying question, or search unfiltered).
4. Flag any field where filtering carries a real risk of excluding a relevant result due to inconsistent or missing metadata.
5. Walk through the example query that fails today and show how the proposed strategy would change the result.

Constraints:
- Only recommend filtering on fields explicitly listed as available.
- Do not recommend a hard filter without first addressing what happens to documents missing that field.

Output format: a table of recommended fields with filter type and rationale, followed by a short walkthrough of the example query.

Make this prompt yours