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)