Why do LLMs hallucinate, and how do you reduce it?
Why do LLMs hallucinate, and how do you reduce it in a product?
TL;DR
LLMs are trained to produce plausible next tokens, not to check facts. When the answer isn't well represented in training data or the context, the model still produces fluent, confident text, and that's a hallucination. Training also tends to reward guessing over saying "I don't know". You can't eliminate it, but you can reduce and contain it: ground answers in retrieved sources (RAG) with citations, allow and encourage abstaining, use tools for facts and math, constrain outputs with schemas, verify claims with a second check, and design the UX so users can see sources and correct mistakes.
Key points
- Two kinds: factuality errors (wrong about the world) and faithfulness errors (contradicting or going beyond the provided context).
- Triggers: rare facts, questions after the knowledge cutoff, long tail entities, ambiguous questions, and leading questions that presuppose something false.
- Mitigations:
- RAG with instructions to answer only from the context and cite chunk IDs.
- An explicit escape hatch: "If unsure, say you don't know."
- Tools for lookups, calculations and current data instead of recall.
- Lower temperature for factual tasks.
- Verification: check that each cited quote really exists in the source, or use an LLM judge to check faithfulness.
- Human review for high-stakes outputs (legal, medical, financial).
- Measure it: track faithfulness and groundedness on an eval set, and sample production traffic.
Example
User: "What's the refund window for EU customers?"
Context: "EU customers can request a refund within 14 days."
Bad: "EU customers have 30 days, or 60 for premium members." ← invented
Good: "EU customers can request a refund within 14 days [doc-12]."Common follow-ups
- Does RAG eliminate hallucinations? No. The model can still ignore, misread or go beyond the context, and retrieval can return the wrong chunks.
- Can you detect hallucinations automatically? Partly: citation checks, NLI or LLM-judge faithfulness scores, and comparing several samples (low agreement suggests guessing).
What interviewers look for
Tip
Why it happens (next-token prediction, rewarded guessing), layered mitigations, and measuring it instead of hoping.
- Red flag: "we told the model not to hallucinate in the prompt."