AI Hallucinations
A hallucination is when an AI gives an answer that sounds correct but is false or made up.
Why Do Hallucinations Happen?
Remember: a language model predicts likely text, not checked text. If it does not know something, the most "likely sounding" answer may still be invented. Reasons include:
- The fact was missing or rare in its training data.
- The question is about events after its knowledge cutoff.
- The prompt is vague, so the model guesses what you mean.
- It tries to be helpful and fills gaps instead of saying "I don't know".
Modern models hallucinate less than early ones, especially when they can search the web, but the problem has not disappeared.
Common Types
| Type | Example |
|---|---|
| Fake facts | Wrong year for an event, wrong capital, wrong formula |
| Fake sources | A book, research paper or court case that does not exist |
| Fake quotes | Words a famous person never said |
| Wrong numbers | A sum or percentage that is slightly off |
| Fake code | A function or library option that does not exist |
| Wrong details about you | Mixing you up with someone with a similar name |
A Simple Way to Spot Risky Answers
Any answer with specific names, numbers, dates, links or quotes needs checking. This small checker flags such details in a reply:
Example
import re
reply = "The bridge opened in 1984 and cost Rs 250 million, says Dr Khan."
numbers = re.findall(r"\d+", reply)
has_quote_source = "says" in reply or "said" in reply
print("Numbers to verify:", numbers)
print("Named source to verify:", has_quote_source)Numbers to verify: ['1984', '250'] Named source to verify: True
The tool cannot tell if the facts are true. It only shows you what to check.
How to Reduce Hallucinations
- Give the source: paste the document and say "Answer only from this text."
- Allow "I don't know": tell the model it is fine to say it is unsure.
- Ask for sources, then open and check them yourself.
- Use web search or research modes for recent or factual questions.
- Ask for low creativity for factual tasks.
- Break big questions into smaller ones.
Here is a prompt that uses several of these ideas:
Example
Answer using ONLY the notice below. If the answer is not in
the notice, reply "Not mentioned in the notice."
Quote the exact sentence you used.
Notice:
"Admissions for the evening batch close on 30 November.
Classes are held Monday to Thursday, 5 pm to 7 pm."
Question: What is the fee for the evening batch?A good model should reply "Not mentioned in the notice." instead of inventing a fee.
Checking Code from AI
AI-written code can call functions that do not exist or have hidden bugs. Always run it and test it:
Example
def is_even(n):
return n % 2 == 0
for n in [0, 3, 10]:
print(n, is_even(n))0 True 3 False 10 True
Testing with a few known answers is the fastest way to catch a mistake.
Never use AI answers alone for medical, legal or financial decisions. Use them to prepare questions, then confirm with a qualified person or an official source.
Exercise
Exercise
Which prompt is most likely to reduce hallucinations?
