Why Language Models Hallucinate
By the Katkat team · Updated · 8 min read
Quick overview
Why LLMs make things up: the training objective, knowledge gaps, decoding and prompt pressure, and which hallucinations you can reduce versus fully fix.
After this lesson you will be able to explain, in an interview, why a language model produces fluent but false statements, and to trace each case to a cause: the training objective, a gap in the model's knowledge, the decoding step, or pressure from the prompt. You will also be able to say which causes engineering can reduce, which it can only contain, and why "just set temperature to 0" is not an answer.
What counts as a hallucination
A hallucination is model output that is fluent and confident but not supported by reality or by the material you gave the model. Two kinds are worth separating, because the fixes differ:
- Factuality errors: the claim is false about the world. Example: a wrong founding year for a company.
- Faithfulness errors: the claim contradicts or goes beyond the source you supplied. Example: a summary that states a number that is not in the document.
Interviewers like this split. Factuality errors come mostly from what the model did or did not learn. Faithfulness errors come mostly from how you built the prompt and context.
The training objective rewards plausibility, not truth
A pretrained model is trained to minimise cross-entropy on the next token. For each position in the text, it is pushed to assign high probability to the token that actually came next. Nothing in that loss says "this sentence is true." It only says "this continuation is likely given the text I have seen."
Two consequences follow:
- The model always produces a distribution. For any prompt, the softmax gives probabilities that sum to 1. There is no built-in "I don't have this" state. A question about an obscure person still gets a fluent, plausible-looking answer, because plausible-looking text is what the objective optimised.
- Training text rarely models abstention. Web text seldom says "I do not know the birthday of this specific person." It usually just states something. So the learned habit is to continue confidently.
Truth is only learned indirectly, to the extent that true statements are more predictable than false ones in the training data. That works well for facts repeated many times and badly for facts seen once or never.
Knowledge gaps: facts the model never learned well
Model weights are a lossy compression of the training data. Facts that appear often, in many phrasings, are stored reliably. Rare facts are stored weakly or not at all. Three gap types matter in practice:
- Long-tail facts: obscure people, small libraries, niche regulations.
- Stale knowledge: anything after the training cutoff, and anything that has changed since.
- Private knowledge: your company's policies, tickets and prices were never in the training data.
When the model is asked about something in a gap, it does not return nothing. It produces the most plausible-sounding completion: a believable name, a realistic URL, a citation with a sensible title. This is why invented references look so convincing.
Worked example: errors compound across claims
Suppose a model states individual claims correctly 95% of the time, and treat the claims as independent for simplicity. An answer containing 10 checkable claims is fully correct with probability:
0.95^10 = 0.95^2 × 0.95^8 = 0.9025 × 0.6634 ≈ 0.599
So roughly 60% of such answers are error-free, and about 40% contain at least one mistake, even though each individual claim looks very reliable. Long answers, summaries and reports hallucinate more often than short ones, simply because there are more places to go wrong. Real claims are not fully independent, so treat this as an intuition, not a prediction.
Decoding: how the answer is picked from the distribution
At each step the model has a probability distribution over the next token, and the decoder picks one. Two mechanisms matter here. See Decoding: Greedy, Temperature, Top-k and Top-p for the full mechanics.
Sampling noise. With temperature 1 and no truncation, low-probability tokens are sometimes chosen. Most of the time that is harmless, but occasionally it picks a wrong name or number.
Snowballing. Generation is autoregressive: every new token is conditioned on everything already emitted, including earlier mistakes. Once the model writes a wrong entity name in the first sentence, later sentences tend to stay consistent with it rather than correct it. One early wrong token can therefore produce a whole coherent, wrong paragraph.
Worked example: low temperature does not add knowledge
Say the model's distribution over three candidate answers to a factual question is:
| Candidate | Correct? | Probability at T=1 |
|---|---|---|
| A | No | 0.40 |
| B | Yes | 0.35 |
| C | No | 0.25 |
- Greedy decoding always picks A. It is wrong 100% of the time, and consistently so.
- Sampling at T=1 picks B 35% of the time, so it is right 35% of the time.
- Temperature 0.5 raises each probability to the power 1/0.5 = 2 and renormalises: 0.16, 0.1225, 0.0625, total 0.345. That gives A ≈ 0.464, B ≈ 0.355, C ≈ 0.181. The correct answer barely moves.
Lowering temperature makes the output more repeatable. It does not make it more correct. If the model's top choice is wrong, a deterministic decoder just repeats the error reliably.
Prompt pressure and post-training
Even a model that has some knowledge can be pushed into hallucinating.
Prompt pressure includes:
- False premises: "Why did the 2019 version of the library remove feature X?" when X was never removed. The model tends to accept the premise and explain.
- Forced formats: "List exactly five peer-reviewed sources." If only two exist, the model will produce three that do not.
- Leading questions: the phrasing signals the expected answer, and the model leans towards agreeing.
- Messy context: irrelevant, contradictory or very long context makes the model less likely to use the right passage. See Context Windows.
Post-training effects. After pretraining, models are tuned to be helpful and to score well with human or automated graders (see From Pretraining to Chat Model: SFT and RLHF). If graders prefer a confident, complete answer over "I'm not sure", the model learns to guess. This is similar to a multiple-choice exam with no penalty for wrong answers: guessing has positive expected value, and abstaining never does. Agreeing with the user (sycophancy) can be rewarded in the same way.
The practical point: some hallucination is a product of how we evaluate and reward models, not only of missing knowledge.
What can and cannot be fixed
| Cause | What helps | What remains |
|---|---|---|
| Missing or stale knowledge | Retrieval-augmented generation, tools, live data lookups | Retrieval can miss the right passage; the model can ignore it |
| Unfaithful use of context | Clear instructions to answer only from sources, quoting, citation checks | Small rates of unsupported claims persist |
| Sampling noise | Lower temperature, top-p, shorter outputs | Consistent wrong answers stay wrong |
| Prompt pressure | Allow "I don't know" explicitly, avoid forced counts, challenge false premises | Users can still phrase leading questions |
| Rewarding guessing | Training that rewards abstention and calibration; evals that penalise confident errors | Depends on the model provider, not your app |
| Compounding over long outputs | Shorter answers, verifying claims individually, structured output | Still non-zero per claim |
The honest summary for an interview: hallucination can be reduced a lot and detected in many cases, but not eliminated, because it comes from the core design of next-token prediction over compressed data. Production systems therefore combine layers: ground the model with retrieval, constrain what it may say, verify outputs, measure the rate with evals, and design the product so a wrong answer is recoverable (citations, "show source", human escalation). For a worked system-design take, see How Would You Reduce Hallucinations in a Support Bot?.
Retrieval deserves a caution. It converts many factuality errors into faithfulness questions, which are easier to measure, but a retrieval miss can still lead to a confident wrong answer. Measuring retrieval and generation separately is covered in Evaluating a RAG System.
How does this come up in interviews?
1. "Why do LLMs hallucinate?" Start with the objective: next-token prediction rewards plausible continuations and has no abstain state. Add knowledge gaps (long-tail, stale, private facts), then decoding effects (sampling noise and snowballing), then prompt and reward pressure. Finish by saying it can be reduced but not removed.
2. "Will setting temperature to 0 stop hallucinations?" No. Temperature 0 makes decoding deterministic, so the model returns its single most likely answer every time. If that answer is wrong, you get the same wrong answer consistently. It helps with repeatability and removes sampling noise, but it adds no knowledge.
3. "Does RAG solve hallucination?" It addresses the largest cause, missing or stale knowledge, by putting source text in the prompt. It does not remove failures: retrieval can return the wrong chunk, the model can ignore or misread context, and it can still add unsupported details. You still need grounding instructions, citation checks and evaluation of both retrieval and generation.
4. "Why would a larger or better-tuned model still make things up?" Scale improves coverage of facts but the long tail never fully disappears, and the objective still has no abstain mechanism. Post-training that rewards confident, helpful-looking answers can encourage guessing. Better models hallucinate less often, but the remaining errors are often more convincing.
5. "How would you measure hallucination in your product?" Split it into factuality and faithfulness. For grounded apps, check each claim against the retrieved sources, using human review on a sample and a calibrated LLM judge at scale. Track the rate over time and on a fixed regression set, and report separately for questions that should be refused.
Common mistakes
- Saying the model "lies" or "knows it is wrong." It has no intent; it produces likely text.
- Claiming temperature 0 or a better prompt fixes factual errors.
- Treating RAG as a guarantee rather than a reduction of risk that needs its own evaluation.
- Mixing up factuality (true about the world) and faithfulness (true to the given source).
- Ignoring that long outputs contain more claims and so more chances to be wrong.
- Forgetting prompt pressure: forced formats and false premises can cause errors in a model that otherwise knows the answer.
- Promising "zero hallucinations" in a design answer instead of describing layers of mitigation and monitoring.