# 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](https://aclanthology.org/2024.eacl-demo.16/). For broader AI system design, explore the [IAICB Certified AI Architect curriculum](https://www.iaicb.org/training/certified-ai-architect).

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