RAG Still Hallucinates? Find the Gap Before Switching Models
Debug RAG hallucinations at the source: check ingestion, retrieval, stale documents, citation support and missing-answer behavior before changing models.
Why can RAG still hallucinate? Retrieval may miss the right passage, return outdated evidence, or supply text that does not support the answer. Trace one claim to its source before changing models.
Your assistant has access to the right documents, yet its answer is wrong. It cites a page that discusses the topic but does not support the conclusion. It combines two versions of a policy, misses an exception in a table or answers confidently when the requested fact is absent. Adding retrieval has changed where evidence can come from; it has not removed the need to check how that evidence is used.
This guide offers a practical way to debug RAG hallucinations. RAG means retrieval-augmented generation: the application finds material and supplies it to a model as context. We will use a fictional internal help assistant that answers questions about software access. The examples are editorial illustrations, not a measured experiment or a claim about a particular vendor's current reliability.
LangChain's RAG evaluation tutorial separates checks on the answer from checks on retrieved material. That distinction is useful here. A retrieval result can be relevant without being sufficient, and an answer can sound correct without being grounded in the supplied evidence. Treat those as separate questions throughout the investigation.
Select one questionable claim and find the exact source passage it relies on. If the passage was not retrieved, investigate retrieval; if it was retrieved but does not support the claim, investigate answer generation. Record both the document version and the result.
Write down the exact claim that is wrong
Begin with the user's question, the assistant's answer and the specific unsupported claim. The whole response may not be wrong. Perhaps the assistant correctly explains how to request access but invents the approval deadline. Identifying the narrow claim makes the investigation more useful than labeling the entire system as hallucinating.
For the fictional access assistant, the disputed statement might be that contractors can keep repository access after a project ends. Write the expected behavior separately: the assistant should find the current rule, identify any relevant exception and avoid inventing a permission when the available documents do not establish one. That gives you a clear target for verification.
Save the retrieved passages and their identifiers from the failed run. If you search the document store again later, the results may differ because the index, query or source content changed. You need the evidence the model actually received, not the evidence you wish it had received. Preserve only the material necessary for the investigation and handle private content appropriately.
Check whether the source contains the answer
Before tuning embeddings or changing the model, inspect the source collection. Is the requested fact actually present? A system cannot reliably retrieve a rule that was never published or ingested. If the source is silent, the correct behavior may be to say that the answer is not available and direct the user to the responsible process.
Look for the scope of the rule as well as the relevant sentence. A paragraph about employees may not apply to contractors. A policy for one repository group may not apply to another. A date in the footer may describe the document template rather than the policy's effective period. These distinctions often determine whether an apparently relevant passage supports the answer.
Create a small reference note with the correct source and the conditions under which it applies. Do not ask the model to generate the expected answer from the same failed retrieval output. The reference needs enough independent review to serve as a useful target. Otherwise your evaluation can reproduce the same assumption that caused the original mistake.
Follow the answer back to evidence
Inspect ingestion before blaming retrieval
The original document and the searchable representation may not contain the same usable information. A parser can lose table structure, merge columns, omit headings or separate a footnote from the statement it qualifies. When that happens, the retriever may return exactly what is in the index while the index itself has already lost the meaning.
In the access-policy example, a table might have one column for employees and another for contractors. If extraction turns the rows into a single undifferentiated paragraph, the assistant may associate an employee exception with a contractor. Changing the generation prompt does not repair the missing relationship in the underlying text.
Compare a problematic source page with its ingested chunks. Check identifiers, headings, table labels, dates and nearby exceptions. Save a sanitized fixture of the parsing failure when possible. Fixing ingestion should be verified by inspecting the new representation and rerunning the affected question, rather than assuming that a successful indexing job means the content was preserved correctly.
Check the query the retriever actually used
The user's wording may not be the query sent to the retriever. An application can rewrite the question, expand terms or use conversation history to build a search. Those steps can help, but they can also drop a qualifier that matters. The word contractor, a product version or a date range can disappear before retrieval even begins.
Record the original question and the final retrieval query for the failed case. Compare them for lost constraints. If the user asks about access after a project ends and the rewritten query asks only about requesting access, the returned documents may be relevant to the wrong task. The final answer can then look grounded while answering a different question.
Test query changes with a focused set of examples. Do not optimize for one phrasing alone. Include equivalent wording, an explicit exception and a question with a similar vocabulary but a different intent. The goal is to preserve meaning across reasonable user language, not to memorize a single string that happens to retrieve the desired passage.
Find the stage before changing the model
Observed evidence
Inspect next
Check the change
The required passage is absent from the retrieved results.
Document ingestion, access rules, chunk boundaries and retrieval settings.
Check whether the same question now retrieves the required passage.
The passage is present, but it is an old policy version.
Source version, effective date and index refresh.
Confirm the answer uses the applicable version, including exceptions.
The passage is current, but the answer adds an unsupported deadline.
The exact claim, supplied context and answer instructions.
Remove the unsupported claim and test questions whose answer is absent.
The answer cites a real document that does not support the claim.
Citation-to-claim alignment, including tables and footnotes.
Check each cited passage against the specific claim, not just the topic.
This is a diagnostic decision table, not measured performance. Preserve the original question and document version, then change one suspected cause at a time.
A retrieved passage can be topically related without containing the evidence needed for the answer. Inspect whether the necessary source appears, whether the relevant section is included and whether contradictory or obsolete material is mixed in. A similarity score alone does not establish that the result is sufficient for the user's question.
For the access assistant, a general onboarding page may rank above the current offboarding rule. That can explain a wrong answer even when the search results contain many familiar terms. Identify the missing evidence before changing the number of returned chunks. More context can introduce more irrelevant or conflicting material as well as more useful information.
Use a small labeled set of questions with known supporting passages. Track which required passages are retrieved under the configuration being tested. Keep the label scope explicit: finding one correct passage is not the same as finding every condition needed for a complete answer. Review misses and near misses, especially where a relevant document is present but the crucial exception is absent.
Preserve document identity and version
A policy archive may contain several versions of the same rule. If the assistant combines them without recognizing dates or supersession, it can produce an answer that never existed in any valid version. Retrieval quality therefore depends partly on the metadata that lets the application choose the right document for the requested time and scope.
Store a stable source identifier, version or effective date when the source provides one. Distinguish the publication date from the date the file was ingested. A document uploaded yesterday may describe a rule from several years ago. Do not label it current merely because the ingestion timestamp is recent.
When the user asks a historical question, older material may be exactly what is needed. The answer should make that time scope visible. When the user asks for the current rule, the system should not silently use an archived version because it ranks well. Test both kinds of question so freshness handling does not become a blunt rule that discards legitimate historical evidence.
Check whether the supplied context supports each claim
Once retrieval is understood, inspect the final answer claim by claim. For each meaningful statement, ask which supplied passage supports it. A citation that points to a related document is not enough. The cited material needs to establish the actual relationship, condition or value asserted in the answer.
In the fictional example, the source may say that an administrator reviews exceptions. That does not establish that an exception was granted to this user, nor that approval is automatic. A model can bridge that gap with plausible language. Mark the unsupported bridge rather than treating the presence of a citation as proof of grounding.
You do not need to check every harmless connective word as a separate fact. Focus on claims that change the user's understanding or next action. Permissions, deadlines, requirements and exceptions deserve especially clear support. An answer with fewer claims may be more useful than a fluent paragraph that adds details the source never supplied.
Give missing evidence a useful response path
A RAG system needs a deliberate behavior for questions the evidence cannot answer. That can be a clear statement of what is missing, a request for a relevant detail or a pointer to the original process. Without that path, the application may reward the model for always completing an answer, even when the correct response is uncertainty.
For example, the assistant can explain that it found the general access policy but not the contractor exception for the named project. It can ask for the project classification or direct the user to the policy owner. This is more useful than a generic refusal because it identifies the exact gap that prevents a grounded answer.
Evaluate this behavior directly. Include questions whose answers are absent, ambiguous or dependent on a missing user detail. A test set containing only answerable questions can make an always-answering system look stronger than it is. The desired outcome is not maximum refusal or maximum completion; it is an appropriate response to the evidence available.
Keep instructions separate from retrieved text
Retrieved documents are evidence, not automatically authorized instructions for the agent. A page can contain irrelevant directions, copied prompts or malicious text that attempts to change the task. The application should preserve the distinction between the user's request, trusted system behavior and material retrieved for reference.
This matters even in a document collection that is usually trusted. A support ticket may quote an attacker, a report may include a dangerous instruction as an example, and an imported page may contain text outside the intended knowledge scope. The model needs to use that content as data without treating it as permission to perform unrelated actions.
Keep access and action permissions narrow at the application level. A help assistant that answers questions does not need to send messages or edit repository membership merely because a retrieved page mentions those actions. Evaluate the boundary with safe test cases and record what the system actually does. A stronger prompt alone is not evidence that every instruction-confusion path is closed.
Compare one configuration change at a time
When an answer fails, it is tempting to change chunk size, retrieval count, query rewriting, model and prompt together. A better result after that bundle tells you little about the cause. Choose a hypothesis, change the relevant variable and compare the same set of questions before and after the change.
If the necessary table labels were lost during ingestion, start there. If the correct passage was retrieved but ignored, investigate answer generation and evidence checking. If archived rules dominated the result, inspect version filtering. Matching the change to the observed failure helps avoid spending time on a layer that was already behaving as designed.
Keep a record of regressions as well as improvements. A configuration that helps the contractor question may hurt a historical-policy question. Evaluate the tradeoff in terms of the product's intended use, not just the most memorable example. Where different question types need different handling, make that decision explicit instead of hiding the conflict inside one average score.
Build evaluation cases from real failure shapes
A useful RAG evaluation set contains more than easy factual questions. Include missing answers, conflicting versions, table-based rules, exceptions, similar terminology and questions that require multiple supporting passages. Use sanitized real failures when available and clearly label any constructed examples. The test set should reflect the decisions users actually need to make.
For each case, record the question, expected evidence, acceptable answer behavior and relevant limits. Some cases may have several valid phrasings. Others may require a specific abstention because the documents do not establish the answer. Avoid scoring only for an exact sentence when the real requirement concerns support and scope.
If you use a model to judge answers, review its decisions against human-checked examples. A judge can miss the same unsupported inference as the answering model. Automated scoring is useful for repeatability and triage, but the evidence for important claims still needs inspection. Keep the raw outcome available so a summary metric cannot hide a serious failure category.
Turn the diagnosis into a reusable check
Finish the investigation with a short explanation of where the evidence chain broke. Was the source absent, parsing damaged, retrieval incomplete, version selection wrong or generation unsupported? More than one layer may contribute, but each claim about the cause should point to something you observed in the failed run.
Save the focused evaluation case and the artifact that exposed the issue. That might be a parsed table fixture, a retrieval result with a missing exception or an answer whose citation does not support its conclusion. Reuse the case when changing the system so the same failure is easier to catch before users encounter it again.
The useful goal is not to declare RAG free of hallucinations. It is to make the path from question to source to answer inspectable, and to stop when that path does not support a conclusion. Better retrieval and better answer checking solve different parts of the problem. Keeping them separate gives you a clearer diagnosis and a more honest basis for trusting the result.