A hallucination is when a model produces something fluent and confident that turns out to be false. In coding this shows up constantly: a method that does not exist on the library, an import from the wrong package, a config option someone wishes were real, a plausible-looking function signature that is subtly invented.
Why it happens
It follows directly from what a model is. The model predicts the most plausible next tokens; it does not look anything up and it has no internal "is this true" check. Most of the time plausible and correct line up, so it feels reliable. When they diverge, you get an answer that reads perfectly and is wrong. Crucially, the model has no way to tell the difference, which is why hallucinations come with the same confident tone as correct answers.
What actually reduces it
You cannot make a model stop hallucinating, but you can starve the failure mode:
- Give it ground truth. The single biggest lever. Let the agent read the real file, the real types, the actual docs, so the answer comes from your context instead of the model's memory.
- Prefer tools over recall. An agent that runs the code or greps the repo beats one guessing from training.
- Verify, do not trust. Run it, type-check it, click it. Treat every generated API you have not seen before as unverified until proven.
Related terms
AI
In the coding-agent world, "AI" almost always means a large language model: a system that predicts the next chunk of text from everything it has been shown. It is not a mind and it is not a database. It is a very good pattern completer.
Read definition →Model
A model is the trained artifact at the centre of every AI coding tool: a large file of numbers (parameters) that, given some text, produces the most likely continuation. When people say "which model are you using," this is the thing they mean.
Read definition →Context window
The context window is the maximum amount of text, measured in tokens, that a model can consider for a single request. It is a hard ceiling, and it is the main resource you manage when working with an agent.
Read definition →