Papa Programmer
Lesson 19 of 20

Why models make things up

9 min read

Optional

Likely is not the same as true

An LLM has no list of facts to look up. It writes the text that best fits the patterns it learned. Most of the time, the likely text is also true, because true statements are common in the training text. When they are not, the model writes something that sounds right and is wrong. This is called a AI hallucinationAn answer that sounds confident but is false. The model wrote text that fits the pattern instead of text that is true..

A well-known case came to court in New York in 2023. In Mata v. Avianca, lawyers filed a brief that cited court cases ChatGPT had invented, with names, dates and quotes. The judge fined the lawyers. The cases sounded real because they followed the pattern of real cases.

Where made-up answers come from

  • Rare facts. A fact that appears a few times in the training text is weakly stored. The model fills the gap with something that fits the pattern, such as a plausible date or name.
  • The knowledge cutoff. The model knows nothing after its Knowledge cutoffThe date at which a model's training text ends. The model knows nothing that happened after it, unless the prompt supplies that information.. Asked about later events, it may answer from older patterns.
  • Pressure to answer. A 2025 OpenAI paper, "Why Language Models Hallucinate", by Kalai and others, argues that training and tests reward a confident guess over "I don't know". A guess sometimes scores a point. "I don't know" never does.
  • Long chains of steps. In maths or reasoning, one wrong step early on carries through to a wrong final answer.

Four ways to reduce it

  1. GroundGive the model the source text and tell it to answer from that text.
  2. AllowTell it to say it does not know when the source has no answer.
  3. QuoteAsk it to copy the sentence that supports each claim.
  4. CheckTest in code that every quote really appears in the source.
Four steps that make a made-up answer less likely and easier to catch

Grounding is the core of Retrieval-augmented generationA method where an app searches sources at question time and adds selected passages to the model's context. Updated information can inform later answers once it is available to retrieval, but the results and answers still need checking.. A search step finds the relevant documents and puts them in the prompt. The model then copies and reshapes facts instead of recalling them.

Check quotes in code

When the model returns a quote for each claim, a few lines of code can test it. The program below checks two quotes against a refund policy.

python
source = """Our return window is 30 days from delivery.
Items must be unused and in the original box.
Refunds go to the original payment method within 5 working days."""

answer = {
	"answer": "You have 30 days to return an unused item.",
	"quote": "Our return window is 30 days from delivery.",
}

def quote_is_real(quote, source):
	return quote.strip() in source

print(quote_is_real(answer["quote"], source))
print(quote_is_real("Refunds are paid within 24 hours.", source))

It prints True for the real quote and False for the invented one. A failed check is a signal to retry, to answer "I could not find this in the policy", or to pass the question to a person. The check proves that the quote exists. It does not prove that the answer reads the quote correctly, so test that part with your evaluation set.

Decide where a person checks

Some mistakes cost little, such as a weak first draft of an email. Others cost a lot, such as a wrong dose, a wrong legal citation or a wrong refund. For costly mistakes, show the sources next to the answer and keep a person in the loop before anyone acts on it. Do not ask the model whether it is sure. Its stated confidence is more generated text, not a measurement.

Fluent is not proofThe model writes likely text, and likely text can be false.
Ground it in sourcesPut the facts in the prompt and allow "I don't know".
Verify in codeCheck that every quote appears in the source before you trust the answer.

Your reading position is saved

0%

0 of 20 complete

Contents

Learning tools