Why Models Hallucinate
Why language models state false things fluently, which situations make this most likely, and how to prompt and check answers to reduce the damage.
On this page
A hallucination is output from a language model that is fluent and confident but false or unsupported by any source, such as a citation for a paper that does not exist or a function that the library does not have. It happens because a model is trained to produce text that is likely, and it has no step that checks whether the text is true. Knowing the situations in which it happens most tells you when to supply the facts yourself and when to verify the answer.
Without that knowledge, a reader treats every confident answer alike. The false details are written in the same tone and format as the correct ones, so you cannot find them by reading for style.
How a model ends up inventing a fact
A model writes one token at a time, and at each step it assigns a probability to every possible next token (What Is an LLM). Pretraining adjusted those probabilities to match real text, which is mostly true, so the model is usually right about things that were written about often.
The model still has to output some token at every step, whether or not it has a fact to draw on. When it does not know an author's name, the probabilities are spread thinly over many plausible names, and sampling picks one of them. The answer "I don't know" appears only when those words happen to be a likely continuation. The tracer below shows this for a reference to a study that the model has not seen. The probabilities are invented to illustrate the pattern.
repeat: chances = model(text so far) token = sample(chances) append token to text- next0A1One2Researchchance00.6210.2120.09
- text
- A study by
1The model starts with "A" at 0.62 and then continues with "study by" almost automatically, because many answers begin this way.
- next0Brennan1Lindqvist2Okafor3Chen4Patelchance00.0710.0620.0530.0540.05
- text
- A study by Brennan
2The model remembers no author for this claim, so the probabilities are flat and none is above 0.07. It still has to pick one, and it picks "Brennan".
- next0et al.1and2(chance00.8110.1120.05
- text
- A study by Brennan et al.
3"et al." is very likely after a surname in a reference. This is real knowledge about the format of references, not about the study.
- next0(2019)1(2018)2(2021)3(2016)chance00.1410.1320.1230.11
- text
- A study by Brennan et al. (2019)
4The year is another guess, and sampling picks 2019.
- next012%115%210%38%chance00.0910.0820.0830.07
- text
- A study by Brennan et al. (2019) found that ... scored 12% higher
5The words "found that" are nearly certain, but the percentage is a flat guess again, and the model writes 12%. Every later token has to stay consistent with what is already written.
- piece0A study by1Brennan2et al.3(2019)4found that512%chance00.6210.0720.8130.1440.9350.09
- confident steps
- 3
- guessed facts
- 3
6The confident steps are the format words, and the guessed steps are the author, the year and the number. They look identical on the page, although all three facts came from probabilities below 0.15.
Situations that make hallucination likely
Hallucination is not equally likely everywhere. Six situations account for most of it, and each one points to a different precaution.
Rare facts
A fact that appeared thousands of times in the training text, such as the boiling point of water, gets sharp probabilities. A fact that appeared once or twice, such as the founding year of a small company, leaves only a weak trace. Names, numbers, dates, quotes, URLs and identifiers are the details most at risk, because each one has to be exactly right, and the model can only approximate it. If a question is about something obscure, assume the model is guessing unless you give it a source.
Information the model never had
The model cannot know your private documents, your internal systems, or events after its training data ended. A question about them still gets an answer, because producing a plausible answer is all the model can do. Questions such as "what does our refund policy say" or "what changed in the latest release" should never be answered from the model's memory.
Questions with a false premise
The question "Why did the city ban bicycles in 2015?" assumes that the ban happened. The most likely continuation of that text is an explanation, so the model may supply one for an event that never took place. Leading questions, wrong terminology and wrong version numbers all have this effect, because the model tends to continue from what the prompt states.
Errors that compound
Each token the model writes becomes part of the text that the next token is based on. One wrong guess early in an answer therefore pulls the rest of the answer toward consistency with it, and a single invented name can grow into a detailed and coherent false story. Long answers contain more places for this to start than short ones.
Training that rewards guessing
If a model is trained or evaluated with a score that only counts right and wrong answers, a confident guess sometimes earns a point and "I'm not sure" never does. A model shaped by that signal learns to guess. Training can also teach a model to decline more often, but this reduces hallucination without removing it, and the model's wording of confidence does not reliably match how likely it is to be correct.
Summaries and answers that go beyond the source
A model can also hallucinate when the source is in the prompt. A summary may add a detail that the document does not contain, merge two people into one, or state a conclusion the document only hints at, because the model fills gaps with what is typical. This is why the prompt should ask for quotes and why you should check the quotes against the document. A leading question has the same effect as a false premise, so ask neutrally first, for example "Does this library have a retry feature?", before asking how it performs.
Reducing hallucination in your prompts
Give the model the source and ask it to read
The strongest fix is to change the task from remembering to reading. Put the relevant text in the prompt and tell the model to answer only from it. Compare the two prompts below.
The first answer describes leases in general and guesses about yours. The second prompt supplies the facts, restricts the model to them, asks for a quote that you can find in the document in a few seconds, and gives the model an allowed way to say that the answer is missing. Retrieval-augmented generation automates the first step by finding relevant documents and adding them to the prompt, and it has the same limit: if the retrieved text does not contain the answer, the model may still guess.
Allow "not stated" and ask for evidence
A model that is asked a question will usually try to answer it. Tell it explicitly what to do when the answer is not available, and name the exact reply you want so that you can notice it. Asking for a supporting quote or a source identifier turns a claim into something you can check. A quote that does not appear in the document is a clear sign of a problem, and it is much easier to spot than a wrong paraphrase.
Use tools for facts and calculations
When the answer lives in a database, a search index or a calculation, give the model a way to look it up through tool use instead of asking it to recall the value. The model then reports what the tool returned. You still need to check that it called the right tool with the right arguments, because it can misread or ignore a tool result.
Pitfalls
What this changes in practice
Decide how much a wrong answer would cost you before you decide how much checking to do. A brainstormed list of names for a project needs no checking, because a wrong item costs nothing. A medical, legal, financial or code-related claim that you will act on needs a source.
Put the facts the answer depends on into the prompt, ask for answers from that text with a quote, and give the model a stated way to say that the information is missing. Check names, numbers, dates, quotes and links yourself, and check more carefully the more a mistake would cost. Verifying AI Output turns that into a routine.
This prompt invites a hallucination, because the model never saw the meeting. Rewrite it so the answer comes from material you provide, can be checked, and can honestly say that something is missing.
Show a sample answer
The rewrite works because it supplies the source, restricts the model to it, asks for a quote that can be checked, and says what to reply in each case, including "not decided" and "not mentioned". A guess is then never the easiest continuation.
Check yourself
Which of these is a model most likely to get wrong without a source?
Why does a hallucinated reference look as convincing as a real one?
What is the most reliable way to get a correct answer about a specific document?
What to practise next
Prompting Basics covers how to write the prompts used here, and Verifying AI Output shows how to check answers quickly when the stakes are real.