Factuality & Hallucinations

Understand why LLMs hallucinate and strategies to improve factual accuracy

The Problem: AI can make up facts that sound completely believable (hallucinations). How can you verify AI claims and ensure accuracy?

The Solution: Be a Fact-Checker

Factuality is about verifying AI outputs against reliable sources and detecting when the AI is making things up. It's like being a fact-checker at a news organization — don't publish until you verify. Hallucinations are the core problem, and RAG with grounding are the best defenses.

Think of it like a newsroom fact-checker:

  • 1. Receive claim: AI says: "According to Smith v. Jones (2019), the regulation requires..."
  • 2. Verify citations: Does "Smith v. Jones (2019)" exist? Check DOI, author names, court records. LLMs fabricate plausible-sounding references
  • 3. Cross-reference facts: Compare claims against 2+ independent sources. Self-consistency: ask the same question 3 ways — do answers agree?
  • 4. Classify confidence: Tag each fact: [VERIFIED] (found in source), [PLAUSIBLE] (consistent but unchecked), [UNVERIFIED] (no source found)

Where Is This Used?

  • Source Attribution: Ask AI to cite its sources
  • RAG: Ground responses in retrieved documents
  • Self-Consistency: Ask the same question multiple ways
  • External Validation: Cross-check with search engines or databases

Fun Fact: Even the best LLMs hallucinate about 3-5% of the time on factual questions. The rate increases significantly for obscure topics, recent events, or highly specific technical details. Always verify important facts!

Try It Yourself!

See how to detect and handle AI hallucinations in practice.

What are Hallucinations?

LLM hallucinations are confidently generated content that does not correspond to reality. The model can invent facts, quotes, statistics, and even scientific studies that do not exist, while sounding absolutely convincing.

Why Does This Happen?

LLMs predict the most likely text continuation, they don't "know" facts. They don't have real-time internet access, their knowledge is limited to training data cutoff, and they're optimized for fluency, not accuracy.

How to Detect?

Signs of hallucinations: overly specific details, non-existent references, contradictions on repeated queries, information about events after the model's training date. Always verify critical information from independent sources.

Mitigation Methods

Effective approaches: RAG (retrieval-augmented generation) for source grounding, Chain of Thought (CoT) for step-by-step verification, self-verification — asking the model to check its claims, requiring sources and confidence levels.

Hallucination Types & Defense Strategies

LLM Hallucinations & Fact-Checking

Explore types of hallucinations and prevention strategies

Types of Hallucinations

Factual HallucinationFactual

"Who invented the telephone?"

Citation HallucinationCitation

"Cite a study about AI safety"

Logical HallucinationLogic

"If A > B and B > C, what about A and C?"

Temporal HallucinationTemporal

"What happened in tech in 2024?"

Spot the Hallucination

An LLM generated the following response about the Eiffel Tower. Click each statement to mark it as Real or Hallucinated, then check your answers.

1.

The Eiffel Tower is 330 meters tall.

2.

It was designed by Gustave Eiffel and completed in 1889.

3.

Albert Einstein visited the tower in 1905 and gave a famous physics lecture from the top.

4.

The tower receives about 7 million visitors per year.

5.

In 2019, a second tower was built next to it called 'Tour Lumiere'.

Hallucination Mitigation Strategies

RAG (Retrieval)

Ground responses in retrieved documents

85%
effectiveness
Chain of Thought

Step-by-step reasoning reduces errors

70%
effectiveness
Self-Verification

Ask model to verify its own claims

60%
effectiveness
Citation Required

Require sources for factual claims

75%
effectiveness

Best Practices

  • Always verify facts from external sources
  • Use RAG for working with current data
  • Ask the model to indicate confidence levels
  • Break complex questions into simpler ones
Practical Tips

When generating content:

  • Ask for sources
  • Use RAG for facts
  • Break down complex questions

When verifying answers:

  • Double-check citations
  • Ask clarifying questions
  • Use external sources

Try it yourself

Interactive demo of this technique

Technique Comparison
Demo Mode
Pre-recorded responses
TaskBeginnerAnalysis

Hallucination detection — confident but incorrect model response

Without technique
Without technique
Prompt
Who wrote the book "Quantum Algorithms for Everyday Life"?
Response

The book "Quantum Algorithms for Everyday Life" was written by Professor Michael Vershinin from MIT and published in 2021 by O'Reilly. It became a bestseller in the popular science category.

Tokens:16/48
Time:280ms
Quality:
With Factuality
With technique
Prompt
<instructions> Answer the user's question. Follow these rules: 1. If you are unsure about a fact — state it explicitly 2. Distinguish "I know for certain" from "I am guessing" 3. If the book/author does not exist — say you cannot confirm 4. Do not invent names, dates, publishers 5. Suggest a way to verify </instructions> Question: Who wrote the book "Quantum Algorithms for Everyday Life"?
Response

I cannot confirm the existence of a book with the exact title "Quantum Algorithms for Everyday Life." You might be thinking of a different book on quantum computing. I recommend checking on Google Scholar, Amazon, or a library catalog.

👁️Without instructions the model confidently "hallucinates" author, publisher, and date
🧠The "do not invent" rule forces the model to acknowledge uncertainty
🧠The model suggests verification instead of fabricating an answer
An honest "I don't know" is far more valuable than a confident lie
Tokens:65/45
Time:260ms
Quality:
Why this works

Models default to providing an answer even when there is none. Explicit instructions to "acknowledge uncertainty" and "do not fabricate" are critical for factual accuracy.

1 / 2

Lesson Quiz

1 of 3

1.What causes LLM hallucinations?

Practice Challenges

Create a free account to solve challenges

7 AI-verified challenges for this lesson

Related lessons:Chain Of VerificationRag

This lesson is part of a structured LLM course.

My Learning Path