Hallucination in Responses

The Problem

LLMs generate confident but factually incorrect information not present in retrieved context, leading to wrong answers despite having correct source material.

Symptoms

  • ❌ AI invents facts not in retrieved documents

  • ❌ Confident responses with fabricated details

  • ❌ Mixing real and made-up information

  • ❌ Cannot cite source for invented claims

  • ❌ Plausible-sounding but wrong answers

Real-World Example

Retrieved context: "API rate limit is 1000 requests per hour"

User query: "What happens if I exceed the rate limit?"

AI response: "If you exceed the rate limit of 1000 requests per hour, 
your account will be temporarily suspended for 15 minutes and you'll 
receive a 429 error. After three violations, your API key will be 
permanently revoked."

Problem: Context only mentions the limit
→ "15 minutes suspension" - INVENTED
→ "three violations" policy - INVENTED  
→ "permanent revocation" - INVENTED

Only "1000 requests/hour" and "429 error" might be accurate

Deep Technical Analysis

Retrieval-Generation Gap

LLM operates beyond retrieved context:

Context Window Usage:

Pattern Completion Bias:

Instruction Following vs Grounding

Tension between creativity and accuracy:

System Prompt Dilemma:

The Helpful Assistant Problem:

Confidence Calibration Failure

LLMs don't know what they don't know:

Equal Confidence for All Outputs:

The Plausibility Trap:

Context Length Limitations

Retrieved context may be insufficient:

Incomplete Information:

Contradictory Sources:

Mitigation Strategies

1. Aggressive System Prompting:

2. Citation Requirements:

3. Confidence Scoring:

4. Two-Stage Generation:


How to Solve

Use strict system prompts requiring citation + implement confidence scoring + apply two-stage extraction-then-answer pipeline + penalize hallucination in prompt engineering + use models fine-tuned for RAG (instruction-following models). See Hallucination Prevention.

Last updated