Advanced

Avoiding Hallucinations

AI hallucinations aren't random bugs — they're predictable failure modes with known causes. Learn the techniques that keep Claude grounded in facts and honest about its limits.

18 min read 10 examples Chapter 8 of 11

What Hallucinations Are and Why They Happen

A hallucination is when an AI generates text that sounds confident and plausible but is factually incorrect. The term is apt: the model produces something that feels real but isn't grounded in reality. The mechanism is statistical, not intentional — Claude generates the most probable next token given its context, and sometimes the most probable sequence is wrong.

Hallucinations are most likely when: the question concerns obscure facts, specific dates or numbers, details from long documents (where the relevant fact was far from the current context window), or anything that requires recalling precise information rather than generating coherent text.

⚠️
The Fluency Trap
Hallucinated content is often written with the same confidence and fluency as correct content. Never judge AI output accuracy by how confident or well-written it sounds. Verify factual claims independently, especially citations, statistics, dates, and names of people or publications.

Types of Hallucinations: Know What to Watch For

📚
Citation Fabrication
Claude invents academic papers, studies, books, or URLs that don't exist. The author names, journal names, and titles are plausible — but the work doesn't exist. Always verify citations before using them.
🔢
Number Errors
Statistics, percentages, revenue figures, population counts — Claude may generate plausible-sounding numbers that are slightly or completely wrong. High-stakes: always verify numeric claims.
📅
Date / Timeline Errors
Getting founding dates, product launch years, historical events, or biographical dates wrong. Dates are stored weakly in model weights and should always be independently verified.
👤
Attribute Mixing
Correctly identifying a person but attributing to them something said or done by someone else. Common with historical figures, executives, and authors with similar names or contexts.
🧩
Confabulation
Inventing plausible-sounding details when the model doesn't know the answer. Instead of saying "I don't know", the model fills the gap with a fabricated but coherent answer.
📎
Over-extrapolation
Taking a true premise and confidently extending it beyond what's actually known. The starting point is accurate; the extrapolation is invented. Subtle and dangerous in analysis contexts.

Technique 1: Grounding — Anchor to Provided Context

The most reliable anti-hallucination technique is to provide the facts yourself and instruct Claude to use only those facts. This works because Claude is excellent at extracting, reasoning about, and synthesizing information from text it can directly reference.

Grounding Pattern
Answer the following question using ONLY the information in the provided document.
Do not use any knowledge from your training. If the answer is not explicitly
stated in the document, say: "This information is not in the provided document."

<document>
{document_text}
</document>

<question>
{user_question}
</question>

Technique 2: Uncertainty Expression

Instruct Claude to signal when it's uncertain rather than guessing confidently. This simple instruction dramatically reduces the rate of fluent-but-wrong answers:

Uncertainty Expression Instructions
# Pattern 1: Simple "say I don't know"
Answer the following question accurately. If you don't know the answer
with high confidence, say "I'm not certain about this" and explain
what you do and don't know. Never guess.

# Pattern 2: Distinguish knowledge types
Answer this question. For each factual claim, indicate whether you are:
- Certain (well-established fact from training)
- Likely (generally accepted but may have exceptions)
- Uncertain (you believe this is true but cannot be confident)
- Unknown (you don't know — do not guess)

# Pattern 3: Knowledge cutoff awareness
Note: Claude's training has a knowledge cutoff. For time-sensitive questions,
indicate if the answer may have changed since your training cutoff and
recommend the user verify with current sources.

Technique 3: Citation Requirements

For research and analysis tasks, requiring Claude to cite specific passages from the provided context forces it to ground every claim in actual text rather than generating from general knowledge:

Citation Requirement Pattern
Analyze the following research paper and answer the questions below.
For every claim you make, quote the specific passage that supports it
using this format: [QUOTE: "exact text from document"].
If a claim cannot be supported with a direct quote, do not make it.

<paper>
{paper_text}
</paper>

Questions:
1. What is the study's main finding?
2. What methodology was used?
3. What are the stated limitations?

Technique 4: Confidence Scoring

Ask Claude to rate its own confidence for each fact in the response. This meta-cognitive prompt activates a different processing mode that tends to produce more calibrated uncertainty:

Confidence Scoring Pattern
Answer the following question. For each factual claim in your response,
add a confidence score in brackets: [HIGH], [MEDIUM], or [LOW].
- HIGH: well-established fact, verified in training
- MEDIUM: generally accepted, but details may vary
- LOW: uncertain — recommend the user verify independently

What were the key factors that led to the 2008 financial crisis?

Before / After: Hallucination-Prone vs. Grounded Prompt

Tell me about the clinical trials for drug X. Include the trial IDs, sample sizes, and results.
Summarize the clinical trial information for drug X using ONLY the information in the provided documents below. For each trial you mention: - Include only trial IDs, sample sizes, and results that are explicitly stated in the documents - If a specific piece of information (e.g., sample size) is not in the documents, write "not specified in provided documents" - Do not extrapolate or infer beyond what is written <documents> {clinical_trial_documents} </documents>
Hallucination-prone: Claude may generate plausible-sounding trial IDs like "NCT04512847", sample sizes, and results that don't correspond to any actual trial. The output looks real and is formatted correctly — but the data is fabricated. Grounded: Claude extracts exactly what's in the provided documents, uses "not specified in provided documents" for missing data, and makes no claims beyond what's explicitly written. Dramatically safer for medical, legal, or financial contexts.

RAG: Retrieval-Augmented Generation

RAG is the architectural pattern that makes the grounding technique scale to production. Rather than including all possible documents in every prompt, RAG retrieves the relevant documents at query time and injects them into the context:

1
Index your knowledge base
Chunk your documents into searchable segments (500-1000 tokens). Generate embeddings using an embedding model. Store in a vector database (Pinecone, Weaviate, pgvector).
2
Retrieve at query time
Embed the user's query. Find the top-k most semantically similar chunks using cosine similarity. Retrieve those chunks from the database.
3
Inject into context
Insert the retrieved chunks into the prompt as a <context> block. Instruct Claude to answer only from this context. Dramatically reduces hallucination on domain-specific questions.

The "No Hallucination" System Prompt Template

Production Anti-Hallucination System Prompt
You are a precise, fact-based assistant. Follow these rules strictly:

1. ONLY use information explicitly provided in this conversation.
   Do not use knowledge from your training unless the user asks for it.

2. NEVER fabricate citations, studies, statistics, or facts.
   If you don't have a source, say so.

3. When you are uncertain about something, say so explicitly.
   Use phrases like "I'm not certain", "you may want to verify this", or
   "I don't have reliable information on this."

4. Do not extrapolate beyond what is stated.
   Distinguish clearly between what the documents say and your interpretation.

5. If asked about something not covered in the provided context,
   say: "I don't have that information in the provided context."

Red Flags: When to Be Extra Careful

⚠️
High-Risk Hallucination Scenarios
Always verify independently when Claude discusses: specific statistics and percentages, publication dates and founding years, names of specific people and their exact roles, URLs and DOIs, legal citations and case names, drug dosages and medical protocols, financial figures, and any claim that begins "studies show" or "research indicates" without a provided source.
Chapter 8 Takeaway
Hallucinations are predictable, not random. They spike for specific fact types (citations, dates, numbers, names) and specific prompting patterns (no context provided, vague questions about obscure topics). The fix is structural: ground Claude in provided context, instruct it to express uncertainty, require citations from source material, and use RAG for production knowledge-intensive applications.