Why LLMs Hallucinate and How to Reduce It in Your App
What causes LLM hallucinations, the types you will see, and practical mitigations: grounding, citations, abstaining, verification and evaluation.
Published December 1, 2026
A hallucination is a fluent, confident output that is not true or not supported by the given sources: an invented API method, a made-up citation, a wrong policy detail. Hallucinations are a natural consequence of how language models generate text, so the goal is not to eliminate them by wishing, but to design systems where they are rare, detectable and low-impact.
The concept
Models generate the most plausible continuation of text based on patterns learned in training. When the needed fact is missing, outdated, rare in training data, or ambiguous in the prompt, the most plausible continuation can still be wrong. Training objectives also historically rewarded giving an answer over saying "I don't know", which encourages confident guessing.
Mitigation works on several levels: give the model the facts (retrieval, tools, structured data), constrain it to those facts and ask for citations, allow and reward abstaining, verify outputs programmatically where possible (run the code, check the URL, validate against the database), and measure hallucination rates with evals so improvements are real.
Kinds of hallucination
| Type | Example | Mitigation |
|---|---|---|
| Fabricated facts | Wrong refund window | RAG with citations; answer only from context |
| Invented references | Non-existent paper or URL | Retrieve real sources; validate links |
| Non-existent APIs | Calls a method that does not exist | Provide docs/types; compile and test |
| Unfaithful summaries | Summary adds claims not in source | Faithfulness checks; quote spans |
| Overconfident math | Wrong arithmetic | Use a calculator/code tool |
Mitigation layers
Effect of layering
Practical examples
Grounded answer prompt with abstention
Make "not in the sources" an explicit, acceptable outcome.
Answer the question using only the sources. Quote or cite the source ID for each claim.
If the sources do not contain the answer, reply exactly: "I couldn't find this in our documentation."Verify generated code by running it
Execution catches invented APIs immediately.
code = llm(f"Write a Python function that ... using only the standard library.")
result = run_in_sandbox(code + "\n" + tests)
if result.failed:
code = llm(f"The code failed:\n{result.stderr}\nFix it.\n\n{code}")Check that cited sources exist
Reject answers that cite IDs not in the retrieved set.
cited = set(re.findall(r"\[(doc-\d+)\]", answer))
if not cited or not cited <= {d.id for d in retrieved}:
answer = FALLBACK_MESSAGECommon mistakes
- Expecting temperature 0 to eliminate hallucinations.
- Prompts that pressure the model to always give an answer.
- Showing generated citations without verifying them.
- No measurement, so improvements are anecdotal.
Key takeaways
- Hallucinations come from generating plausible text without sufficient facts.
- Ground, constrain, allow abstaining, verify and measure.
- Verification (running code, validating references) is the strongest defence.
- Design for detection and low impact, not perfection.
FAQ
Do newer models hallucinate less?
Generally they improve, but no model is hallucination-free, especially on niche or recent facts.
Can a second model detect hallucinations?
A judge model checking claims against sources helps, but it can also err; combine with deterministic checks.
Is RAG enough?
RAG reduces hallucination but models can still misread or over-extend sources; faithfulness evals remain necessary.