RAG for Everyone

← Back to all chapters

Chapter 24 of 28Evaluation105 min read

Failure Analysis

Failure analysis is the discipline of turning bad RAG answers into precise engineering work. It keeps teams from randomly changing prompts, chunk sizes, retrievers, and models without understanding the root cause.

How to read this chapter

A bad answer feels like one problem. It is usually several problems wearing one costume — and the costume is the only part most teams ever look at.
Core ideaFailure analysis is the practice of tracing a bad RAG answer back through corpus, parsing, chunking, retrieval, prompt, and safety layers to find the exact system stage that produced it, then turning that fix into a permanent test.
Sub-topic 1 of 15

Why Failure Analysis Matters

When a RAG answer fails, the visible symptom is usually "the answer is wrong." But the root cause may be far upstream. The source may not exist. The parser may have dropped a table. Chunking may have separated a condition from its exception. Retrieval may have missed the gold evidence. The prompt may have ignored a citation rule. The access layer may have filtered out the only useful document.

Failure-analysis north starDo not fix the answer. Fix the system behavior that produced the answer.

A senior RAG builder treats every failure as a traceable production signal.

Sub-topic 2 of 15

Real-Life Analogy: Incident Investigation

When a plane has a hard landing, investigators do not just tell the pilot to "fly more carefully next time." They pull the flight recorder, reconstruct every decision point, and trace the event back through weather data, maintenance logs, air traffic instructions, and crew communication. The hard landing is the visible symptom. It is rarely the actual defect, and closing the file without finding the defect just schedules the next incident.

RAG failure analysis works the same way. A wrong answer is the hard landing. The real defect could be sitting in a missing document, a broken parser, a bad chunk boundary, a retriever that never surfaced the evidence, or a prompt that let the model guess. You do not close the investigation until you can point to the exact stage where the failure happened, and until you have a way to check tomorrow that it does not happen again.

Sub-topic 3 of 15

Trace Anatomy

A useful trace should include user question, detected intent, query rewrite, filters, retrieval route, candidate pool, reranker output, final context, prompt version, answer, citations, evaluator result, and user feedback.

Trace flow

question
  -> query rewrite
  -> filters and route
  -> candidate chunks
  -> reranked chunks
  -> final context pack
  -> prompt version
  -> answer and citations
  -> eval result and feedback
Sub-topic 4 of 15

Failure Taxonomy

Corpus

Source missing

The answer cannot be grounded because the organization never indexed an authoritative source.

Parsing

Text lost

Tables, footnotes, headings, or scanned text were extracted incorrectly.

Chunking

Meaning split

The rule and exception landed in different chunks without parent context.

Retrieval

Gold absent

The right evidence exists but never appears in candidates.

Sub-topic 5 of 15

Corpus and Parsing Gaps

If the source is missing, retrieval tuning cannot help. If parsing loses a table, chunking cannot recover it. Always verify source existence and parser quality before touching embedding settings.

Corpus gap

Add source, assign owner, document authority, and re-index.

Parsing gap

Repair parser, add parser regression test, compare extracted text.

Metadata gap

Fix source version, access, section, freshness, or domain labels.

Sub-topic 6 of 15

Retrieval Failures

Retrieval failures split into recall failures and ranking failures. If gold evidence is absent from the candidate pool, improve chunking, filters, query rewriting, hybrid search, or indexing. If gold exists but ranks low, consider reranking, score fusion, or top-k policy.

Sub-topic 7 of 15

Prompt and Generation Failures

If the final context contains the right evidence but the answer is unsupported, the problem is likely prompt, context injection, citation discipline, or model behavior. Check whether the prompt clearly says "use only evidence" and whether the answer cites the exact supporting source.

Sub-topic 8 of 15

Safety Failures

Safety failures include leaking restricted context, following instructions embedded in retrieved documents, using stale policies, or answering high-risk questions without enough evidence. These failures should become blocking tests.

Sub-topic 9 of 15

What To Fix First

Use this order: source existence, access/freshness policy, parsing, metadata, chunking, retrieval recall, ranking/reranking, context injection, prompt, answer formatting. This prevents polishing an answer path that lacks trustworthy evidence.

Sub-topic 10 of 15

Architecture View

Failure analysis architecture showing a trace captured from a bad answer, classified against the failure taxonomy, assigned an owner, placed in priority order, turned into a recommended fix, converted into a replay test, and enforced by a release gate
Failure analysis turns a single bad answer into a traced, owned, and permanently tested fix.
Sub-topic 11 of 15

Replay Tests

Every serious failure should become a replay test with frozen input, expected behavior, and owner. Replays are how teams avoid celebrating the same bug fix every month.

Sub-topic 12 of 15

Common Mistakes

M01

Prompt-tuning every failure

Symptom: if the gold chunk was never retrieved, prompt tuning is noise and the answer stays wrong.
Better move: confirm the gold chunk is in the final context before touching prompt wording.
M02

No trace ids

Symptom: without traces, debugging becomes storytelling, and two engineers give two different explanations for the same failure.
Better move: attach a trace id to every request so the whole pipeline is replayable.
M03

No replay tests

Symptom: fixed failures quietly return after a prompt or index change because nothing checks for them again.
Better move: convert every closed failure into a frozen replay case in the regression suite.
M04

Ignoring risk

Symptom: a rare legal or security failure gets the same priority as a common cosmetic formatting miss.
Better move: weight the fix queue by risk and frequency, not just by how loud the complaint was.
M05

Treating every failure as equally urgent

Symptom: the triage board fills with low-impact issues while a high-risk safety failure waits in the same queue.
Better move: score failures by blast radius and user harm before scheduling the fix.
M06

Closing a ticket without a replay test

Symptom: the team believes an issue is resolved, but the same question fails again two releases later.
Better move: require a passing replay test as the definition of "closed," not just a manual re-check.
M07

Blaming the model when the corpus was the gap

Symptom: engineers spend a week tuning prompts and rerankers for a question that has no correct source in the index.
Better move: verify the source document exists and is indexed before assuming the model or retriever is at fault.
M08

Not separating recall failures from ranking failures

Symptom: a team lowers the top-k or rewrites the prompt when the real issue is that gold evidence never entered the candidate pool at all.
Better move: check whether the correct chunk was retrieved at all before deciding whether the fix belongs to recall or ranking.
Sub-topic 13 of 15

Project Roadmap

Build a failure triage board that receives traces, classifies root cause, assigns owner, recommends fix, and creates replay tests. This becomes the operating system for improving a production RAG product.

Sub-topic 14 of 15

Interview-Level Understanding

A strong answer sounds like this: "I treat every bad RAG answer as a trace, not a verdict. I follow the question through query rewriting, retrieval, ranking, context assembly, and generation to find the exact stage where it broke. I classify the failure against a taxonomy — corpus, parsing, chunking, retrieval, prompt, or safety — assign an owner, and prioritize by risk and frequency rather than fixing whatever complaint is loudest. Once I understand the root cause, I turn the incident into a replay test so the fix is permanent, and I use those replay tests as a release gate before shipping changes."

Sub-topic 15 of 15

Points To Remember

  • Failure analysis fixes system behavior, not just the visible answer.
  • A complete trace makes every failure explainable from question to answer.
  • The failure taxonomy separates corpus, parsing, chunking, retrieval, prompt, and safety issues so the right owner fixes the right layer.
  • Fix priority should follow risk and frequency, and recall failures need different fixes than ranking failures.
  • Every resolved failure becomes a replay test that guards the release gate.
← Chapter 23 ProjectTake the Quiz →