DEV Community

Navas Herbert
Navas Herbert

Posted on

𝙷̲𝚊̲𝚕̲𝚕̲𝚞̲𝚌̲𝚒̲𝚗̲𝚊̲𝚝̲𝚒̲𝚘̲𝚗̲ ̲𝚖̲𝚒̲𝚝̲𝚒̲𝚐̲𝚊̲𝚝̲𝚒̲𝚘̲𝚗̲

A question that exposes how much people misunderstand RAG: "How do you stop the LLM from hallucinating?"

Honest answer: you don't, fully. You layer mitigations, and none of them are bulletproof alone.

𝗙𝗶𝗿𝘀𝘁 𝗹𝗮𝘆𝗲𝗿 - 𝘵𝘩𝘦 𝘱𝘳𝘰𝘮𝘱𝘵 𝘪𝘵𝘴𝘦𝘭𝘧. You explicitly instruct the model to use only the provided context, and give it a fallback phrase for when the answer isn't there. This helps, but LLMs don't perfectly follow instructions, so it reduces hallucination, it doesn't eliminate it.

𝗦𝗲𝗰𝗼𝗻𝗱 𝗹𝗮𝘆𝗲𝗿 - 𝘳𝘦𝘵𝘳𝘪𝘦𝘷𝘢𝘭 𝘲𝘶𝘢𝘭𝘪𝘵𝘺. This one matters more than people think. No amount of clever prompting saves you if you retrieved the wrong chunks in the first place. 𝗚𝗮𝗿𝗯𝗮𝗴𝗲 𝗶𝗻, 𝗴𝗮𝗿𝗯𝗮𝗴𝗲 𝗼𝘂𝘁, no matter how polite your prompt is.

𝗧𝗵𝗶𝗿𝗱 𝗹𝗮𝘆𝗲𝗿 - 𝘵𝘳𝘢𝘯𝘴𝘱𝘢𝘳𝘦𝘯𝘤𝘺. Always return the actual source chunks alongside the answer. If the model does hallucinate, the user can check the claim against the cited text immediately. This one's not really a technical fix - it's a trust mechanism. You're not preventing the lie, you're making it easy to catch.

That third layer is the one I think gets underrated. Sometimes the most valuable engineering decision isn't solving the hard problem - it's making the unsolved part visible instead of hidden.

Sharing what I'm learning in public.

RAG #LLM #AI #PromptEngineering #LearningInPublic

Top comments (0)