When AI Makes Things Up
A survival guide for dealing with LLM hallucinations
What Is a Hallucination?
You ask an AI about the winner of the 2025 Turing Award. It gives you Dr. Zhang Wei, his groundbreaking paper, and a detailed biography. Only problem? None of it exists. The award hasn't even been announced yet.
Hallucinations aren't bugs. They're an emergent property of how language models work. The model isn't lying - it's doing exactly what it was trained to do.
Every AI Researcher, Eventually
The Core Mechanism
- LLMs are pattern-matching engines, not databases
- Predict next word based on statistical probabilities
- When data is missing, they improvise instead of admitting ignorance
- The result: confident, plausible-sounding fiction
The Hallucination Taxonomy
How LLMs Generate Text
An LLM is a probability machine. Given text, it calculates the odds for each possible next word, then picks one.
When Patterns Fail
- Underrepresented data: Rare topics get interpolated → fabricated details
- Ambiguous contexts: Similar topics blend together → mixed-up facts
- Missing entirely: No data at all → pure imagination
Why Hallucinations Happen
Statistical Pattern Matching
- No structured knowledge base
- Rare facts = weak signals = corruption
- Learn associations, not truths
Training Data Issues
- Knowledge cutoffs (frozen in time)
- Internet noise and contradictions
- Conflicting information learned
The Compression Problem
- Billions of parameters compress trillions of tokens
- Lossy compression degrades fine details first
- High-level patterns survive, specifics don't
Decoding Strategy
- High temperature = more random = more hallucinations
- Low temperature = deterministic but repetitive
- No perfect setting exists
Model Size Matters
- Smaller models = fewer parameters = more hallucinations
- Less self-correction capability
- More confidently wrong
Lab Setup
Time to test this yourself. We'll use two models with very different capabilities:
| Model | Size | Type | Behavior |
|---|---|---|---|
| Qwen3.5-Plus | Large | Premium | More factual, nuanced reasoning |
| Qwen3-4B | 4B params | Lightweight | Fast, more prone to hallucination |
Python Setup
Test 1: Fake Citations
Ask for academic papers on a niche topic. Watch the model invent references.
✓ Hallucination detected: 5 papers with detailed metadata, none verified on Google Scholar or ACL Anthology
✓ Hallucination detected: 3 papers with fabricated citations, conferences don't match publication records
Test 2: False Premises
Test if the model detects false premises or plays along.
✗ Major hallucination: Fabricated an entire event with fictional participants (Steven Pinker, Zenon Pylyshyn), specific venue (MIT), and elaborate arguments. Most confident and detailed fabrication.
✗ Hallucinated the event but showed slight hesitation: "While there isn't a single 'three key points'..." Still accepted the false premise and fabricated arguments. Less elaborate than large model.
Test 3: Fictional Breakthrough
Ask about a fictional recent scientific discovery that sounds highly plausible.
✓ CORRECT: Refused to hallucinate. Explained why macroscopic teleportation is impossible, identified real Chinese quantum research (Micius), and clarified actual applications.
✗ MAJOR HALLUCINATION: Invented entire research paper with specific details (microdiamond, nitrogen-vacancy center, USTC affiliation). Created 5 fictional implications for space travel. Extremely confident fabrication presented as fact.
Test 4: Confident Nonsense
Ask about something that doesn't exist at all.
✓ CORRECT: Successfully identified the fiction. Checked RFC numbering, confirmed non-existence, explained why, and offered real alternatives. Excellent fact-checking.
✗ MAJOR HALLUCINATION: Created elaborate fictional protocol with fake RFC number, invented publication date, fabricated technical specifications, and even built a comparison table with fake data. Extremely confident fabrication.
Defense Strategies
- Shifts from recall → reading comprehension
- Most effective technique
- Reduces randomness
- Use JSON mode, function calling
- Mark uncertain claims
- Force it to check work
- Disagreements flag hallucinations
- Use large model as judge
- Look up facts, don't generate them
- Web search, DB queries, code execution
- RLHF, DPO target hallucination reduction
- Domain-specific fine-tuning
RAG Prompt Template
Key Takeaways
Hallucination Is Inherent
- Not a bug - it's how LLMs work
- Pattern completers, not databases
- Will always exist with current architecture
Model Size Matters
- Larger models hallucinate less
- But no model is immune
- Never trust blindly for critical info
Defense In Depth
- RAG + low temp + chain-of-thought + verification
- No single technique is enough
- Layer multiple defenses
Test Empirically
- Use experiments to find failure modes
- Different models hallucinate differently >li>Know your model's weaknesses
Never Trust Blindly
- Goal: detect and contain, not eliminate
- Like error handling in software
- Human-in-the-loop for critical decisions