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.

13 minLesson 6 of 6
On this page
  1. How a model ends up inventing a fact
  2. Situations that make hallucination likely
  3. Reducing hallucination in your prompts
  4. Pitfalls
  5. What this changes in practice
  6. Check yourself
  7. What to practise next

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.

Writing a reference from guessesUse the arrows or ← → keys
repeat:  chances = model(text so far)  token = sample(chances)  append token to text
  1. next
    0A
    1One
    2Research
    chance
    00.62
    10.21
    20.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.

  2. next
    0Brennan
    1Lindqvist
    2Okafor
    3Chen
    4Patel
    chance
    00.07
    10.06
    20.05
    30.05
    40.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".

  3. next
    0et al.
    1and
    2(
    chance
    00.81
    10.11
    20.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.

  4. next
    0(2019)
    1(2018)
    2(2021)
    3(2016)
    chance
    00.14
    10.13
    20.12
    30.11
    text
    A study by Brennan et al. (2019)

    4The year is another guess, and sampling picks 2019.

  5. next
    012%
    115%
    210%
    38%
    chance
    00.09
    10.08
    20.08
    30.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.

  6. piece
    0A study by
    1Brennan
    2et al.
    3(2019)
    4found that
    512%
    chance
    00.62
    10.07
    20.81
    30.14
    40.93
    50.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.

1 / 6

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.

Asking it to rememberIllustrative example. Real replies vary.
You
What is the notice period in our office lease?
Model
Most commercial office leases have a notice period of 3 to 6 months. Your lease likely requires written notice of 3 months before the end of the term.
Asking it to readIllustrative example. Real replies vary.
You
Using only the lease text below, answer: what is the notice period for ending the lease? Quote the sentence your answer is based on. If the text does not say, reply "Not stated in the lease". <lease> [full lease text] </lease>
Model
The notice period is 90 days, given in writing. Quote: "Either party may terminate this agreement at the end of the initial term by giving not less than ninety (90) days' written notice to the other party."

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.

Try it: Ground the answer

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
Rewritten promptIllustrative example. Real replies vary.
You
Below are my notes from Tuesday's product meeting. Using only these notes, tell me what was decided about the launch date. - If a date was decided, give it and quote the line it comes from. - If it was discussed but not decided, say so and list the options mentioned. - If the notes do not mention it, reply "Not in the notes". <notes> [paste meeting notes] </notes>

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

Quick check

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.