RAG · Module 11 of 14 · 8 concepts · about 10 min

Failure Modes and Debugging

The specific ways a RAG answer goes wrong, how to tell which stage was responsible, and the fix that belongs to each. The most practical module, and a favourite interview topic.

At work: The day-to-day work of owning a live assistant: a customer reports a wrong answer, and an engineer has to find the broken stage and repair it without breaking the rest.

The seven places a RAG answer can go wrong

What it is

A wrong answer has a cause at one specific stage. In pipeline order:

  • 1. Missing content: the answer is not in any document.
  • 2. Missed retrieval: it is in the index but was not in the retrieved candidates.
  • 3. Lost in ranking: it was retrieved but ranked too low to reach the prompt.
  • 4. Not used: it was in the prompt and the model ignored it.
  • 5. Wrong format or incomplete: the model used it but left part out or shaped the answer badly.
  • 6. Hallucinated detail: the model added something the context did not say.
  • 7. Stale or conflicting source: the context itself was outdated or contradicted another chunk.

Why it matters

Naming the stage is most of the work, because each has a different owner and a different fix. An interviewer who asks 'your RAG system gives wrong answers, what do you do?' wants to hear this list and a method for telling the cases apart, not a guess at a fix.

In the real world: A weekly review of failed answers at a software company sorts each one into these seven buckets; the biggest bucket decides the next week's engineering work.

Visual example

Failure map

Stages 1 to 3 are retrieval-side; 4 to 6 are generation-side; 7 is a data problem.

Seven failure points and the fix that belongs to each
#failurethe model saw the answer?fix lives in
1Missing contentNo: it does not existAdd the document; abstain meanwhile
2Missed retrievalNoChunking, hybrid search, query rewriting, embeddings
3Lost in rankingNo: cut off before the promptReranker, larger k
4Not usedYesContext order, fewer chunks, prompt
5Wrong format or incompleteYesPrompt, structured output
6Hallucinated detailPartlyGrounding rules, citation checks, cleaner context
7Stale or conflicting sourceIt saw the wrong oneIngestion: versions, dedup, dates

Reaching for the prompt first. Rewording the instructions is the easiest change to make, and it only addresses stages 4 to 6. For the first three, the model never saw the answer, and no wording can help.

Debugging order: is it retrieval or generation?

What it is

One question splits every failure in two: was the chunk containing the right answer in the prompt?

  • Look at the logged context for the failed question.
  • If the right chunk is absent, it is a retrieval-side problem.
  • If it is present, it is a generation-side problem.

Why it matters

This single check halves the search and takes a minute.

  • From there, follow the pipeline backwards for retrieval failures: is the fact in the documents at all? Is it in a chunk in one piece?
  • Was that chunk in the first-stage candidates? Did the reranker drop it? The first 'no' is the broken stage.

In the real world: An engineer handed a complaint opens the trace, sees the right article was retrieved in position 14 and cut at 5, and tunes the reranker instead of the prompt.

Visual example

Debugging

Stop at the first stage where the answer goes missing.

Walk the pipeline backwards from the prompt

  1. The promptcheck firstWas the answer's chunk in the context?
  2. The rerankerWas it among the candidates?
  3. The retrieverDoes a direct search find it?
  4. The chunksIs the fact intact in one chunk?
  5. The documentscheck lastDoes the content exist at all?

The first 'no' is the stage to fix.

A wrong answer is reported.

Was the right chunk in the prompt?
├─ NO  -> retrieval side
│    Is the fact in any document?         no -> missing content
│    Is it whole inside one chunk?        no -> chunking
│    Was it in the first-stage top 50?    no -> retrieval / query
│    Did it survive reranking?            no -> reranker or k
│
└─ YES -> generation side
     Is the answer contradicted by context? -> hallucination
     Is the right chunk buried mid-context? -> ordering / fewer chunks
     Do two chunks disagree?                -> stale or conflicting data

Debugging from the final answer alone. Without the logged query, candidates and prompt, you are guessing. If those are not being recorded, adding that logging is the first fix.

Missing content

What it is

The question is reasonable, but the answer is not in the collection: nobody wrote it down, the document was never ingested, or the parser failed on that file. The retriever returns its nearest chunks anyway, and the model, handed plausible-looking context, often produces a plausible-looking answer.

Why it matters

This is common in real traffic, and it is the case that most needs abstention. It is also valuable signal: a log of questions that had no good match is a list of the documents your organisation needs to write.

In the real world: A software company's top ten unanswerable questions each month go to the documentation team, who write the missing articles; the 'I don't know' rate falls month after month.

Treating it as a model problem and tightening the prompt. The durable fixes are a relevance threshold so the system can say 'I don't know', and a process that sends unanswered questions to whoever owns the content.

Missed retrieval

What it is

The answer exists in a chunk, but that chunk was not among the retrieved candidates. Usual causes:

  • the question and the chunk use different words and the search is keyword-only;
  • the question contains an exact code and the search is dense-only;
  • the fact was split across two chunks;
  • the chunk is ambiguous on its own ("the fee is refunded", with no mention of which fee);
  • the query was a follow-up fragment;
  • a filter excluded it.

Why it matters

Each cause maps to a technique from an earlier module, which is why those modules exist:

  • Different words: hybrid search, multi-query.
  • Exact codes: keyword search.
  • Split facts: overlap, structure-aware chunking.
  • Ambiguous chunks: contextual headers.
  • Fragments: query rewriting.
  • Filters: check the metadata.

In the real world: A retailer finds that questions with order numbers fail; the index was dense-only. Adding BM25 alongside it fixes the whole class in one change.

Raising k as the universal fix. Retrieving 200 instead of 50 may catch a chunk ranked 120th, but it does nothing for a chunk that scores near zero because of a wording gap or a bad cut.

Retrieved but ignored

What it is

The right chunk was in the prompt and the model still answered wrongly or said it did not know. Usual causes:

  • the chunk sat in the middle of a long context;
  • it was surrounded by distracting chunks that looked relevant and pointed elsewhere;
  • the chunk was hard to read (a flattened table, broken formatting);
  • the instructions were so cautious that the model abstained despite having the answer.

Why it matters

It shows that retrieval being right is necessary and not sufficient. The fixes are about making the right chunk easy to use: fewer chunks, best first, clean formatting, clear labels, and instructions that balance caution against answering.

In the real world: A pricing assistant gives wrong fees although the fee table is retrieved every time; the table had been flattened into one line, and re-ingesting it as Markdown fixes the answers.

Adding more context to 'give the model more to work with'. More near-miss chunks are precisely what causes this failure. Models are distracted more by passages that are almost relevant than by passages that are plainly unrelated.

Hallucination despite good context

What it is

The context was right and the model still stated something it does not support. Typical forms:

  • adding a plausible detail (a time limit the policy never mentions);
  • merging two chunks into a rule neither states;
  • over-generalising (the policy covers late orders; the answer says 'all orders');
  • getting numbers slightly wrong.

Why it matters

This is the residual risk that no retrieval improvement removes, so it needs its own defences: a firm grounding instruction, a citation per claim, a low temperature, an automatic groundedness check on the output, and for high-stakes answers a second model pass that verifies each claim before the user sees it.

In the real world: A lender's assistant quoted an interest rate one decimal place off the document; after that, every number in an answer is checked against the cited passage before it is shown.

Assuming a stronger model removes the problem. It lowers the rate; it does not reach zero. For answers where an error is expensive (medical, legal, financial), keep verification in the pipeline whatever model you use.

Stale and conflicting documents

What it is

The system retrieves and faithfully reports a passage that is out of date, or retrieves two passages that disagree: last year's policy and this year's, a draft and the final version, a regional rule and the global one. The model then picks one, or blends them.

Why it matters

It is a data problem appearing as a model problem, and common in any organisation whose documents were never tidied. Fixes sit in ingestion: remove or archive superseded versions, store an updated_at date and a status on every chunk, filter or down-rank old content, show the date to the model in the context, and instruct it to prefer the most recent source and to say so when sources conflict.

In the real world: An HR assistant keeps quoting the old leave allowance; the fix is not a prompt change but archiving the superseded policy and adding the effective date to every chunk.

Expecting the model to know which version is current. Unless the date or status is in the context, both passages look equally authoritative.

Tracing: logging every stage

What it is

A trace is a record of everything that happened for one question: the original message, the rewritten query, the filters applied, the candidate chunks with their scores, the reranked order, the final prompt, the model's answer, the time and cost of each step, and any user feedback. Each trace has an ID that ties the pieces together.

Why it matters

Every debugging step in this module depends on it.

  • Without traces, a reported wrong answer cannot be reproduced, because the documents, the index and the prompt may all have changed since.
  • With them, diagnosis takes minutes, and failed traces can be added straight to the golden set.

In the real world: When a customer complains about an answer from three weeks ago, the support engineer pulls the trace by conversation ID and sees exactly which chunks the model was given that day.

Logging only the question and the answer. The intermediate steps are where the fault is. Also remember that traces contain user questions and document text, so they need the same privacy and access controls as the data they came from.