Sub topic 3
What we mean by a hallucination
This chapter assumes you have used a chat assistant, can read short Python, and know that models are trained on large text collections. It also assumes you have seen the previous two chapters: a model predicts the next token, and fluent text is not the same as true text.
A working definition
In this tutorial, a hallucination is output that reads as fluent and confident but states something that is false, unsupported, or not traceable to any real source. The model did not look up a fact and misreport it. It produced text that fit the pattern of a correct answer.
The word is borrowed from psychology and is imperfect. The model does not perceive anything. Some writers prefer "confabulation" or "fabrication". This tutorial uses "hallucination" because most tools and papers do, and uses "fabricated" when a specific invented detail is meant.
Two things that get called hallucination
Not every wrong answer has the same cause, and the cause decides the fix. A useful split is:
- Fabricated facts. The model asserts something that is not true of the world, such as a book that does not exist or a wrong founding year. Nothing in the prompt forced the error. It comes from what the model learned, or failed to learn.
- Context failures. The model is given material or a framing and handles it badly. It may accept a false premise in the question, ignore a document you supplied, or contradict it.
A related distinction is between being wrong about the world and being unfaithful to the input. If you paste a report and the summary adds a figure that the report never mentions, the summary may match reality and still be a hallucination, because it is unsupported by the source you gave.
| Situation | Type | Typical cause | Typical response |
|---|---|---|---|
| Invents a journal article with a plausible title | Fabricated fact | Pattern completion with no stored fact | Check against a primary source |
| Answers "Why did Napoleon win at Waterloo?" without objecting | Context failure | False premise accepted | Rephrase, or ask the model to check premises |
| Summary includes a number absent from the pasted text | Context failure | Unfaithful to the source | Compare against the supplied text |
What is not a hallucination
Some errors look similar but differ in kind:
- Outdated information. The model's knowledge stops at a training cutoff. A correct-at-the-time answer that is now stale is a limitation, though it can be just as misleading.
- Reasoning slips. An arithmetic or logic mistake in a worked solution is wrong, but nothing was invented.
- Ambiguity. If your question has two readings and the model picks the other one, the answer is not fabricated.
- Disputed claims. When experts disagree, choosing one side is not fabrication.
In practice the boundaries blur. What matters is the habit of asking: was this detail invented, mishandled from the input, or simply mistaken?
Why the definition matters
A hallucination does not announce itself. The invented citation has the same tone as a real one. The following diagram shows how the same generation process can lead to either outcome.
Because both branches end in the same style of text, you cannot detect the problem from tone alone. This is the reason the later chapters give you checks to run instead of a feeling to trust.
A small illustration
You can express "supported by the source" as a test. The function below checks whether a quotation the model attributes to a document actually appears in it, ignoring case and spacing.
def quote_supported(quote, source_text):
def norm(s):
return " ".join(s.lower().split())
return norm(quote) in norm(source_text)
source = "The report was published in March and covers 2021 data."
print(quote_supported("covers 2021 data", source))
print(quote_supported("covers 2023 data", source))This prints True and then False. The second quote reads naturally and is the right shape, yet the document never says it. That is the hallucination pattern in miniature.
Exercise
A model is given a pasted press release and asked for a summary. The summary says the company hired 400 people, but the release never mentions hiring. In fact, the company did hire about 400 people that year. Is this a hallucination under this chapter's definition, and which type is it?
Show answer
Yes. It is a context failure, because the statement is unsupported by the source the model was given. That it happens to be true of the world does not make it supported by the document, and you cannot rely on it. You would need to verify it separately.