Hallucinations: why AI is confidently wrong
AI sometimes states false things in a fluent, certain tone: invented facts, fake citations, code that calls functions that do not exist. Learn why it happens, where it is most likely, and a practical routine for catching it.
A hallucination is an answer that sounds right but is false or made up. A student asks for references for an essay and gets five neat citations, with authors, journal names and years. None of the papers exist. A developer gets code that calls df.smart_clean(), a pandas function nobody ever wrote.
The problem is not that the AI is lying. It has no intention to deceive. It is doing what it was built to do: produce likely-sounding text. When the true answer is not something it learned well, a plausible-sounding one comes out instead, in the same confident voice.
Why it happens
Four root causes
- 1It predicts, it does not look up. As the lesson *How large language models work* explained, the model generates the likely next tokens. A made-up book title that fits the pattern of real titles is a very likely output.
- 2Gaps in what it learned. Rare topics, local details (your college's rules, a small Bengaluru startup), new events after its knowledge cutoff and niche technical versions are thinly covered, so it fills the gaps with guesses.
- 3Training rewards helpfulness. Models are tuned to give useful-sounding answers, and an answer is often judged better than "I don't know". Newer models are getting better at admitting uncertainty, but not reliably.
- 4Your prompt can push it. A question with a false assumption ("Why did the Indian government ban Python in 2019?") may be answered as if the assumption were true. A request for "five sources" pushes it to produce five, real or not.
Where to expect it
Risk by type of request
| Request | Risk | Why |
|---|---|---|
| Explaining a well-known concept (what is a loop?) | Lower | Seen countless times in training |
| Exact numbers, dates, prices, statistics | High | Specific details are easy to blur or invent |
| Citations, links, case law, book and paper titles | Very high | Looks like a pattern, so fake ones are easy to generate |
| Recent events | High without search | Beyond the knowledge cutoff |
| Your own documents, if not pasted in | High | The model cannot see them |
| Code using libraries or APIs | Medium to high | Function names, flags and versions get mixed up |
| Maths and multi-step logic | Medium | Small slips in a long chain spoil the result |
| Medical, legal, financial advice | Serious consequences | A confident error can hurt; consult a professional |
Confidence is not evidence
A smooth, detailed, well-formatted answer feels trustworthy. That feeling is exactly what fluent text produces whether or not it is true. Do not judge accuracy by tone, length or how many details are given. Real-looking details are often where the invention hides.
Reduce it
Ways to get fewer hallucinations
- Turn on web search or a research mode when the question depends on current or specific facts, then open the sources it cites.
- Paste the source text (notes, a policy, an article) and say "answer only from the text below".
- Give the model permission to say it does not know: "If you are not sure, say so instead of guessing."
- Ask for one claim at a time, not a long list of facts.
- Avoid false-premise questions; ask "Is it true that...?" instead of "Why did...?"
- Use tools for what they are good at: a calculator or code run for arithmetic, search for news.
- Ask for the reasoning or the exact quote that supports a claim.
Answer the question using ONLY the text between the --- lines. If the text does not contain the answer, reply "Not in the text." For each point in your answer, quote the sentence from the text that supports it.
Question: [your question]
---
[paste your notes or document here]
---What to expect: A good answer quotes real lines from your text. If a quote does not appear in what you pasted, treat that part as invented.
Catch it: a verification routine
Five quick checks before you trust an answer
- 1Decide the stakes. A study tip needs a light check. A figure in a report, a legal point or code in production needs a careful one.
- 2Pick out the checkable claims: names, numbers, dates, quotes, links, function names.
- 3Check each against a second source you trust: the official documentation, the textbook, the government or company website, the original paper. Searching for the exact title in quotes is a fast test for a citation.
- 4Run code. Run it, read the error, and check function names in the official docs. Code that runs can still be wrong, so test it with a few cases.
- 5Ask the model to check itself, then check again. "List the claims above you are least sure about." This often surfaces weak spots, but it is a prompt for your checking, not a replacement for it.
Review your previous answer. List every factual claim, number, name, date and citation in it. For each one, tell me: (a) how confident you are, (b) how I could verify it (a specific kind of source), and (c) whether you may have made it up. Be honest rather than reassuring.What to expect: The model can miss its own errors, so use the output as a checklist of what to verify yourself. Claims it flags as uncertain are the first to check.
Hallucinations are useful to know in interviews
Interviewers for AI-related roles often ask how you would reduce hallucinations in a product. Good answers mention giving the model source documents (retrieval, often called RAG), asking for citations, letting it say "I don't know", checking outputs automatically where possible, and keeping a human in the loop for high-stakes decisions.
Try it: Catch an invented fact
1. In a free chatbot with web search turned off, ask: "Give me three academic papers, with authors and year, about [a niche topic you know something about]." 2. Search for each title in quotation marks on Google Scholar or the web. 3. Mark each as real, partly right or invented. 4. Repeat the request with search or a research mode on and compare. 5. Finally ask: "Why did Python's creator ban the print function in 2015?" and see whether it challenges the false premise.
Key takeaways
- A hallucination is fluent, confident text that is false or invented.
- It happens because models predict likely text rather than look up facts, and gaps in knowledge get filled with plausible guesses.
- Highest risk: citations, exact numbers, recent events, your private documents and unfamiliar APIs.
- Reduce it by supplying source text, using search, allowing "I don't know" and avoiding false premises.
- Verify claims that matter against a second source; run and test code; never judge by tone.
Check yourself
Finishing the quiz marks the lesson as done.
1. Why do language models hallucinate?
2. Which request carries the highest hallucination risk?
3. An answer is long, detailed and very confident. What does that tell you about its accuracy?
4. You paste your class notes and want an answer based only on them. Which instruction helps most?
5. AI-written code throws an error saying a function does not exist. What is the best next step?
Saved on this device. Create a free account to keep it on every device.
Practise this with Sam
A real mock interview, out loud, with an honest scorecard. Free to start.