Hallucinations
Why models hallucinate, real examples, and how to develop a verification mindset.
AI models can be incredibly useful, but they can also be confidently wrong.
This is often called a hallucination: the model produces an answer that sounds plausible but is not actually true.
Why hallucinations happen
Models generate likely continuations from patterns. They do not automatically know whether a statement is true in your codebase, your production environment, or today's documentation.
If you ask for an API that does not exist, a model may still invent one that looks reasonable. If you ask about a file it has not seen, it may infer the answer from common project structures and get it wrong.
That does not make the model useless. It means you need to work with it as a powerful assistant whose output must be verified.
Common examples
A model might:
- Import a package that is not installed.
- Call a method that does not exist in your version of a library.
- Assume a folder structure from another framework.
- Produce code that typechecks but does not match the product requirement.
- Explain a bug with a plausible theory that logs do not support.
These failures are especially common when the model lacks the right context.
Build a verification mindset
The most important habit is to ask: how would I prove this is correct?
For code, that proof can come from:
- Tests.
- Type checking.
- Running the app.
- Reading the actual implementation.
- Comparing the answer against official documentation.
- Inspecting logs or production traces.
Do not treat the model's confidence as evidence. Treat the model's answer as a candidate that still needs proof.
Use hallucinations productively
When a model is wrong, tighten the loop:
- Provide the missing context.
- Show the exact error.
- Ask for a smaller hypothesis.
- Verify with a concrete command or test.
Good AI usage is not about avoiding every mistake. It is about making mistakes cheap to catch.