LLMs & GenAI

Why LLMs Hallucinate

Understanding root causes of un-grounded factual errors in autoregressive language generation.

🟡 intermediate5 min readllmmust-know
Hallucination refers to instances where Large Language Models generate un-grounded, factually incorrect, or contradictory text with high confidence. Root causes include next token prediction probability sampling, noisy pretraining data, parametric memory degradation, and exposure bias during autoregressive decoding. Mitigations include RAG vector grounding, Chain of Thought reasoning, constrained decoding, self-consistency sampling, and external fact verification.

What is an LLM Hallucination?

A Hallucination occurs when a Large Language Model generates text that is factually false, illogical, or un-grounded while outputting tokens with high confidence.

  User Query:  "Who won the 2028 World Cup?"
  LLM Output:  "Brazil won the 2028 World Cup by defeating Germany 3-1 in Tokyo." (CONFIDENT HALLUCINATION!)

The model generates fluent, authoritative prose, making hallucinations dangerous in legal, medical, and financial applications.

Taxonomy of Hallucinations

┌──────────────────────────┬──────────────────────────┐
│ 1. PARAMETRIC            │ 2. CONTEXTUAL (INTRINSIC)│
├──────────────────────────┼──────────────────────────┤
│ Model invents false facts│ Model directly           │
│ from parameter memory.   │ CONTRADICTS information  │
│ (e.g. inventing a fake   │ provided inside the      │
│ book title or quote).    │ current prompt context.  │
└──────────────────────────┴──────────────────────────┘

Core Causes of Hallucination

┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ A. TRAINING OBJECTIVE    │ B. NOISY PRETRAINING DATA│ C. EXPOSURE BIAS        │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Next-token loss rewards  │ Scraping web text inserts│ Small errors early in    │
│ plausible fluent text.   │ false rumors and un-     │ generation compound      │
│ Model is not penalized   │ verified facts into      │ exponentially over long  │
│ for confident guessing.  │ parameter memory.        │ output sequences.        │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘

1. Objective Function Mismatch

Cross-entropy pretraining loss $-\sum \log P(x_t \mid x_{<t})$ rewards outputting high-probability fluent text.

The model is never penalized for lack of truthfulness during pretraining. If a fact is missing from parameters, generating a plausible-sounding completion yields lower loss than outputting "I do not know".

2. Sycophancy & Prompt Pressure

If a user prompt contains a false premise ("Why did Einstein invent the TV?"), the attention mechanism adapts to the prompt context, generating fake explanations to satisfy the user statement.

Production Mitigations

  1. Retrieval-Augmented Generation (RAG): Inject verified ground-truth document passages into prompt context and instruct the model: "Answer using ONLY provided context. If context does not state the answer, state I do not know."
  2. Chain-of-Thought Reasoning: Instructing the model to show intermediate reasoning steps reduces premature false conclusions.
  3. Lower Sampling Temperature ($T \to 0$): High temperature increases randomness, forcing sampling into low-probability tail tokens where hallucinations spike.
  4. Self-Consistency (Majority Voting): Sample 10 independent responses at $T=0.7$. If 9 responses agree on a fact and 1 hallucinates, majority voting selects the true fact.

Say this out loud

LLM Hallucination refers to generating factually false text with high confidence. Root causes include next-token loss rewarding plausible fluency over truthfulness, noisy pretraining data, and exposure bias during autoregressive decoding. Mitigations include RAG vector grounding, lowering sampling temperature, Chain-of-Thought reasoning, and self-consistency voting.

Followups to expect

  1. What is Hallucination Rate Evaluation (TruthfulQA / HaluEval)? Benchmark datasets designed to measure how frequently language models output false rumors, common superstitions, or un-grounded claims.
  2. Can RLHF / DPO eliminate hallucinations completely? No. Preference alignment reduces hallucinations by teaching models to express uncertainty ("I am not sure"), but cannot eliminate hallucinations if underlying factual knowledge is absent from pretraining weights.

Check yourself

Question 1 of 3

Why does the next token prediction objective cause LLMs to generate confident hallucinations instead of admitting ignorance?

More in LLMs & GenAI

See all →
Pretraining → SFT → RLHF5 minFine-Tune vs RAG vs Prompt: Choosing5 minRetrieval-Augmented Generation5 min