News / Learn / Evaluation & safety
Why do models hallucinate and how do you reduce it?
You'll be able to explain why models make up facts and apply two practical ways to reduce it in your product.
In plain English
A language model predicts the next word that fits the text so far. It does not look up facts in a database. When it lacks the answer, it can still produce a fluent, confident sentence that is wrong. That wrong output is called a hallucination.
Why it matters
Users trust fluent text, so a confident wrong answer can break trust or cause real harm. If you build with AI, you need to design for this failure, not hope it goes away. Knowing the cause tells you which fixes will help.
How it works
A model is trained to continue text in a way that looks like the data it saw. Its training data is large but incomplete, and it compresses that data into patterns. When a question falls outside those patterns, the model still has to output something, so it generates the most plausible-sounding answer.
The model also has no built-in sense of whether it knows something. It does not check its answer against a source as it writes. Each token follows from the tokens before it, so one early mistake can carry into the rest of the answer.
Two main levers reduce hallucination. The first is grounding: you give the model the source text in the prompt and tell it to answer only from that text. This is the basis of retrieval-augmented generation (RAG). The second is permission to abstain: you tell the model that saying it does not know is acceptable, and you check that it does so. Lower temperature can make outputs more consistent, but it does not make facts more accurate.
Neither lever is perfect. Grounded answers can still misread the source, and abstention can be too cautious. You need an eval set to measure how often hallucinations happen, and you should recheck after each change to the prompt or model.
A concrete example
A grounded prompt that tells the model to answer only from supplied text and to say when the answer is missing.
def build_prompt(question: str, source_text: str) -> str:
return (
"Answer the question using only the source text below.\n"
"If the answer is not in the source text, reply exactly: "
"'I don't know based on the provided text.'\n"
"Quote the sentence you used.\n\n"
f"Source text:\n{source_text}\n\n"
f"Question: {question}"
)A short sketch to show the idea. Check the official docs of the tool you use.
What goes wrong
- Assuming a fluent answer is a correct answer Check outputs against a source or a labeled test set. Fluency tells you nothing about accuracy.
- Thinking low temperature removes hallucinations Lower temperature makes outputs more repeatable. A repeatable wrong answer is still wrong. Measure accuracy directly.
- Giving no way to say 'I don't know' Add an explicit abstain instruction and test that the model uses it when the source lacks the answer.
- Testing only on easy questions Include questions where the answer is missing or tricky in your eval set, since those are where hallucinations appear.
Going deeper
Learn how to build an eval set that includes unanswerable questions, and how to score groundedness, meaning whether each claim is supported by the source.
FAQ
Can hallucinations be eliminated completely?
Not with current methods. You can reduce them and detect many of them, but you should design your product so a wrong answer is survivable, such as showing sources so users can verify.
Does a bigger model stop hallucinating?
Model size can change error rates, but it does not remove the underlying behavior. Always measure your own task rather than assuming a larger model is safe.
Is RAG the same as preventing hallucinations?
No. RAG gives the model relevant source text, which helps. The model can still misread or ignore that text, so you still need checks.
Why does the model sound so sure when it is wrong?
Its training rewards fluent continuation, not calibrated confidence. Output style does not reflect whether a fact is true.
Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.