# Hallucination

> The Hallucination is a response of an AI model that sounds plausible but is factually incorrect or made up.

## What is an AI hallucination and how do I reduce it?

The situation when a model confidently generates false information, such as non-existent APIs, libraries or facts. Reduced by providing relevant context and verified by checking sources and running the code.

- Topic: Language Models
- Type: concept

## Example

Wrong:

```text
What does section 4.2 of our refund policy say?
```

Right:

```text
Answer only from the policy below.
If it does not cover the question, reply 'I don't know'.
<policy>
{{policyText}}
</policy>
Question: What does section 4.2 say?
```

Giving the source and an explicit way to say 'I don't know' removes the pressure to invent an answer.

## Common mistakes

- Installing a package an AI made up, which an attacker may have registered.

## Key points

- Every imported package and called API method actually exists in the docs or registry.
- Quotes, links and citations in the answer point to real sources that say the same thing.
- The prompt allows the model to answer that it does not know.

## Interview questions

### Why do LLMs hallucinate?

Models predict likely text, not verified facts. When the training data lacks an answer, the most plausible-sounding continuation can still be false.

### Can hallucinations be fully prevented?

No. Grounding, citations, a low temperature and checks in code reduce them, but output that matters still needs verification.

### What is package hallucination?

It is when a model suggests a dependency that does not exist. Attackers can register such names with malicious code, so check every package in the registry before installing.

## Related cards

- [Grounding](https://wonderium.dev/ai/grounding.md)
- [Slopsquatting](https://wonderium.dev/ai/slopsquatting.md)
- [RAG](https://wonderium.dev/ai/rag.md)
- [Knowledge Cutoff](https://wonderium.dev/ai/knowledge-cutoff.md)
- [Evals](https://wonderium.dev/ai/evals.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/hallucination
- Last updated: 2026-11-25
