01
Short answer
In retrieval-augmented generation (RAG), an unsupported answer can originate in retrieval, generation, or both. The model confabulates because the context it received was missing, wrong, or contradictory. Diagnose the failure first. Test retrieval coverage, ranking, and chunking. Add source-support checks and an abstention path, and measure faithfulness separately from general answer quality. Plan for residual unsupported answers. Design and test an abstention path for cases where the available sources do not support an answer.
02
Diagnose before you treat
"Hallucination" covers at least three distinct failure modes, and they have different fixes. The context is missing entirely, the answer exists in your corpus but retrieval never found it. The context is present but ranked too low to make the cut. The context is contradictory, two documents disagree, and the model picked one or averaged them into nonsense. Pull a sample of hallucination complaints and classify them. Measure the share of each failure type in your own workload. Also check cases where the retrieved source is correct but the generated answer misreads or adds to it. Teams that skip this classification and reach for prompt tweaks like "do not hallucinate" are treating the symptom with a word the model does not have a mechanism to obey.
03
Fix retrieval before touching the prompt
Start with coverage testing: use a labeled set of questions across common, rare, ambiguous, and unanswerable requests. Measure whether a source that supports the answer reaches the context supplied to the model. If coverage is low, the problem is upstream of the model, chunking, embeddings, or indexing. Inspect chunk boundaries, document parsing, embedding behavior, and filters. Chunks too small split tables and definitions from their context; chunks too large dilute relevance. There is no universal right size, which is why the answer is to test with your documents rather than adopt a default from a tutorial.
Then check ranking quality and, critically, whether your top results ever contradict each other. Contradictory context needs an explicit source-precedence rule. A model may choose the wrong source or combine incompatible claims; averaging is not a universal model behavior. If your corpus has versioned documents, old policy next to new policy, store version and status metadata at ingestion, and apply the appropriate filters during retrieval. Define which source is authoritative and return uncertainty when the conflict remains unresolved.
04
Force grounding in the prompt contract
Once retrieval is sound, change the prompt contract. Require source references for claims about the retrieved material. Check that each reference resolves to a source available for that request. Separately check that the source supports the claim. A real citation can still be attached to an unsupported statement. Treat citation requirements as one control. Evaluate fabricated references, incorrect attribution, and unsupported claims as separate failure types.
Then build the abstention path, which matters more than people expect. The instruction should be explicit: if the retrieved context does not contain the answer, say so and offer a next step. Abstention feels like a failure when you demo the system and it works. In production it is the feature that makes the system trustworthy. A user who gets "I don't have that information, but here is who does" trusts the system next time. A user who gets a confident invented number does not.
05
Measure faithfulness separately
Generic quality scores hide hallucination. An answer can be fluent, complete, helpful, and wrong. Score faithfulness as its own dimension: does every claim trace to the retrieved context? A model judge can compare individual claims with the supplied sources. Validate its decisions against human labels and include difficult cases such as negation, conflicting versions, and tables. Faithfulness to a source does not establish that the source itself is correct. Track the faithfulness score as its own trend line, segment by query type, and feed the worst failures back into your retrieval test set.
06
Accept the residual and contain it
After retrieval fixes, grounding prompts, and faithfulness measurement, a residue of hallucination remains. The production answer is containment, not elimination. Add post-generation checks on high-stakes outputs, deterministic verification for numbers and dates against source documents, human review for anything where a wrong answer has legal or financial consequences. And set expectations honestly with the business: the system will occasionally be wrong, the design goal is that it is rarely wrong about things that matter and that when it is unsure, it says so.
07
Build a failure table before changing retrieval
Use a small labeled investigation set to establish the diagnosis, then expand it to cover the traffic that matters. Each row needs the user question, the authoritative source, the retrieved chunks, the generated answer, and a failure category. Separate answerable questions from requests that the corpus cannot answer. Otherwise a retrieval test can penalize the system for correctly finding no supporting material.
Consider a returns question where the answer depends on the purchase date and whether the item arrived damaged. This is an illustrative example. A chunk containing the ordinary return window may be relevant but insufficient if the damaged-item exception is in a different section. Label both pieces as required context. Test whether they reach the model together and whether the answer applies the exception to the stated facts.
The failure table should also distinguish stale sources, unauthorized sources, contradictory sources, and correct sources that the model misinterprets. These need different owners. A document owner resolves policy conflicts. An ingestion owner repairs missing content. A retrieval owner fixes selection. The application owner changes answer checks or escalation behavior.
08
Test retrieval and answers separately
Choose the retrieval metric that matches the application. A top-results recall measure asks whether the supporting material appears among the candidates. It does not establish that the final prompt includes the material, that the user may access it, or that the answer uses it correctly. Check the complete path from ingestion to the context supplied for generation.
Run answer evaluation on the same cases. Record whether the answer addresses the question, stays within the sources, applies the correct version, and abstains when support is missing. Keep these judgments separate so that a fluent response cannot hide a grounding failure. Inspect disagreement between human reviewers before relying on an automated judge.
When comparing chunking or ranking changes, hold the rest of the configuration steady where practical. Use the same question set and source snapshot. Record the change in retrieval results, answer quality, latency, and cost. A ranking improvement is useful only if it improves the final task enough to justify its operational trade-offs.
09
Make abstention useful to the user
Define the response for missing support as part of the workflow. It may ask for a missing detail, offer a source link, or route the request to a person with the required authority. Avoid presenting unsupported conclusions alongside an uncertainty disclaimer. The application should withhold the unsupported claim rather than expect the disclaimer to cancel its effect.
Test the opposite failure too: unnecessary abstention. A system that refuses answerable questions may satisfy a narrow faithfulness check while failing its users. Track supported answers, unsupported answers, appropriate abstentions, and unnecessary abstentions together. Include the time and effort needed to resolve escalated cases.
Before release, add regression cases for every important failure the team corrected. Preserve a held-out set that the team does not repeatedly tune against. After release, sample new question types and recheck source freshness. A corpus update can introduce conflicting versions or change the context boundaries even when the model and prompt remain unchanged.
10
Related
Where to read next on the same subject.