A hallucination is a confident, fluent, and wrong output — a fabricated fact, a citation that doesn't exist, or a plausible-sounding but incorrect answer, generated with no visible difference in tone from a correct one.
Why Hallucination Happens — The Root Cause
An LLM is trained to predict statistically plausible next tokens, not to verify truth. When it lacks reliable information — a question outside its training data, a niche fact, a very specific detail — it doesn't have a built-in "I don't actually know this" signal. It continues generating the most plausible-sounding continuation anyway, which can be entirely fabricated while reading identically to a correct answer.
Common Hallucination Patterns
| Pattern | Example |
|---|---|
| Fabricated citations | Inventing a plausible-sounding paper title, author, and journal that doesn't exist |
| Confident wrong facts | Stating an incorrect date, statistic, or name with full confidence |
| Fabricated API/library details | Inventing a function or parameter that doesn't exist in a real library, especially for less common libraries or newer versions |
| Overconfident extrapolation | Answering a question about something outside its training data as if it were well-established fact |
A Concrete Example
Prompt: "What method does the 'requests' Python library use to
set a custom timeout on a session-level basis?"
Risk: if the model isn't certain, it may confidently generate
a plausible-looking but incorrect method name and usage pattern
rather than indicating uncertainty — always verify generated
code against real documentation before relying on it.
Detection Strategies
- Grounding in retrieved sources — RAG reduces (does not eliminate) hallucination by giving the model real source material to draw from, rather than relying purely on parametric memory (see RAG)
- Faithfulness evaluation — checking whether a generated answer is actually supported by the provided context, a standard part of RAG evaluation (see Faithfulness)
- Asking for sources — prompting the model to cite where in the provided context an answer came from, then verifying the citation is real and actually supports the claim
Mitigation Strategies
- Ground answers in retrieved, verifiable context (RAG) rather than relying on the model's memorized training data for facts
- Lower temperature for fact-sensitive tasks, reducing (not eliminating) output variability
- Add explicit instructions to acknowledge uncertainty rather than guess — effectiveness varies and should be evaluated, not assumed
- Human review for high-stakes outputs (medical, legal, financial claims)
- Structured output with required source fields, making unsupported claims easier to catch programmatically
Common Mistakes
- Treating hallucination as rare or unusual — it's an expected, systemic behavior to design around, not an occasional bug
- Assuming RAG "solves" hallucination completely — it substantially reduces the risk for grounded questions but doesn't eliminate it; a model can still misread or overgeneralize from retrieved context
- Shipping LLM-generated factual content (especially in regulated domains) without any human review step
Interview Relevance
"How would you reduce hallucination in a production LLM application?" is one of the most common Generative AI interview questions — a strong answer names multiple concrete strategies (RAG grounding, faithfulness evaluation, human review), not just "use a better model."
Practice Question
A legal-document summarization tool occasionally invents clause numbers that don't exist in the source document. Propose two concrete mitigations.