Software Engineeringunpacked

LLM hallucination: why it happens and seven ways to reduce it with Claude

An LLM hallucination is an answer that sounds right but is false or not supported by the context it was given. You can't remove it entirely, but you can make it rare and catchable: give Claude permission to say it doesn't know, ground answers in quotes from your documents, make it cite and retract unsupported claims, restrict it to the sources you provide, and check the facts that matter in code.

What is an LLM hallucination?

Anthropic's docs describe it as text "that is factually incorrect or inconsistent with the given context". The danger isn't that the model is sometimes wrong; it is that a wrong answer reads exactly like a right one. A support agent that invents a refund policy, an extraction job that fills a missing date, a summary that quotes a sentence the document never said: all look confident.

Why hallucinations happen

A language model predicts likely text. When the context doesn't contain the answer, the most likely continuation is still a fluent answer, not "I don't know", unless you make that an acceptable outcome. Three situations make it worse: the information is missing from the context, the prompt or schema demands an answer anyway, and the relevant fact is buried in a long context where it is easy to miss.

Seven ways to reduce hallucinations with Claude

The first three are the docs' basic strategies; the rest are their advanced techniques.

  1. Allow "I don't know". Explicitly permit uncertainty: "If the documents don't say, answer: not stated." The docs say this simple step "can drastically reduce false information."
  2. Quote first, then answer. For long documents (over about 20k tokens), ask for word-for-word quotes relevant to the question first, then the answer based only on those quotes. If no quote exists, the answer is that none was found.
  3. Verify with citations. Have Claude attach a supporting quote to each claim, then check every claim and remove any it can't support. That makes the answer auditable.
  4. Restrict to your sources. Tell Claude to use only the provided documents, not its general knowledge, when that is what the task needs.
  5. Best-of-N. Run the same prompt several times and compare. Answers that disagree point to the claims to double-check.
  6. Iterative refinement. Feed the answer back and ask Claude to verify or expand specific statements.
  7. Read the reasoning. With thinking enabled and summarized, review the reasoning when an answer looks wrong to find the faulty assumption.

A grounded prompt, step by step

```xml {{RENTAL_TERMS}}

A customer asks: "Do I get my deposit back if I return the e-bike two hours late?"

  1. Quote, word for word, every sentence of the policy about late returns or deposits. If there is none, write "No relevant quote found."
  2. Answer using only those quotes. If they don't settle the question, say that a person will confirm, and hand the case off. ```

The quotes step forces Claude to look before it speaks, and the fallback gives it an honest exit instead of a guess.

Hallucinations in structured output

Schemas guarantee shape, not truth. If a field is required, the model must fill it, even when the email never mentioned the value. Make such fields nullable, add examples of documents where a value is really missing, and validate meaning in code: does the booking exist, do the amounts add up. More in Claude structured output and few-shot prompting.

Hallucinations in agents

In an agent, the worst hallucinations come from tools that fail quietly. If a lookup times out and returns an empty result, Claude believes "no booking found" and builds on it. Return the failure as a failure (an error in the tool_result, saying what was tried) so the agent can retry or hand the case to a person; see LLM tool calling.

What these techniques can't do

The docs are explicit: they "significantly reduce hallucinations, they don't eliminate them entirely." For high-stakes facts (money, safety, legal terms), keep a check outside the model: code that validates, or a person who approves.

Hallucinations on the Claude Certified Architect exam

The CCAR-F exam touches this in Domain 4 (few-shot examples that reduce hallucination in extraction, nullable schema fields, validation and retry) and Domain 5 (preserving provenance, handling uncertainty, and when to escalate). The usual trap: answering "add 'don't make things up' to the prompt" when the fix is structural, such as a nullable field, a quote-first step or a check in code.

More in all articles.

Sources: Reduce hallucinations; Structured outputs; Prompting best practices; Claude Certified Architect Foundations exam guide v1.0, domains 4 and 5.

FAQ

What is an LLM hallucination?

Text that is factually incorrect or inconsistent with the given context, produced with the same confidence as a correct answer. Anthropic's docs call it a phenomenon that can undermine the reliability of AI solutions.

How do you reduce hallucinations in Claude?

Allow it to say I don't know, ask for word-for-word quotes before the analysis on long documents, have it cite a quote for every claim and retract what it can't support, restrict it to provided documents, and compare several runs or verify with follow-up prompts.

Do these techniques eliminate hallucinations?

No. The docs say they significantly reduce hallucinations but don't eliminate them. Critical facts still need validation, ideally in code or by a person.

Why does a JSON schema sometimes cause made-up values?

A required field forces an answer even when the source has none. Making fields nullable when the information may be missing lets Claude say not stated instead of inventing a value.