AI Hallucination: Why AI Makes Things Up and How to Reduce It

What is an AI hallucination? Learn why language models invent facts, how to spot it, and practical ways to reduce hallucinations in chats and AI agents.

An AI hallucination is when a language model states something false, invented, or unsupported as if it were true. It happens because LLMs generate the most plausible-sounding text, not text that has been checked against reality. You cannot remove hallucinations entirely, but you can make them much rarer and much easier to catch.

This guide explains why hallucinations happen, what they look like in everyday use and in coding, and the habits that reduce them.

What an AI hallucination looks like

Hallucinations are rarely obvious nonsense. They usually look exactly like a correct answer, which is what makes them risky. Common forms include:

  • Invented facts. A wrong date, a made-up statistic, or a feature a product does not have.
  • Fake sources. Citations, book titles, or links that do not exist.
  • Made-up code. A function, library option, or command-line flag that sounds right but is not real.
  • Wrong details in real things. A real person, place, or tool with incorrect information attached.
  • Overconfident reasoning. A clean step-by-step explanation that reaches the wrong conclusion.
  • False claims of success. An agent saying a task is done or tests pass when they do not.

Why AI hallucinates

To understand hallucinations, it helps to remember what an LLM does. It predicts the next piece of text based on patterns learned from training data. If you want the full picture, see how LLMs work.

From that, several causes follow.

It optimizes for plausible, not true

The model learned what text usually looks like. A confident, well-formed answer is a very “likely” kind of text, even when the specific facts inside it are wrong. There is no built-in fact checker in the prediction step.

Gaps in what it learned

If a topic was rare in the training data, or changed after training ended, the model has weak or outdated patterns to draw on. Instead of stopping, it often fills the gap with something that fits the shape of an answer.

Pressure to answer

Models are trained to be helpful. Unless they have learned to say “I don’t know” in the right situations, the most natural continuation of a question is an answer. Modern models are better at expressing uncertainty, but it is not guaranteed.

Missing or unclear context

If the information the model needs is not in its context window, it has to rely on memory. Vague prompts make this worse, because the model has to guess what you mean as well as what is true. See tokens and context windows for why the model only “knows” what is in front of it.

Randomness in generation

Most apps let the model sample among several likely next tokens. That creativity is useful for writing, but it also means a less likely, wrong detail can slip in.

Where hallucinations matter most

The risk depends on the task:

Task Hallucination risk Why
Brainstorming, drafting Low impact You expect to edit and choose ideas anyway
Summarizing a document you provide Lower risk The facts are in the context, though details can still slip
Answering niche factual questions Higher risk Relies on memory of rare information
Citations, quotes, statistics High risk Specific details are easy to invent convincingly
Code using less common libraries Higher risk Plausible but nonexistent functions or options
Legal, medical, financial facts High impact Errors can cause real harm

How to reduce AI hallucinations

You cannot switch hallucinations off, but these techniques make a real difference.

1. Give the model the facts

The single most effective step is grounding. Paste the document, data, or code the answer should come from, and ask the model to use only that. Systems that fetch relevant documents before answering, often called retrieval-augmented generation, use the same idea at scale.

2. Ask it to admit uncertainty

Say so explicitly: “If you are not sure, say you don’t know” or “Mark anything you are uncertain about.” Models follow this kind of instruction reasonably well.

3. Ask for sources you can check

Request quotes from the provided material or links you can open. Then actually open a few. If a source cannot be found, treat the claim as unverified.

4. Be specific in your prompt

Clear questions with defined scope leave less room for guessing. “Summarize the refund policy in this text” is safer than “What’s the refund policy?”

5. Lower the temperature for factual work

A lower temperature makes the model favor its most likely answer and reduces random detours. It does not guarantee accuracy, but it helps for factual and technical tasks. More on that in LLM temperature and other settings.

6. Break big tasks into smaller steps

Long, complex answers give more chances for errors to creep in. Smaller steps are easier for the model to get right and easier for you to check.

7. Verify what matters

Treat AI output like a draft from a smart colleague who sometimes misremembers. Check names, numbers, quotes, and anything you will publish or act on.

Hallucinations in coding agents

Coding is one area where hallucinations are easier to catch, because code can be tested. A made-up function fails when the program runs. A wrong assumption shows up when a test fails.

That is why good coding agents do not just write code and stop. They run the code, run the tests, read the errors, and fix them. This feedback loop turns a hallucination from a silent mistake into a visible error the agent can correct. Read what is an AI agent for how that loop works.

Agents can still hallucinate about their own work, for example claiming that everything passes. The fix is the same as with people: independent checks.

  • Run the project’s real tests and checks, not just the agent’s own summary.
  • Have a second agent or a human review the changes.
  • Send failing work back until it actually passes.

BotQuarters builds this into its AI teams: the team runs the project’s tests and checks itself, and work that fails goes back to the desk until it passes, before you get a report to approve.

FAQ

What is an AI hallucination?

An AI hallucination is false or made-up information that an AI model presents as fact. It can be an invented statistic, a fake citation, a nonexistent code function, or a wrong detail about a real topic, often stated with full confidence.

Why does AI hallucinate?

Language models generate the most plausible next text based on patterns from training, rather than checking facts. When information is missing, rare, outdated, or not in the prompt, the model may fill the gap with something that sounds right but is not.

Can AI hallucinations be completely eliminated?

No current method eliminates them completely. You can greatly reduce them by giving the model the source material, asking it to flag uncertainty, using lower temperature for factual tasks, and verifying important output with tests, sources, or a reviewer.

Do AI agents hallucinate less than chatbots?

Agents can hallucinate just like chatbots, since they use the same models. The difference is that agents can check their work with tools, for example by running code and tests, which catches many errors. Independent review is still important, because an agent can misreport its own results.

CEO of BotQuarters

Writes about AI agents, AI teams and getting real work done with them. BotQuarters turns a team of AI agents into a company you can watch at work.

Keep reading