What counts as a hallucination
A hallucination is any generated claim that is false or not supported by the information the model was given, presented with the same fluency as a true one. Two flavours matter in practice:
Factual (world) errors
Contradicts reality: wrong dates, invented papers, non-existent laws or APIs.
Faithfulness errors
Contradicts or goes beyond the provided source: a summary adding a number the document never stated.
In business systems the second kind is often more dangerous, because users trust an answer “from the document” more.
Why LLMs hallucinate
- They predict, they don’t look up. An LLM generates the most plausible continuation, token by token. “Plausible” and “true” overlap most of the time — but not always. (How LLMs work.)
- Knowledge gaps and cutoffs. Rare facts appear in training data only a handful of times, and anything after the training cutoff is unknown. The model fills gaps with pattern-shaped guesses.
- Training rewards answering. Evaluation and training have historically rewarded a confident attempt over “I don’t know,” nudging models toward guessing.
- Ambiguous or false-premise prompts. “Summarise the 2019 ruling in Smith v. Jones” invites the model to invent one if it doesn’t exist.
- Long or noisy context. Important details lost in long inputs, or irrelevant retrieved chunks, lead to blended or misattributed answers.
- Sampling randomness. Higher temperature gives low-probability (often wrong) tokens more chances.
- Tokenization limits. Exact numbers, character counts and long arithmetic are awkward in token space — see tokens explained.
Types of hallucinations (with examples)
| Type | Example | Main fix |
|---|---|---|
| Fabricated sources | Citing a journal article with a real-looking DOI that doesn’t exist | Retrieve sources; only cite retrieved items |
| Invented figures | “Revenue grew 14% in Q3” when the report never gives a growth rate | Extract numbers from source; calculate with tools |
| Unfaithful summary | Summary says a contract auto-renews; contract says it doesn’t | Faithfulness check; quote-then-summarise |
| Non-existent code | Calling a library function that was never part of the API | Docs in context; run tests |
| False premise accepted | Explaining “why the Eiffel Tower was moved in 1920” | Instruct to challenge premises |
| Entity mix-ups | Merging two people or companies with similar names | Retrieval with metadata; disambiguation |
9 proven ways to reduce hallucinations
1. Ground answers in retrieved sources (RAG)
Give the model the relevant text instead of relying on memory. RAG is the single biggest lever for knowledge questions — provided retrieval is good (see chunking strategies).
2. Explicitly allow “I don’t know”
Say it plainly: “If the answer is not in the context, reply ‘I can’t find that in the provided documents.’” Models follow this instruction surprisingly well, and it converts many confident fabrications into honest abstentions.
3. Require citations — then check them
Ask for a source ID or quote for every claim. Then validate in code that each cited ID was actually retrieved; drop or flag claims citing anything else.
4. Quote first, then answer
For long documents, have the model first extract the exact relevant quotes, then answer using only those quotes. This forces it to anchor on real text.
5. Use tools for facts, maths and data
Let the model call a calculator, code interpreter, SQL database or search API instead of “remembering” numbers. An agent that runs SELECT SUM(...) doesn’t hallucinate the total.
6. Constrain the output
Structured output with enums and required fields (via JSON schema) leaves less room for invention than free prose — especially for extraction tasks. Build schemas with the JSON Schema Builder.
7. Lower temperature for factual tasks
Use low temperature for extraction, Q&A and code. It won’t fix missing knowledge, but it removes avoidable randomness.
8. Add a verification pass
Run a second step (same or different model) that checks each claim against the source and lists unsupported ones. For high-stakes outputs, route flagged answers to a human.
9. Measure with evals — continuously
Keep a test set of questions, including ones whose answer isn’t in your data. Track faithfulness and abstention rate on every prompt or model change.
A grounded system prompt you can copy
You are a careful assistant answering questions about company documents.
Rules:
1. Use ONLY the information inside <context> tags. Do not use prior knowledge.
2. Cite the source ID in [brackets] after every factual sentence.
3. If the context does not contain the answer, reply exactly:
"I can't find that in the provided documents."
4. If the question contains a false assumption, point it out instead of answering it.
5. Never invent numbers, names, dates, or quotes.
<context>
{{retrieved_chunks_with_ids}}
</context>
Question: {{question}}
Stress-test variations of this prompt against tricky inputs in the Prompt Optimizer.
How to measure hallucinations
- Faithfulness / groundedness: share of claims supported by the provided context (scored by humans or a calibrated LLM judge).
- Citation precision: share of citations that genuinely support the sentence they’re attached to.
- Correct abstention rate: on unanswerable questions, how often the system says it doesn’t know.
- Factual accuracy: agreement with reference answers on a labelled set.
Include unanswerable questions in your eval set. A system that scores 95% on answerable questions but invents answers to every unanswerable one is not production-ready.
Discussion