Engineering Guide

How to Reduce LLM Hallucinations: A Builder's Playbook

Hallucination is not a bug you patch — it is a statistical property of how language models are trained, and 2025 research proved it is inevitable in the general case. That reframes the job. You do not eliminate hallucination; you engineer around it with grounding, verification, calibrated abstention, and model choice. This playbook maps each technique to the failure mode it actually fixes, shows the math behind why models guess, and treats model selection as a routing problem a gateway is built to solve.

Reduce LLM hallucinations — a builder pipeline mapping each technique to the failure mode it fixes

Why hallucination is statistically inevitable

Most guides open with a list of fixes. Start instead with the uncomfortable result: in the general case you cannot make a language model stop hallucinating. OpenAI's September 2025 paper Why Language Models Hallucinate (Kalai, Nachum, Vempala, Zhang) frames hallucinations as natural statistical errors, not glitches. Two of its arguments matter for anyone shipping on top of an LLM.

First, generating valid text is harder than judging it. The paper argues the generative error rate is at least about twice the Is-It-Valid binary-misclassification rate — deciding whether a given sentence is valid is a strictly easier problem than producing valid sentences, so even a model that could grade answers well will still generate some wrong ones. Second, for facts that appear exactly once in training data — the paper calls them singletons — the hallucination rate should be at least the singleton rate, the fraction of facts seen only once. If a quarter of the birthdays in your domain were seen a single time, expect a model to miss at least a quarter of them from memory alone. These are theoretical lower bounds under stated assumptions, not universal empirical laws, but they set the ceiling on what prompting can buy you: for rare, arbitrary facts, parametric memory is structurally unreliable.

How this is sourced. The statistical argument is from arXiv 2509.04664 (OpenAI, Sept 2025). Technique guidance draws on Anthropic's Reduce hallucinations guide, the Chain-of-Verification paper (arXiv 2309.11495), and provider structured-output docs. Model and price details are as of July 2026 and are illustrative snapshots — factuality leaderboards move monthly.

Reframe: engineer for calibrated abstention

The second half of the paper explains why models got worse at admitting ignorance: benchmarks reward guessing. Under binary 0-1 scoring, saying I don't know always earns zero, while a guess has a positive expected score. So the score-maximizing behavior is to bluff, and post-training on those benchmarks — MMLU-Pro, GPQA, SWE-bench and their kin all use binary accuracy — teaches exactly that. A confident wrong answer beats an honest abstention on the scoreboard.

OpenAI's proposed fix is not a new hallucination-only benchmark but a change to existing ones: put an explicit confidence threshold in the instructions. For example, answer only if you are more than t confident, since mistakes are penalized t/(1-t) points. That penalty grows fast, which is the whole point — it makes bluffing expensive. The same instruction pattern works in your own prompts and evals:

Wrong-answer penalty by confidence threshold t/(1-t)Higher threshold = a wrong guess costs far more, so abstaining wins. Source: OpenAI 2025.t = 0.501xt = 0.753xt = 0.909x
Chart: DataLLM Lab — the penalty a wrong answer should carry at each confidence threshold, computed as t/(1-t) from OpenAI's 2025 scoring proposal. At t=0.9 a bluff costs nine times a correct answer's reward, so I don't know becomes the rational output.

So the goal is not zero hallucination — that is unreachable — but calibrated abstention: the model answers when it is likely right and declines when it is not. Anthropic's official guidance says the same thing in plain terms: explicitly give the model permission to say it doesn't know. That one line in a system prompt is the cheapest hallucination reduction available, and most apps still omit it.

The technique-vs-failure-mode table

Every popular fix targets a different failure. Grouping them by the error they actually remove — rather than listing them as interchangeable tips — is where most advice falls short. Here is the builder's decision table:

TechniqueFailure mode it fixesCostGuarantee
Grounding / RAGWrong recall of rare or fresh facts from memoryRetrieval infra + input tokensLargest error share, least effort
Citations (cite-or-retract)Unsupported claims presented as sourcedExtra output tokensEvery claim traces to a passage
Allow I don't knowBluffing on out-of-scope questions~free (one prompt line)Abstention becomes valid
Constrained decodingInvalid enums, missing keys, broken JSONNear-zero at inferenceFormat only, not truth
Chain-of-VerificationPlausible but false claims in a draft2-4x tokens + latencyCatches self-contradiction
Self-consistency / best-of-NUnstable answers that vary run to runN x tokensFlags uncertain outputs
Model choice / routingA model that is simply weak on your taskEval timeOnly as good as your eval

Read it top-down: grounding and citations do the heavy lifting, the free prompt lines catch the easy cases, verification loops clean up what is left, and model choice is the backstop. Notice constrained decoding sits apart — it is the only row whose guarantee is about shape, not substance. That distinction trips up a lot of teams, so it gets its own section below.

Test every model against one factuality eval

Grounding, citations, and constrained decoding behave differently on each model. With 300+ models on one OpenAI-compatible key, run the same eval across Claude, GPT-5.5, Gemini and more and keep whichever wins on your task.

Grounding and citations: the heavy lifters

Retrieval-Augmented Generation injects the relevant documents at inference time, so the model answers from retrieved text rather than fuzzy memory. Because the biggest error source is exactly that unreliable recall of rare facts, grounding plus abstention is widely described as removing the largest share of hallucinations for the least effort. If you are standing up retrieval, the model you put behind it matters — see best LLM for RAG for how grounding-heavy workloads reward different models than open-ended chat, and best LLM for summarization for the closely related grounded-generation case.

Grounding on its own still lets a model paraphrase loosely. Citations close that gap. Anthropic's Citations API, launched January 2025, chunks the source documents into sentences and has the model automatically cite the exact passages behind each claim. Anthropic reports one customer cut source hallucinations and formatting issues from 10% to 0% while seeing about a 20% increase in references per response — the model both stopped inventing sources and pointed to more real ones. The feature has since expanded well beyond the models named at launch, so treat it as broadly available, not limited to one version. Even without a dedicated citations feature, you can approximate it in the prompt: Anthropic's guide recommends, for long documents over ~20k tokens, having the model first extract word-for-word quotes and then answer only from those quotes, and afterward requiring a supporting quote for every claim and retracting any claim that lacks one.

Verification loops and format guards

When you cannot ground — closed-book reasoning, synthesis across many sources — verification loops catch errors after the fact. Chain-of-Verification (Dhuliawala et al., ACL 2024 Findings) runs a four-step loop: draft an answer, plan a set of verification questions about it, answer those questions independently, then produce a final corrected response. It measurably reduced hallucinations on Wikidata list questions, closed-book QA, and long-form generation. Self-consistency methods such as SelfCheckGPT take a different angle: sample several generations and treat disagreement between them as a factual-uncertainty signal — a black-box detector needing no external knowledge base. Both are established 2023-era techniques, still valid in principle, that trade extra tokens and latency for fewer false claims. A cheap model like DeepSeek V4 Flash makes a good verifier so you are not paying flagship rates on every check.

Now the caveat that section deserves. Constrained decoding — structured outputs — compiles a JSON Schema into a grammar (often a finite-state automaton) that restricts which tokens are valid at each step. OpenAI shipped it as response_format: json_schema in August 2024; Anthropic added constrained decoding for Claude around November 2025, caching compiled schemas for roughly a day. It guarantees the output always conforms to your schema — no invalid enum values, no missing required keys, no truncated or trailing-comma JSON. That removes an entire class of format-level hallucinations. But it says nothing about whether the field values are true. A schema-perfect object can still contain a wrong number. Some practitioners argue structured outputs breed false confidence for exactly this reason, so keep the boundary sharp: constrained decoding fixes shape, not substance. For the implementation details on Claude specifically, see Claude structured output, and for pushing labels reliably into a fixed set, best LLM for classification.

Model choice is a routing problem

Factuality varies sharply by model, which makes model choice a genuine lever — but not the way vendors frame it. OpenAI's SimpleQA measures short-form parametric recall; Google DeepMind's FACTS Grounding leaderboard measures long-form document grounding. The pattern across them is consistent: document-grounded scores sit far above short-form parametric-recall scores. FACTS-Grounding-style document QA lands in the mid-80s percent range while raw short-form recall is much lower. That gap is itself an argument for grounding over trusting any model's memory — and a caution that these numbers move monthly, so read them as dated snapshots, not standings.

The operational mistake is betting the whole app on one model because it topped a leaderboard last quarter. When xAI launched Opus-class rival Grok 4.5 on July 8, 2026 (around $2/M input, $6/M output) with Musk calling it maximally truth-seeking, that phrase was marketing, not an independent factuality result — do not wire it into a pipeline on the strength of a slogan. The durable move is to treat model choice as routing: run the same factuality eval across several models through a gateway and keep whichever wins on your task. Compare Claude Opus 4.8 with citations against GPT-5.5 with structured outputs against Gemini's grounding, A/B them on your own labeled set, and let the winner serve production while a cheaper model handles verification. A gateway is what makes that a config change instead of a rewrite — the same pattern behind LLM routing and failover. You are no longer asking which model hallucinates least in the abstract; you are measuring which one hallucinates least on your data, and switching freely as the leaderboards churn.

FAQ

Can you fully stop an LLM from hallucinating?

No. OpenAI's 2025 paper shows that for facts seen once in training, the hallucination rate is at least the singleton rate — zero is unreachable in the general case. You drive it down with grounding, citations, verification, and letting the model say I don't know.

Why do benchmarks make hallucination worse?

Binary 0-1 scoring gives abstention a zero while a guess has positive expected value, so post-training rewards confident bluffing. The fix is a confidence threshold in the eval that penalizes wrong answers, making I don't know a scored, valid response.

What is the single most effective fix?

Grounding plus abstention. Feed the model the source documents (RAG) and instruct it to answer only from them and to decline when they do not cover the question. It removes the largest error share for the least effort.

Does structured output reduce hallucination?

Only format-level hallucination. Constrained decoding guarantees schema-conforming JSON — no invalid enums, missing keys, or broken syntax — but the values inside a valid schema can still be factually wrong. Treat it as a shape guarantee, not a truth guarantee.

How do verification loops work?

Chain-of-Verification drafts, plans verification questions, answers them independently, then rewrites a corrected answer. Self-consistency samples several generations and flags disagreement as uncertainty. Both cost extra tokens for fewer false claims, with no external knowledge base needed.

Does the choice of model matter?

Yes — factuality varies sharply by model. Rather than betting on one, route the same factuality eval across several through a gateway and keep the winner on your task. Document-grounded scores beat parametric-recall scores, which argues for grounding over trusting memory.

Written by
Kevin Fan

Founder of DataLLM Lab, the unified LLM gateway. Kevin tests models the boring way — same prompts, real costs, unedited outputs — and writes up what the runs actually show.

One API for every model

One API, every model.

Get a single API key for Claude Opus 4.7, GPT-5.4, and 300+ more — with automatic price comparison and routing to the best model for every request.