Why Does AI Sometimes Make Things Up? Understanding and Mitigating Hallucinations

Language models (LLMs) can generate impressive texts, write code, and answer complex questions. Yet they have one fundamental weakness: they sometimes present complete nonsense with absolute confidence. In the world of artificial intelligence, we call this phenomenon a hallucination.

What is an AI hallucination?

A hallucination occurs when an AI model generates information that is not factually correct, does not logically follow from the context, or is simply made up. This happens because LLMs are not databases where they 'look up' facts. They are probabilistic models: they predict which word is statistically most logical to type next, based on their training data.

How do you recognize them?

Hallucinations are often difficult to spot because the grammar and tone are perfectly fine. Watch out for the following signs:

Techniques to mitigate hallucinations

Although you can never 100% rule out hallucinations in foundational models, there are powerful methods to drastically limit them.

  1. Targeted Prompt Engineering: Explicitly instruct the model to only answer if it knows the facts. Add: "If you do not know the answer, say 'I do not know'."
  2. Ask for source attribution and citations: Force the model to quote parts of the text you provided exactly before drawing a conclusion.
  3. Retrieval-Augmented Generation (RAG): This is the most effective method for production environments. With RAG, you link the language model to an external knowledge base (such as your own documents). The system first searches for the relevant facts via vector search and provides these as context to the LLM. The model then only needs to summarize the provided context, instead of drawing from its 'memory'. For implementation details on how to link models to your own data, you can visit api.llmnet.nl.

Exercise: Verify and correct

Assignment: Open your favorite AI model. Ask it to write a short biography of a local politician or a niche topic from your field of expertise (something that is not world-famous).

Analyze the response:

  1. Which facts are correct?
  2. Which years or achievements sound logical, but turn out to be made up upon a Google search?
  3. Adjust your prompt with the rule: "Limit your answer strictly to facts you are 100% sure of; do not invent missing data." Compare the new response.