Beginner

Anatomy of Hallucination

Not all hallucinations are the same. Understanding the taxonomy (intrinsic vs. extrinsic, factual vs. reasoning vs. citation) is the prerequisite for choosing the right prevention technique for each type.

✍️ AI School Editorial Team · Lilly Tech Systems 📅 Published Jul 23, 2026 · Reviewed Jul 23, 2026

The First Division: Intrinsic vs. Extrinsic

The most important structural distinction in hallucination research is between intrinsic and extrinsic hallucination. The difference determines where the fix lives:

TypeDefinitionExamplePrimary Fix Layer
IntrinsicOutput contradicts information that was present in the context windowThe document says the contract expires in 2027; the model summarizes it as 2029Prompting, grounding, retrieval faithfulness
ExtrinsicOutput adds information not present in the context and cannot be verified from itThe model adds a clause to a contract summary that does not appear in the original documentRAG design, output constraints, monitoring

Intrinsic hallucination is, counterintuitively, easier to detect: you can check the output against the source document. Extrinsic hallucination is harder because the fabricated information may look plausible and there is nothing in the input to compare it against.

💡
Closed-domain vs. open-domain: Intrinsic hallucination is the dominant concern in closed-domain applications (document Q&A, summarization, code explanation). Extrinsic hallucination is the dominant concern in open-domain applications (general knowledge questions, research assistance, creative tasks with factual claims).

The Five Types of Hallucination

Type 1: Factual Hallucination

The model asserts something that is factually wrong. This is the most commonly discussed type and the one most people think of when they hear "hallucination."

📚
Before (hallucinated): "The World Health Organization was founded in 1945 and is headquartered in New York."
After (correct): "The World Health Organization was founded in 1948 and is headquartered in Geneva, Switzerland."
Both sound equally authoritative. Only the second is accurate.

Factual hallucination is especially common in queries about specific dates, numbers, names, and organizational details, exactly the details that feel most checkable but are, in practice, rarely verified before use.

Type 2: Reasoning Hallucination

The model produces a logically invalid conclusion from premises that may themselves be correct. The steps look reasonable; the conclusion does not follow.

📚
Before (hallucinated reasoning): "Since the contract was signed before the regulation took effect, the liability clause is automatically grandfathered and enforceable under the new rules."
After (correct): "Grandfathering under this regulation applies only to performance obligations, not liability caps. A signed date before the effective date does not automatically exempt this clause."
The reasoning in the first example sounds like legal analysis. It contains a subtle error that a non-expert would not catch.

Reasoning hallucination is hardest to catch because it requires domain expertise to identify. It is most dangerous in legal, medical, and financial contexts where the stakes of wrong reasoning are highest.

Type 3: Citation Hallucination

The model invents references: paper titles, author names, journal names, URLs, court cases, regulatory citations. The format is correct; the content does not exist.

📚
Before (hallucinated): "See Smith et al. (2024), 'Attention Mechanisms in Transformer Architectures,' Journal of Machine Learning Research, vol. 25, pp. 1201-1247."
After (correct approach): "I do not have a citation for this specific claim. You should verify this in the primary literature before relying on it."
The fake citation will pass a casual review. It will fail the moment someone tries to locate the paper.

Citation hallucination is particularly insidious in academic, legal, and regulatory contexts where citations are expected to be verifiable. Teams have encountered fabricated court case citations, invented regulatory guidance, and non-existent product documentation.

Type 4: Code Hallucination

The model generates syntactically valid code that calls APIs incorrectly, references removed methods, uses wrong parameters, or makes incorrect assumptions about library behavior.

📚
Before (hallucinated):
response = client.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[...],
    stream_mode="continuous"  # Does not exist
)
After (correct):
with client.messages.stream(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[...]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
The hallucinated parameter name looks like it belongs. It throws a TypeError at runtime.

Code hallucination is especially common at API version boundaries, when libraries have recently updated their interfaces, or when the model is working with a less-common library that appears infrequently in training data.

Type 5: Entity Hallucination

The model invents named entities: people, organizations, products, events, dates, or places that do not exist or did not occur as described.

📚
Before (hallucinated): "The AI Safety Institute's 2025 report on model evaluation, authored by Dr. Priya Sharma and Dr. James Lin, established the three-tier risk classification framework."
After (correct approach): Verify whether this report, these authors, and this framework exist before including the reference in any published document.
The named entities are plausible. They may or may not be real. Only verification will tell you.

Why Taxonomy Matters for Prevention

Different hallucination types respond to different interventions. Matching the fix to the type is the core skill in hallucination engineering:

TypeBest Prevention ApproachBest Detection Approach
FactualRAG + grounding promptsCross-reference against source
ReasoningChain-of-thought + self-critiqueExpert review, LLM-as-judge
CitationExplicit "do not invent citations" instruction; cite-from-context onlyURL/DOI existence check
CodeRAG over current API docs; runnable test stepStatic analysis + execution
EntityNamed entity constraints; entity verification tool callNamed entity recognition + lookup
Start with the most consequential type for your use case. If you are building a code generation tool, code hallucination is your primary risk. If you are building a research assistant, citation hallucination is your primary risk. The taxonomy tells you where to spend your prevention budget first.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.