AppliedAIPrep logoAppliedAI/Prep
LLM & GenAI Fundamentals / 05
medium★ EssentialOpenAIAnthropicMicrosoft

What causes LLM hallucinations, and how do you reduce them in a production feature?

Every customer asks how to stop the model making things up. The weak answer is 'better prompts.' The signal is knowing why models hallucinate and layering grounding, abstention, and measurement into a system you can defend.

Updated Aug 2026 · Grounded in real Applied AI Engineer interview loops and written to a senior-engineer editorial bar.

TL;DR: LLMs hallucinate because they are trained to produce fluent, probable continuations, not to know what they do not know. There is no built-in truth check and no access to facts outside their weights. Reduce it by grounding answers in retrieved sources (RAG) with citations, giving the model an explicit "I don't know" path, constraining claims to the provided context, and measuring faithfulness so you know your rate. You contain and measure it; you do not eliminate it.

RAG PIPELINE (press run)
“what is our enterprise refund window?”
embed queryretrieve + rankbuild promptgenerate
Enterprise refund window is 30 days
Enterprise SLA and uptime terms
Pricing tiers and seat limits
Onboarding checklist for admins
Office locations and hours
answer appears here, grounded in the retrieved chunks
A query is embedded, the closest chunks are retrieved and ranked, the top few are stuffed into the prompt, and the model answers grounded in them. Retrieval quality is the ceiling: the answer can only be as good as what it retrieves.

How to approach it. Explain the root cause (next-token objective, no truth signal, closed-book knowledge gaps) before jumping to fixes, because every fix follows from the cause. Then layer the mitigations and put weight on measurement, since "how do you know it improved" is the real test and most candidates skip it.

A strong answer. Why it happens. A model predicts the most probable next token given context. The objective optimizes fluency and plausibility, not factual accuracy, and the network has no internal flag for "I am uncertain" versus "I know this." Hallucination is worst when the answer needs facts not in the weights: recent events, private data, long-tail specifics. The model then confabulates something that reads right. This is how the model works, not a bug you patch away.

Mitigations, layered from highest leverage down:

  • Grounding (RAG). Retrieve relevant sources and instruct the model to answer only from them, with citations the user can click. This is the single biggest lever for knowledge hallucinations: facts come from a controlled corpus, not the model's memory.
  • Abstention. Give an explicit "if the context does not contain the answer, say you do not know" path plus a grounding threshold. A system that declines beats one that confidently invents.
  • Constrain and verify. Restrict the model to the provided context, and for high-stakes outputs add a verification pass that checks every claim traces to a source.
  • Prompting and decoding. Clear instructions, few-shot examples, and lower temperature cut creative drift on factual tasks. Necessary, not sufficient.
  • Fine-tuning / RLHF improves calibration and reduces confident wrongness, but it does not inject missing facts. That is retrieval's job.

Measurement. You cannot improve what you do not measure. Track a faithfulness/groundedness rate on an eval set (does every claim trace to a source), scored by an LLM judge calibrated against human labels, plus production signals like citation clicks and user corrections. State your hallucination rate honestly. "Zero hallucination" in anyone's pitch is a red flag.

LeverFixesCostLimit
RAG groundingMissing/stale factsRetrieval infra, latencyOnly as good as the corpus
AbstentionConfident wrong answersA few declined queriesTune the threshold or it over-refuses
Verification passUnsupported claimsExtra model callAdds latency and spend
Lower temperatureCreative driftNear zeroDoes not close knowledge gaps

Key takeaways

  • Hallucination is the next-token objective working as designed, not a defect, so frame fixes as containment.
  • RAG with clickable citations is the highest-leverage move for factual errors; abstention is the cheap safety net.
  • Fine-tuning improves calibration but never injects fresh facts; that is retrieval's job.
  • Ship a faithfulness metric on day one or quality regressions stay invisible.

What interviewers probe next.

  • "RAG or fine-tuning to fix factual errors?" RAG. Facts change and fine-tuning bakes in stale facts while still hallucinating; retrieval grounds and updates without retraining.
  • "How do you detect hallucination automatically?" Groundedness scoring of each claim against retrieved context, flagging unsupported claims. It is imperfect, so pair it with user-visible citations.
  • "Does lower temperature solve it?" It reduces variance, not the knowledge gap. Necessary, not sufficient.
  • "What about reasoning models or self-consistency?" Chain-of-thought and sampling multiple answers then voting catch some errors at a latency and cost hit; you still need grounding for facts.

Common mistakes.

  • "Just prompt it better" as the whole answer, ignoring grounding and abstention.
  • Fine-tuning to add facts, then fighting stale and still-confident errors.
  • Claiming a method eliminates hallucination rather than reducing and measuring it.
  • Shipping with no faithfulness metric, so degradation goes unnoticed until a customer complains.
HOW DID IT GO?
0
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

No comments yet — be the first to share your approach.