Intermediate
Why Do LLMs Hallucinate?
Why can a language model generate an answer that sounds completely certain even when it is entirely wrong? The problem isn't that AI is “lying”. It comes from how LLMs learn language, predict the next token, and deal with uncertainty.
Why Do LLMs Hallucinate?
When a language model answers a question, its response can be fluent, logical, and full of detail while being completely false. It can provide a nonexistent paper, invent the author of a book, attribute a result to an experiment that never produced it, or create a citation that looks exactly like a real scientific source.
This phenomenon is called a hallucination. The name is obviously a metaphor — the model does not “see” or experience hallucinations in the human sense. The problem comes from something much more fundamental about LLMs: the model generates a probable continuation of text rather than directly retrieving truth from some internal database of facts.

A language model isn't searching for truth
An LLM, or Large Language Model, is primarily trained to predict the next token based on the preceding context.
A token does not necessarily correspond to an entire word. It can be a word, part of a word, punctuation, or another piece of text. For the model, text is therefore a sequence of tokens, and its task is to determine what should come next.
In simplified form:
P(x_t \mid x_1, x_2, \ldots, x_{t-1})
represents the probability of token x_t given the previous tokens.
If we enter:
“The capital of France is...”
the model assigns a very high probability to the token corresponding to “Paris”.
The generated token then becomes part of the new context. The model predicts the next token, then another one, and another.
And this is where one of the key problems appears.
The most probable continuation of a text does not necessarily have to be true.
Linguistic probability is not probability of truth
Imagine asking:
“Who wrote the book The Quantum Butterfly Effect in 1987?”
If the book never existed, the correct answer should be something like:
“I can't confirm that such a book exists.”
The model may nevertheless find a strong linguistic pattern leading toward an answer such as:
“The book was written by an American physicist...”
Then comes a name, publisher, publication date, ISBN number, and description.
Everything can look perfect.
And everything can be fabricated.
The model did not necessarily “decide to lie”. It generated a sequence of tokens that statistically fit the context.
We can therefore express the fundamental distinction as:
\text{Plausibility} \neq \text{Truth}
This is one of the most important things to understand when working with LLMs.
How does an answer actually emerge?
In a very simplified model, we can represent generation as:
\text{Context} \rightarrow \text{Representation} \rightarrow \text{Probability Distribution} \rightarrow \text{Token Selection} \rightarrow \text{Next Token}
The process is repeated many times.
The model does not normally generate the entire answer simultaneously. In autoregressive generation, subsequent tokens are selected based on the context that came before them.
This means that an answer can gradually develop in a direction that seemed probable at first but eventually leads to incorrect details.
More importantly, the model does not necessarily contain a representation equivalent to:
“This statement is true.”
in the same sense that a human can consciously know a fact and identify where that fact came from.
An LLM operates through learned representations and relationships. That is extremely powerful, but it is not the same thing as a direct mechanism for verifying reality.
Why can a hallucination sound like an expert answer?
Because LLMs are extremely good at modelling the structure of language.
If a model has learned what a scientific paper looks like, it can reproduce its characteristic structure. It can create an abstract, introduction, methodology, results, discussion, and bibliography.
It can also use specialized terminology and construct sentences that sound highly professional to someone who is not familiar with the subject.
The problem is that correct form does not guarantee correct content.
Imagine a generator capable of producing a perfectly formatted invoice. If the invoice number, amount, and customer information are fabricated, the quality of the formatting changes nothing.
The same principle applies to an LLM.
A model can reproduce the form of information perfectly even when the specific information itself is false.
The worst hallucinations don't look like errors
You might expect a hallucination to look like random nonsense.
Often, the opposite is true.
The most dangerous hallucination can be:
- coherent,
- detailed,
- logical,
- grammatically correct,
- full of specialized terminology,
- written with confidence.
It can even contain citations.
That makes it very easy for a person to feel that they have received a correct answer.
Meanwhile, the only problem is that the content has no counterpart in reality.
Consistency is not evidence of truth.

Does the model “know” that it doesn't know?
This is an even more interesting question.
The model can obviously answer:
“I'm not sure.”
It can also say:
“I don't have enough information.”
But generating such a sentence does not mean that the model has a simple and reliable mechanism for evaluating its own knowledge.
“I don't know” is also generated text.
There is no simple switch:
\text{KNOW} \leftrightarrow \text{DON'T KNOW}
that checks the state of the model's knowledge before every answer.
The model can learn when people usually express uncertainty and learn to produce appropriate phrases.
That does not automatically mean that its assessment of uncertainty is always correct.
What about temperature?
It is often said that hallucinations can be reduced simply by lowering the model's temperature.
Temperature does affect how the model samples from its probability distribution, but it does not solve the fundamental problem.
In simplified form:
P_i = \frac{e^{z_i/T}} {\sum_j e^{z_j/T}}
where z_i is the logit of a given token and T is the temperature.
A lower temperature makes the model more likely to select high-probability tokens. A higher temperature increases the diversity of possible choices.
But if the most probable answer is wrong, lowering the temperature does not make it true.
The model may simply produce the same mistake more confidently and consistently.
Temperature controls the behavior of generation. It is not a fact-verification mechanism.
Where does the problem come from during training?
During training, the model receives enormous amounts of text and learns to predict subsequent tokens.
One way to express the loss function for this task is:
\mathcal{L} = -\sum_t \log P(x_t \mid x_{<t})
The model is therefore optimized to increase the probability of correct tokens within the training data.
This matters because the objective:
“Predict the next token.”
is not identical to:
“Never say anything false.”
Modern models are of course further fine-tuned. They use instruction tuning, human feedback, evaluation, and other techniques intended to improve usefulness and reduce undesirable behavior.
But the fundamental distinction remains between generating language and verifying reality.
Why do models invent sources?
One of the most frustrating examples of hallucination is fabricated literature.
A model might generate a citation such as:
Smith, J. (2019). Advanced Quantum Computation in Biological Systems. Nature Physics.
It looks credible.
There is an author. A year. A title. A journal.
The problem?
The publication may not exist.
The model has learned bibliographic patterns. It knows what citations look like. It knows which journals exist. It knows which names appear in scientific literature.
It can therefore combine these elements into a structure that looks like a genuine reference.
But it is still generated text.
That is why a citation generated by an LLM is not itself proof that the source exists.
If the publication matters, it needs to be checked in an actual bibliographic database, on the publisher's website, or through another reliable source.
RAG: when the model receives real documents
One approach to reducing this problem is Retrieval-Augmented Generation, or RAG.
The idea is relatively simple.
Instead of expecting the model to answer exclusively from information encoded in its parameters, we provide it with relevant context from an external source.
The pipeline can look like this:
\text{Question} \rightarrow \text{Retrieval} \rightarrow \text{Documents} \rightarrow \text{Context} \rightarrow \text{LLM} \rightarrow \text{Answer}
First, the system receives a question. It then searches for relevant document passages. Only afterward does the model use the retrieved material to generate an answer.
A practical RAG system may include:
- embeddings,
- vector search,
- document chunking,
- reranking,
- result filtering,
- source citations.

This does not mean that RAG automatically solves hallucinations.
If retrieval finds the wrong document, the document is outdated, or a passage is taken out of context, the model can still generate an incorrect answer.
Therefore:
\text{good retrieval} \not\Rightarrow \text{guaranteed truth}
but at the same time:
\text{good retrieval} \rightarrow \text{better foundation for an answer}
RAG therefore shifts the problem from:
“Does the model remember the correct information?”
toward:
“Did the system provide the model with the correct information?”
That is a major improvement, but it is not a magical solution.
An LLM is not a search engine
This distinction is crucial.
A search engine is designed to find existing information in external sources.
An LLM generates text based on learned relationships and the context available to it.
Modern AI systems can of course combine both mechanisms. A model can use a search engine, database, calculator, code interpreter, or API.
At that point, the LLM becomes part of a larger system.
It can be viewed as a language and reasoning layer operating on top of external tools.
That is why combining an LLM with retrieval and external tools can be much more reliable than asking the model to generate an answer purely from its learned parameters.
How should we use LLMs intelligently?
The most important rule is simple:
The more important the information, the less you should trust the fluency of the answer itself.
If you ask the model for a project name, a mistake may have no consequences.
If you ask for a mathematical formula, verify it.
If you ask about an experimental result, you need the data.
If you ask about a scientific publication, check that it exists.
If you ask about current information, check an up-to-date source.
If an answer affects a medical, legal, or financial decision, do not treat the LLM alone as a sufficient authority.
The point is not to stop using AI.
The point is to understand when an answer requires verification.
A language machine, not a truth machine
LLMs are extraordinary language models.
They can translate, program, summarize documents, analyze information, generate ideas, and conduct remarkably complex conversations.
But their fundamental mechanism is still the generation of successive elements of an answer based on context and learned relationships.
That means an answer can be:
fluent + logical + detailed + confident + false.
And that is exactly what makes hallucinations such an interesting problem.
They do not look like a system failure.
They are not always obvious errors.
They often look like a very good answer.
Only confrontation with reality may reveal that beneath the correct language there is no corresponding true information.
A document. An experiment. A database. A publication. Measurement data. A source.
These are the things that can answer a question the language model itself cannot reliably settle:
Is what I just generated actually true?
So there are two things worth remembering:
Fluency is not evidence.
Verification is.
Sources and references
- arXiv Why Language Models Hallucinate arxiv.org
- arXiv Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks arxiv.org
- arXiv Language Models are Few-Shot Learners arxiv.org
- arXiv Training language models to follow instructions with human feedback arxiv.org
Enjoyed this one?