← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · ✎ updated 7d
← Back to glossary

AI Hallucination

AI / ML Intermediate
debt(d8/e7/b7/t7)
d8 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9), -1 because with careful testing or domain-expert review some hallucinations can be caught before production, but the detection_hints explicitly state automated detection is 'no' — there is no static analysis tool, linter, or SAST scanner that can flag hallucinated content. Most hallucinations surface only when end-users encounter confidently wrong information in production.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix mentions RAG, citation grounding, and human review layers — none of these are one-line fixes. Implementing RAG requires a retrieval pipeline, vector store, prompt engineering changes, and validation layers across every AI-powered feature. This is a cross-cutting architectural concern that touches data pipelines, prompt construction, output validation, and UI (displaying confidence/sources).

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). Once AI-generated content is part of the system, every feature that consumes or displays LLM output must account for potential hallucination — adding grounding, validation, and review workflows. This shapes how every AI-adjacent feature is designed and maintained. It applies across web and CLI contexts per applies_to, and the reliability concern is load-bearing: every new AI feature inherits the obligation to mitigate hallucination.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap — contradicts how a similar concept works elsewhere' (t7). The misconception field is explicit: developers believe hallucination is a bug that future model versions will fix, when it is actually a fundamental property of probabilistic generation. This contradicts the mental model from traditional software where bugs get patched. Developers who treat LLM output like a deterministic API call (the 'obvious' mental model) will be consistently surprised by fabricated facts, fake citations, and invented data — especially since the output is delivered with high confidence.

About DEBT scoring →

Also Known As

confabulation LLM hallucination factual errors

TL;DR

When an LLM generates confident, plausible-sounding text that is factually incorrect — a fundamental property of next-token prediction, not a bug to be patched away.

Explanation

LLMs predict the most probable next token given context — they do not retrieve facts from a database. When the model has insufficient training data for a query, it generates plausible-sounding completions that may be fabricated. Hallucinations are more common with: obscure topics, recent events after the training cutoff, precise numerical data, citations and URLs, and code for niche APIs. Mitigations: RAG (provide source documents), constrained output (JSON schema), chain-of-thought, and output validation.

Diagram

flowchart TD
    PROMPT[User prompt] --> LLM[LLM generates response]
    LLM -->|confident but wrong| HALL[Hallucination<br/>plausible-sounding falsehood]
    subgraph Causes
        TRAIN[Not in training data]
        AMBIG[Ambiguous prompt]
        LIMIT[Knowledge cutoff]
    end
    HALL --> TRAIN & AMBIG & LIMIT
    subgraph Mitigations
        RAG[RAG: ground in real documents]
        CITE[Require citations]
        TEMP[Lower temperature<br/>less creative = more factual]
        VERIFY[Human verification<br/>for critical outputs]
    end
    HALL -.->|reduce with| RAG & CITE & TEMP & VERIFY
style HALL fill:#f85149,color:#fff
style RAG fill:#238636,color:#fff
style VERIFY fill:#238636,color:#fff

Watch Out

⚠ Hallucinations often become more confident and internally consistent when you add retrieval or fine-tuning, making them harder to spot — the model doesn't know what it doesn't know, so it fabricates with conviction regardless of guardrails. Testing against ground truth and explicit uncertainty scoring are essential, because a hallucination wrapped in correct syntax or plausible citations will pass surface-level checks.

Common Misconception

✗ Hallucination will be eliminated in future model versions — it is a fundamental property of probabilistic text generation, not an implementation bug; it can be reduced but not eliminated.

Why It Matters

An AI feature that confidently provides wrong information — fake citations, incorrect API usage, invented medical advice — erodes user trust and can cause real harm.

Common Mistakes

  • Treating LLM output as ground truth without validation — always verify factual claims from external sources.
  • Using LLMs for real-time data without RAG — the model's training cutoff means recent facts are fabricated.
  • No output validation for structured data — a hallucinated JSON field name causes a production crash.
  • Prompting for citations without providing source documents — the model fabricates plausible-looking but fake references.

Avoid When

  • Trusting LLM output for factual, legal, medical, or financial claims without verification.
  • Using a model without retrieval augmentation for domain-specific or time-sensitive facts.
  • Presenting LLM output directly to users without human review in high-stakes contexts.
  • Relying on a model to accurately cite sources — citation hallucination is common even in capable models.

When To Use

  • Always implement retrieval-augmented generation (RAG) when facts matter — ground the model in verified sources.
  • Use structured output and validation to catch impossible or malformed responses.
  • Add a verification step that checks generated claims against a trusted knowledge base.
  • Set system prompts that instruct the model to say 'I don't know' rather than fabricate.

Code Examples

✗ Vulnerable
// Trusting LLM output without validation:
$answer = $llm->complete('What is the current PHP 8.4 memory_limit default?');
echo $answer; // May be completely fabricated — training data may be outdated
// Worse: generating code with fabricated function names that don't exist
✓ Fixed
// RAG with source citation — grounded, verifiable:
$docs = $vectorDb->search('PHP 8.4 memory_limit default', topK: 3);
$context = implode("\n", array_column($docs, 'content'));
$prompt = "Answer using ONLY the provided documentation. If unsure, say so.\n\nDocs:\n$context\n\nQ: {$query}";
$answer = $llm->complete($prompt);
// Also validate structured outputs with JSON Schema

Added 15 Mar 2026
Edited 6 Jun 2026
Views 227
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 2 pings T 3 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M
Bing 1
No pings yesterday
Scrapy 20 Ahrefs 13 SEMrush 10 ChatGPT 9 Amazonbot 9 Google 8 Perplexity 8 Bing 8 Twitter/X 8 PetalBot 8 Unknown AI 3 Brave Search 2 Applebot 2 Baidu 2 Meta AI 1 Sogou 1
crawler 109 crawler_json 3
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Prediction ai_ml A prediction is the answer a trained model gives when you show it new data. It's the model's best guess based on patterns it learned during training.

Prediction is the whole point of a trained model — it's what turns learned patterns into useful output. Understanding that predictions are probabilistic guesses, not truths, shapes how you build, test, and trust AI systems.

💡 Always ask a prediction two questions: what did it guess, and how sure is it?

Ask Codex about Prediction →
Training ai_ml Training is the process of showing an AI model many examples so it can learn patterns and make predictions on new data it hasn't seen before.

Training is the step that actually creates the model — everything else in AI, from prompts to fine-tuning, depends on what happened during training. Understanding it demystifies why models behave the way they do.

💡 Always split your data into training and test sets — if you evaluate on data the model saw during training, you're grading a student on the same questions they studied.

Ask Codex about Training →
⚡ DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: High
⚡ Quick Fix
Always ground AI responses in retrieved context (RAG), ask the model to cite sources, and add a human review step or fact-checking layer for high-stakes outputs
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
AI-generated content displayed directly without grounding or fact-checking; LLM answering questions about real-time data it cannot have
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant