Articles

Why LLMs Hallucinate, and How to Reduce It

An LLM hallucination is a fluent, confident output that is factually wrong — a byproduct of next-token prediction, not a bug you can simply patch.

Chisato Chisato · · 4 min read
Abstract purple neural network fibers

A hallucination is when a large language model produces output that’s fluent and confident but factually wrong — a fabricated citation, an invented API method, a plausible-sounding date that never happened. It’s not a glitch in the traditional software sense. It’s a direct consequence of how LLMs generate text in the first place, which is why it can’t be fixed with a patch and has to be managed instead.

Why it happens

An LLM doesn’t retrieve facts from a database. At every step, it predicts the most statistically likely next token given everything before it, based on patterns learned across its training data. Most of the time, the most likely continuation is also the correct one, because correct information dominates the training distribution. But the model has no internal mechanism that distinguishes “I am recalling a verified fact” from “I am generating a plausible continuation” — both feel identical from the inside, because there is no inside. It’s the same underlying process either way.

This gets worse in a few predictable situations:

  • Sparse training data. Ask about a niche library version, an obscure historical event, or a long-tail fact, and the model has seen fewer examples to anchor its predictions, so it fills gaps with the most plausible-sounding pattern rather than an actual fact.
  • Long, multi-step reasoning. Errors compound. A wrong intermediate claim becomes the premise for the next sentence, and the model has no way to backtrack once it’s committed to a token.
  • Pressure to answer. Models are trained to be helpful and to produce a complete response. A model that’s uncertain will often still generate a specific, confident-sounding answer rather than an honest “I don’t know,” because refusals were comparatively rare and low-reward during training.

Sampling temperature and hallucination

Temperature controls how much randomness goes into token selection. Higher temperature increases the chance of picking a lower-probability token, which increases creative variation but also increases the odds of drifting into unsupported claims. Lower temperature makes output more deterministic and repetitive but doesn’t eliminate hallucination — a model can be extremely confident and still wrong, because confidence and correctness are not the same signal in this architecture.

Reasoning models don’t solve it, they redirect it

Reasoning models that generate an explicit chain of intermediate steps before answering tend to hallucinate less on tasks that benefit from decomposition, because working through a problem step by step gives the model more opportunity to self-correct within a single generation. But the reasoning trace itself can contain fabricated steps that look rigorous while being wrong — a well-formatted derivation is not the same as a correct one. Chain-of-thought prompting helps most on tasks with a checkable logical structure, and helps least on tasks that are fundamentally about recalling a specific fact the model never learned accurately.

Practical mitigations

Retrieval-augmented generation. RAG grounds a model’s output by retrieving relevant documents and inserting them into the context before generation, so the model can quote or paraphrase real source material instead of relying purely on parametric memory. This is the single most effective mitigation for factual questions, because it changes the task from “recall a fact” to “summarize this provided text,” which the model is much better at.

Fine-tuning on domain data. Fine-tuning can improve accuracy within a narrow domain by exposing the model to more examples of the specific facts and formats it needs, but it doesn’t fix the underlying mechanism — a fine-tuned model can still hallucinate confidently about anything outside the data it was tuned on.

Smaller, well-scoped context windows. Giving a model exactly the information it needs — rather than relying on it to recall something from training — shrinks the surface area for fabrication. This is part of why keeping prompts scoped and relevant matters more than stuffing a large context window with tangentially related material.

Prompting for calibrated uncertainty. Explicitly instructing a model to say “I don’t know” or to cite which parts of its answer are uncertain measurably reduces confidently-wrong output, though it doesn’t eliminate the underlying tendency — it just makes the model more willing to flag its own gaps.

Human or automated verification for high-stakes output. For anything consequential — legal, medical, financial, or production code — treat LLM output as a draft that requires verification against a real source, not a finished answer.

Hallucination vs bias vs error

These three get conflated but are different failure modes. Bias is systematically skewed output reflecting patterns in training data — for example, associating a profession with one demographic more than reality warrants. A retrieval error in a RAG system is the model faithfully summarizing a wrong or outdated source document. A hallucination specifically means the model generated a claim that has no basis in either its training data or any provided context — it’s invented, not skewed or mis-sourced.

The takeaway

Hallucination is a structural property of next-token prediction, not a solvable bug — a model has no built-in way to distinguish recalled fact from plausible generation. The practical response is to reduce reliance on unaided recall: ground answers in retrieved sources with RAG, scope context tightly, prompt for calibrated uncertainty, and verify anything high-stakes against a real source rather than trusting fluency as a proxy for correctness.

Chisato Chisato · · 5 min read

What Is Catastrophic Forgetting in AI Fine-Tuning?

Catastrophic forgetting is when training a model on new data erases skills it already had. Why it happens during fine-tuning, and how teams work around it.

#AI #LLMs #Machine Learning