Skip to main content

๐Ÿง  Fixing Hallucinations

What Are Hallucinations?โ€‹

Hallucinations happen when an AI confidently generates information that is incorrect, made up, or not grounded in reality. The AI might invent fake statistics, cite non-existent sources, or state wrong facts โ€” all while sounding completely sure of itself.

This is one of the most dangerous failure modes because the output looks correct even when it's not.

Why This Mattersโ€‹

If you use AI-generated content without checking for hallucinations, you risk publishing false information, making bad decisions based on fake data, or losing credibility. In fields like medicine, law, and finance, hallucinations can cause real harm. Every prompt engineer must know how to reduce and catch them.


Why Do AI Models Hallucinate?โ€‹

  1. Pattern completion โ€” LLMs predict the next likely word, not the next true word.
  2. Training data gaps โ€” The model may not have seen enough data on a topic.
  3. Overconfidence โ€” Models are trained to give answers, not to say "I don't know."
  4. Vague prompts โ€” When the prompt is unclear, the AI fills in gaps with plausible-sounding fiction.
  5. Rare or niche topics โ€” The less common the topic, the more likely the AI invents details.

Strategies to Reduce Hallucinationsโ€‹

1. Ask for Citationsโ€‹

โœ… List 5 benefits of intermittent fasting. 
For each benefit, cite a specific published study or say "no source available."

When you ask for sources, the AI is more cautious and often flags uncertain claims.

2. Train "I Don't Know" Behaviorโ€‹

โœ… Answer the following question. If you are not sure or the information 
might be outdated, say "I'm not confident about this" instead of guessing.

3. Use Grounding Techniquesโ€‹

Provide the source material directly in the prompt:

โœ… Based ONLY on the following article, answer the question. 
Do not add any information that is not in the article.

Article: [paste article text here]

Question: What were the key findings?

4. Verification Promptsโ€‹

After getting an answer, ask the AI to check itself:

โœ… Review your previous answer. Are there any claims that might be 
inaccurate or that you're not confident about? Flag them.

5. Constrain to Known Dataโ€‹

โœ… Using only the data in the table below, calculate the average revenue.
Do not estimate or use external knowledge.

| Quarter | Revenue |
|---------|---------|
| Q1 | $50,000 |
| Q2 | $65,000 |
| Q3 | $58,000 |

Before / After Examplesโ€‹

โŒ Bad Exampleโ€‹

Tell me about the history of the Python programming language, 
including exact dates and version release statistics.

Risk: The AI may invent specific dates, version numbers, or download statistics that are wrong.

โœ… Improved Exampleโ€‹

Give me a brief overview of Python's history covering:
- Who created it and approximately when
- Major version milestones (Python 2 vs Python 3)
- Why it became popular

If you're unsure about a specific date or number, say "approximately"
or "I'm not certain of the exact figure." Do not invent statistics.

โŒ Bad Exampleโ€‹

What are the latest crime statistics for New York City?

Problem: The AI's training data has a cutoff date. It will likely hallucinate recent numbers.

โœ… Improved Exampleโ€‹

I need crime statistics for New York City. Your training data may be outdated.

Please:
1. State what year your data goes up to
2. Provide what you know with appropriate caveats
3. Recommend official sources where I can find current data
4. Do NOT make up recent numbers

The Hallucination Detection Checklistโ€‹

When reviewing AI output, check for:

Red FlagWhat to Do
Specific numbers or statisticsVerify with a trusted source
Named studies or papersSearch for the actual paper
Quotes attributed to peopleConfirm the quote exists
"According to research..."Ask: which research, specifically?
Very confident tone on niche topicsCross-reference independently
URLs or linksCheck if they actually exist

๐Ÿงช Try It Yourself

Edit the prompt and click Run to see the AI response.


Practice Challengeโ€‹

Challenge

Try this exercise to practice catching hallucinations:

  1. Ask the AI: "Who won the Nobel Prize in Literature in 2019 and what was their most famous work?"
  2. Verify the answer independently
  3. Now ask: "Who won the Nobel Prize in Literature in 2019? If you're not 100% certain, say so."
  4. Compare how the two responses differ
  5. Try the same with a more obscure question the AI is likely to get wrong

Real-World Scenarioโ€‹

Scenario: A legal assistant uses AI to research case law. The AI returns three case citations, complete with case numbers, dates, and summaries. The assistant includes them in a legal brief. Two of the three cases don't exist โ€” the AI fabricated them.

What Went Wrong:

  • The prompt asked for specific citations without grounding
  • No verification step was included
  • The confident tone made fake cases look real

Fix:

I need case law related to employer liability for remote work injuries.

Important rules:
- Only cite cases you are highly confident are real
- For each case, include: case name, year, and a one-sentence summary
- If you cannot find specific cases, say so and suggest search terms
I can use on legal databases like Westlaw or LexisNexis
- It is better to cite fewer real cases than to risk citing fake ones

Interview Questionโ€‹

Interview Question

Q: How do you handle AI hallucinations in production applications?

A: I use a multi-layer approach:

  1. Prompt-level prevention โ€” I use grounding (provide source material), ask the AI to cite sources, and instruct it to say "I don't know" when uncertain.
  2. Output validation โ€” I check specific claims, numbers, and citations against trusted sources before using them.
  3. Retrieval-Augmented Generation (RAG) โ€” For knowledge-heavy applications, I connect the AI to a verified knowledge base so it answers from real data instead of generating from memory.
  4. User-facing disclaimers โ€” If the output goes to end users, I flag AI-generated content and encourage verification.

The key principle: never trust AI output on factual claims without independent verification.


Summaryโ€‹

Summary
  • Hallucinations are confidently stated false information โ€” the most dangerous AI failure
  • They happen because LLMs predict likely words, not true words
  • Reduce hallucinations by: asking for citations, grounding in source material, training "I don't know" behavior, and using verification prompts
  • Always verify specific facts, statistics, quotes, and citations independently
  • In production, use RAG and validation layers โ€” never trust AI output on factual claims blindly
  • It's better to get "I'm not sure" than a confident wrong answer