Back to Tutorials
LLM Application Development
Intermediate

Hallucinations: Why Models Make Things Up

Read 1,260 real answers from a small model, see where it invents names and dates, then try the fixes: a source, permission to say “I don’t know”, and asking more than once.

11 minInteractive: drag, click and try things as you read


Ask a language model something it doesn’t know and it rarely says so. It answers anyway, fluently and confidently, with a name, a date or a number that sounds right and isn’t. That’s a hallucination, and it’s the main reason you can’t take an AI’s word for things. You can’t stop a model guessing, but you can give it the facts, let it decline, and check its answers. Here you’ll read 1,260 real answers from a small model, see where it invents things, and try the fixes on them.

Why models make things up#

A language model writes by predicting the next word, again and again, and it was trained to make those predictions plausible, not true. There’s no separate store of facts it checks against. For a famous fact, the plausible answer and the true one are the same, because the model saw it thousands of times. For an obscure one, the model has only a vague sense of what kind of answer fits (a plausible name, a city in the right part of the world), and it produces one.

Saying “I don’t know” is also something a model has to learn, and the incentives are against it. In 2025, OpenAI researchers argued that most of the tests used to train and compare models score only right answers, like a multiple-choice exam with no penalty for guessing. A model that always guesses beats one that admits doubt, so that’s the behaviour training rewards. You’ll see this effect in the second figure.

An experiment you can read#

We asked Qwen3-1.7B, a small open model that runs on a laptop, 42 questions: 12 well-known facts, 20 less well-known ones, and 10 about things that don’t exist, such as a 1931 novel called The Lanterns of Haverford or a chemical element called brennium (we checked that none of them exist). Each question went in three ways (plain, with permission to say “I don’t know”, and with a short source text), and each was asked ten times, because a model’s answer can change from one try to the next.

Predict first

Asked ten times who wrote The Lanterns of Haverford, a novel that doesn’t exist, how many times does the model say it doesn’t know?

Try it
Real answers from Qwen3-1.7B, run offline with its recommended settings (temperature 0.7) and shown exactly as it wrote them. Each answer is marked right, wrong or declined against the true answer. The made-up questions have no true answer, so any answer other than a refusal is wrong.

Well-known facts come back right ten times out of ten, with one exception: asked which gas plants take from the air, it says “oxygen” all ten times. On the less well-known questions it gets half wrong, and the wrong answers wander: the capital of Burkina Faso is Bamako five times (Mali’s capital), Bouaké four times (a city in Ivory Coast) and Conakry once (Guinea’s capital); the capital of Vanuatu is “Vaišava”, “Vaihutu” and “Vaiholmaka”, places that don’t exist. On the made-up questions it never once declines: 100 answers, 100 inventions, including a Holloway–Brandt engine “invented by John Holloway and Carl Brandt”.

This model is small, and larger models know far more facts. But the pattern is the same for every model, just further out: past the edge of what it knows, it carries on in the same confident voice. The model sounds equally sure whether it knows or not, so confidence in the wording tells you nothing.

Five ways to reduce them#

1. Give it the facts

Switch the first figure to With a source. The prompt now includes a short passage and asks the model to answer only from it. Every one of the 32 real questions comes back right, all 320 answers. That’s retrieval-augmented generation (RAG) in miniature: find the relevant text first, then ask the model to answer from it rather than from memory. It’s the single most effective fix.

Now look at the made-up questions with a source. The passages are about something nearby but don’t answer the question, as happens when search finds the wrong document. For 7 of the 10 it answers anyway, and 6 of those answers are lifted straight from the passage: the opera The Glass Orchard is “by Philip Glass”, because the source mentions Philip Glass; the capital of Veldoria is “Vaduz”, the capital of Liechtenstein. Grounding moves the problem rather than removing it: the answer is now only as good as what you retrieved.

2. Let it say “I don’t know”

Adding “If you’re not sure, say ‘I don’t know’” helps, unevenly. On the made-up questions, 4 of 10 now get an honest refusal every time, but the other 6 are still invented. It even fixed some real answers: with permission to decline, Burkina Faso’s capital comes back right (Ouagadougou) 8 times in 10. And it costs little: none of the well-known answers got worse. Always offer the model a way out, and say what it should do instead: “say you don’t know”, “ask a clarifying question”, “pass it to a person”.

3. Ask more than once

Look again at the wandering answers. When the model knows something, its ten samples agree; when it’s guessing, they scatter. So you can ask several times and only trust an answer the samples agree on.

Predict first

You only accept an answer when all ten samples agree. With the plain prompt, how many of the 21 wrong answers get through?

Try it
The same 42 questions. Each dot is a question, placed by how many of its ten samples gave the most common answer and coloured by whether that answer was right. Questions left of the bar are held back unanswered. The score is computed live.

With the plain prompt and no bar, the model gets 21 right and 21 wrong. Demand that all ten samples agree and it answers 25: 20 right and 5 wrong. That’s a much more trustworthy assistant, at the price of staying silent on 17 questions. Researchers have built this into methods with names like self-consistency (take the most common of several answers, which improves reasoning) and SelfCheckGPT (flag statements the samples don’t agree on). It costs extra calls, so it fits answers that matter more than a few cents.

Now use the scoring row. If a wrong answer costs nothing, always answering wins: guessing is free, which is exactly the incentive OpenAI’s researchers described. Charge 1 point per wrong answer and the best bar is 10 of 10; charge 3 and always answering scores −42. Whether a model should guess depends on what a wrong answer costs, so decide that cost first. With a source, the bar barely matters: the right answers are unanimous, and so are most of the borrowed ones, which is why consistency checks can’t replace checking the source.

4. Check answers against the source

Ask the model to quote the sentence that supports its answer, then check in code that the quote really appears in the source. That catches answers invented from memory. It isn’t enough on its own: “Vaduz” does appear in the source, it just doesn’t answer the question. So the stronger check asks whether the quote supports the claim, using a second model call or a model trained for that job (an entailment model). When the check fails, show the source instead of the answer, or say nothing.

5. Measure it

You can’t reduce what you don’t count. Build a test set like the one here: questions the model should know, questions only your documents answer, and questions with no answer at all. Track wrong answers separately from refusals, because “accuracy” alone rewards guessing. Re-run it whenever you change the model, the prompt or the retrieval, and read the wrong answers, not just the score.

In code#

The consistency check from the experiment, with the same model, free and local (pip install transformers torch):

from collections import Counter
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

torch.manual_seed(0)  # sampling is random; fix the seed to get the same answers each run

name = "Qwen/Qwen3-1.7B"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)

def ask(question, n=10):
    messages = [{"role": "user", "content": question + " Answer with just the answer, no explanation."}]
    text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
    inputs = tok(text, return_tensors="pt")
    out = model.generate(**inputs, do_sample=True, temperature=0.7, top_p=0.8, top_k=20,
                         num_return_sequences=n, max_new_tokens=24)
    return [tok.decode(o[inputs.input_ids.shape[1]:], skip_special_tokens=True).strip() for o in out]

for q in ["What is the capital of Bhutan?", "What is the capital of Burkina Faso?"]:
    answers = Counter(ask(q))
    top, count = answers.most_common(1)[0]
    print(q, dict(answers))
    print("  ->", top if count >= 8 else "Not sure: the answers disagree.")
# What is the capital of Bhutan? {'Thimphu': 10}
#   -> Thimphu
# What is the capital of Burkina Faso? {'Conakry': 2, 'Bouaké': 2, 'Bamako': 6}
#   -> Not sure: the answers disagree.

Your answers will differ from run to run, which is the point: the spread is the signal. The same idea works with any model behind an API, at ten times the cost of one call, so save it for answers that matter.

What to remember

  • Models are trained to sound plausible, not to know what they don’t know, so past the edge of their knowledge they guess in the same confident voice.
  • A source fixes most of it, but only if the source holds the answer; otherwise the model borrows whatever is nearby.
  • Permission to decline, agreement across several samples, checking quotes against the source and counting wrong answers separately each catch more of what’s left.

Keep going

Sign in to save your place and keep a learning streak. Free, with Google.