Skip to main content

How to Diagnose a Wrong Answer in a RAG Pipeline

Run the same question twice to see whether your system found the right evidence and used it correctly.

Updated 3 min readMarkdown
How to Diagnose a Wrong Answer in a RAG Pipeline

Your support assistant says customers have 14 days to request a refund. The current policy says 30. Before rewriting the prompt, check which policy the model actually saw.

In a retrieval-augmented generation (RAG) system, a wrong answer can come from missing evidence, conflicting documents, or the model misreading a passage. A two-run test helps narrow down where to look.

Run the same question twice

  1. Use the actual context. Ask, “How long do I have to request a refund?” Save the answer and the exact passages that reached the model after ranking, filtering, and truncation.
  2. Use verified context. Ask the same question again with the relevant passage from the current refund policy. Keep the model, prompt template, and generation settings the same.

For both runs, check whether the deadline is correct and whether the supplied evidence supports it.

What you observe What to check next
The first run says 14 days, the second says 30, and the first never saw the current policy. Check whether the current policy was indexed, ranked high enough, and included in the final prompt.
The first run saw both policies and picked 14 days. Check whether archived documents are filtered out or clearly marked as outdated.
Both runs say 14 days even though the verified passage says 30. Check whether the model can extract the deadline from that passage with a simpler prompt.
The answer says 30 days, but the supplied passages give no deadline. Record the answer as unsupported and check whether the system should have declined to answer.

Replacing the context can also remove distracting passages. If the second run succeeds, add conflicting passages back one at a time to see which change affects the answer.

Turn the failure into a regression test

Save the question, expected answer, policy version, and supporting passage. Add one question that requires two passages and one the knowledge base cannot answer. Rerun all three whenever you change indexing, ranking, or prompts.

Track three outcomes separately: Did the evidence reach the model? Did the answer use it correctly? Did the system decline when evidence was missing?

For more on evaluating retrieval and generation, see the RAGAs paper. For broader AI system design, explore the IAICB Certified AI Architect curriculum.

Which is harder to catch in your pipeline: missing evidence or a convincing answer backed by the wrong source?

Running the exact same prompt template once with actual context and once with the verified policy passage is the fastest binary search in RAG debugging. In two calls it tells you immediately whether you have a retrieval/ranking problem, a stale-document conflict, or a model comprehension failure.

Adding conflicting passages back one at a time after the clean run succeeds is also a great isolation technique. Quite often a model reads a single policy accurately in isolation, yet flips to the wrong deadline the moment an older FAQ sits directly above it in the prompt.

Thanks, Ahmet! The older FAQ example is a good one. I’d try swapping the order of the two passages and see if the answer flips. Have you found that marking the old FAQ as superseded is enough, or do you usually filter it out before it reaches the model?

Filtering superseded documents out at retrieval time is much more reliable than marking them as outdated in the prompt. Even with an explicit SUPERSEDED label, models still pull the older number occasionally when the phrasing in the old FAQ matches the user's wording more closely than the new policy.

I only keep historical versions eligible when the query explicitly carries an as-of date or audit context; for standard live support traffic, excluding superseded revisions via metadata pre-filters avoids relying on prompt compliance.