What you'll learn
The most notorious failure mode of language models is the hallucination: a fluent, confident statement that is simply false. It isn't a glitch — it's a direct consequence of how models work. This phase is about the single best cure: grounding the model in real, provided facts.
By the end of this module you'll be able to:
- Define hallucination and explain why next-token prediction causes it
- Ground answers in context you provide, dramatically cutting made-up facts
- Prompt for citations and honest "I don't know" responses
- Spot the situations where hallucinations are most likely
What a hallucination is
A hallucination is output that is presented as fact but isn't true — an invented statistic, a fake citation, a nonexistent function, a plausible-but-wrong date. The danger isn't that the model is obviously confused; it's that hallucinations are fluent and confident, so they slip past a casual reader.
Why next-token prediction invents facts
Recall Module 2: a model generates the most plausible-sounding continuation, not a verified one. When it doesn't actually "know" something, the statistically likely next tokens still form a confident-looking sentence — so it produces one. The model has no built-in sense of "I'm not sure" unless the prompt gives it room to say so.
| Hallucinations spike when… | Because… |
|---|---|
| You ask about niche or obscure facts | Sparse training signal — the likely continuation is a guess |
| You ask about events after the training cutoff | The model simply has no data, but still completes the text |
| You demand a specific detail (a date, a quote, a source) | It fills the slot with something plausible rather than leaving it blank |
| The prompt provides no grounding context | There's nothing to anchor the answer to |
Grounding in provided context
The fix is to stop relying on the model's memory and instead hand it the facts in the prompt, with an instruction to use only those. This is "open-book" prompting — and it's the idea that RAG (next module) automates at scale.
Prompt
What is the refund window for TaskFlow Pro?
Response
Prompt
Using ONLY the policy below, answer the question. If it's not covered, say "Not specified." Policy: "Refunds are available within 14 days of purchase. After 14 days, sales are final." Question: What is the refund window for TaskFlow Pro?
Response
Key idea
Citations & "I don't know"
Two prompt habits make grounding even stronger. First, give the model explicit permission to decline (Module 5): "If the answer isn't in the context, say so." Second, ask it to citewhich part of the context it used — this both helps you verify and discourages it from drifting off-source.
Prompt
Answer from the context and quote the exact sentence you used. If unsupported, reply "Not in the document." Context: "The workshop runs from 9am to 12pm. Lunch is not provided." Question: Is lunch included?
AI response
Spotting hallucinations
Until grounding is airtight, stay skeptical. Red flags to watch for:
- Oddly specific, unverifiable details — exact figures or dates with no source.
- Citations you can't find — plausible-looking papers, URLs, or quotes that don't exist.
- Answers to impossible questions — confident replies about the future or private data.
- Overconfidence on the obscure — the more niche the topic, the more you should verify.
Watch out
Recap & quick check
Key takeaways
- A hallucination is confident, fluent output that is factually wrong — dangerous precisely because it sounds right.
- It happens because the model produces plausible-sounding text, not verified facts, and defaults to guessing when unsure.
- The best fix is grounding: provide the facts in the prompt and instruct the model to use only them.
- Give an explicit 'say I don't know' path and require citations to keep answers anchored and checkable.
- Grounding reduces but doesn't remove hallucination — verify high-stakes answers and stay skeptical of unsourced specifics.
Quick check
1. Why do language models hallucinate?
2. What is 'grounding' a model?
3. Which habit makes a grounded answer easiest to verify?
4. When are hallucinations MOST likely?
Grounding by hand works for one document. To ground a model in thousands, you retrieve the right passages automatically. Next up: Module 19 — Retrieval-Augmented Generation (RAG).