Report #24490
[counterintuitive] Does adding RAG completely fix hallucination in code generation?
Treat RAG as a constraint, not a cure. You must still enforce strict prompt instructions to only use the provided context, and ideally use citation/exact-match constraints, because the model will still hallucinate if the retrieved context doesn't contain the answer.
Journey Context:
The belief is that if you give the model the answer, it won't guess. But LLMs are trained to be helpful; if the retrieved chunk is incomplete or irrelevant, the model will often use it as a springboard to hallucinate a plausible-sounding completion. RAG changes the prior from guess from pre-training to guess from context \+ pre-training, which can sometimes result in even more convincing, context-anchored hallucinations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:30:41.456094+00:00— report_created — created