Search

Why LLMs Hallucinate

Why LLMs Hallucinate

The short answer

Quick answer: A language model generates text by predicting plausible next words. It was trained to produce text that looks like its training data, not to check statements against the world. Most of the time, plausible and true are the same thing. When the model lacks the relevant knowledge, the same process still produces a fluent, confident answer, because nothing in it distinguishes "I know this" from "this sounds right". The result is a hallucination: an invented fact, citation, quote or function name. Hallucinations can be reduced a great deal by giving the model the source material and tools it needs, but not removed entirely.

Also Read: How Tokenization Works and Why It Affects AI - How To's

What counts as a hallucination

The term covers output that is fluent and confident but false or unsupported. Researchers, as in A Survey on Hallucination in Large Language Models, usually separate two kinds:

TypeMeaningExample
Factuality hallucinationContradicts real-world facts, or cannot be verifiedCiting a court case that does not exist
Faithfulness hallucinationContradicts the user's instructions or the supplied documentA summary that includes a claim the source never made

Typical forms:

  • Fabricated references: papers, URLs, legal cases and quotations that look right and are not real.
  • Wrong specifics: dates, figures, names and version numbers.
  • Invented code: functions, parameters or packages that do not exist.
  • False attribution: a real quote assigned to the wrong person.
  • Confident answers to impossible questions, such as details of an event that never happened.

Some people prefer the word "confabulation", since the model is not perceiving anything. "Hallucination" is the term that stuck.

Cause 1: It predicts text; it does not look things up

As explained in how LLMs predict the next word, a model outputs a probability for each possible next token and picks one. There is no database of facts inside it and no step where a claim is checked.

What it knows is stored as patterns in its weights: a lossy, compressed impression of its training text. Facts that appeared thousands of times are captured firmly. Facts that appeared once or twice are captured faintly, or blended with similar ones.

So when you ask for the title of an obscure researcher's 2014 paper, the model produces something with the right shape: a believable title, a believable journal, a believable year. It is generating the most likely text of that kind, which is not the same as retrieving a record.

Cause 2: The model cannot tell knowing from guessing

When a person does not know something, they usually notice. A language model has no such built-in signal available to it by default. The process that produces a correct, well-supported answer is the same process that produces a fabricated one, and both come out equally fluent.

A model's internal probabilities do carry some information about uncertainty, but confident-sounding prose is not a reliable guide to it.

Cause 3: Training rewards answering

  • Pretraining teaches the model to continue text. Text on the internet rarely says "I don't know"; it states things.
  • Later training to make models helpful rewards giving answers. If guessing is rewarded more often than abstaining, models learn to guess.
  • Evaluation often scores a wrong answer and a declined answer the same, which again favours guessing.

Model developers now train deliberately for calibrated refusals: saying when information is missing or uncertain. That has improved matters significantly, but the tension between being helpful and being cautious remains.

Cause 4: Gaps and errors in what it learned

  • Knowledge cut-off. The model knows nothing after its training data ends, and may answer questions about recent events with outdated information.
  • Rare topics. Niche subjects, small organisations and private individuals are thinly covered.
  • Errors in the data. The training text contains mistakes, myths, jokes and fiction, and the model absorbed those too.
  • Your private information. It has never seen your company's documents or your codebase.

Cause 5: The prompt steers it there

  • False premises. "Why did the Eiffel Tower move to Rome in 1987?" invites an explanation of something that never happened.
  • Forced specificity. Demanding five citations when the model knows of two encourages it to invent three.
  • Long contexts. With a great deal of text in the prompt, details can be missed or mixed up.
  • Sampling. Output is chosen with some randomness. Higher temperature settings make unlikely, and sometimes wrong, tokens more probable.
  • Snowballing. Once the model has written an error, everything after is conditioned on it, and it tends to stay consistent with the mistake.

How to reduce hallucinations

Give it the facts: grounding

The most effective technique is to put the relevant source text in the prompt and ask the model to answer from it. This is retrieval-augmented generation, introduced in the paper Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. The model's job shifts from recalling to reading. See how RAG works.

Give it tools

Let the model run a web search, query a database, call a calculator or execute code, then answer from the results. See how AI agents use tools.

Ask for evidence

Have the model quote the passage that supports each claim, or cite the document it came from. Claims with no supporting quote can be dropped or flagged.

Also Read: Transformers Explained: The Architecture Behind AI

Allow it to say "I don't know"

Explicitly state that "the documents do not say" is an acceptable answer. This simple instruction prevents a lot of invention.

Shape the task

  • Lower the temperature for factual work.
  • Ask precise questions with the context needed.
  • Break large tasks into steps that can each be checked.
  • Request structured output, so missing fields are obvious.

Verify

  • For code, run it. Compilers and tests are excellent hallucination detectors.
  • For facts, check primary sources.
  • Use a second pass, by a model or a person, to compare claims against sources.
  • Keep a human in the loop where errors are costly: law, medicine, finance.

For choosing among approaches, see fine-tuning vs prompting vs RAG.

Can it be eliminated?

Not completely. A system that generates language from learned patterns will sometimes produce something false. Even with the right document in front of it, a model can occasionally misread or over-generalise.

The same ability that causes hallucination is also what makes these models useful: producing new text that was not in the training data. Writing a story, drafting an email or proposing a design all require going beyond stored facts. The aim is to keep that flexibility while anchoring factual claims to evidence.

Rates have fallen substantially as models, training methods and tooling have improved, and well-grounded systems can be very reliable. The sensible stance is to treat unsupported model output as a draft from a knowledgeable but fallible assistant.

Frequently asked questions

What is an AI hallucination?

Output from a model that is presented confidently but is false, fabricated or not supported by the provided sources.

Why do LLMs make up citations?

They learned what citations look like and generate text in that format. Without access to a real database of sources, the result can be a plausible invention.

Does a lower temperature stop hallucinations?

It reduces randomness but does not fix missing knowledge. A model can be consistently wrong at temperature zero.

Does RAG eliminate hallucinations?

It reduces them substantially by supplying real source material. Errors can still occur if retrieval returns the wrong passages or the model misreads them.

Conclusion

Language models hallucinate because they are built to produce plausible text, and plausibility is not truth. They have no automatic sense of the edge of their knowledge. The practical response is to supply what they need: source documents, tools, permission to abstain, and a verification step. Do that, and the problem shrinks from a deal-breaker to a manageable risk.

Related articles

Sources and further reading

TWT Staff

TWT Staff

Writes about Programming, tech news, discuss programming topics for web developers (and Web designers), and talks about SEO tools and techniques

Your experience on this site will be improved by allowing cookies Cookie Policy