AGI

How to Reduce LLM Hallucinations in Production

Introduction

Teams searching for how to reduce LLM hallucinations in production usually arrive after a chatbot has already told a customer something false. The scale of the problem is real, because public models are reported to hallucinate 3% to 16% of the time, and live traffic often looks worse than benchmarks. A single invented refund policy, fake court citation, or imaginary product feature can cost far more than the engineering hours needed to prevent it. Fortunately, hallucination is not a mysterious defect that only a new model release can cure. It is an engineering and measurement problem that responds to retrieval, constrained prompts, verification layers, and disciplined monitoring. This guide walks through each control in the order a production team would apply it, with code, benchmarks, and real incidents. By the end, you will have a layered plan, a way to measure progress, and a clear sense of where the remaining risk lives.

Quick Answers on How to Reduce LLM Hallucinations in Production

What is the fastest way to reduce LLM hallucinations in production?

Ground every answer in retrieved documents, tell the model to abstain without evidence, and verify claims before display. Layering these controls reduces LLM hallucinations in production more than any single prompt tweak.

Does retrieval-augmented generation eliminate hallucinations?

No. Stanford researchers found purpose-built legal tools using retrieval still produced hallucinations about 17 percent of the time, so retrieval needs verification and monitoring behind it.

How do you measure an LLM hallucination rate?

Split each LLM answer into atomic claims, check every claim against the retrieved context, and report supported claims divided by total claims on a sampled slice of live traffic.

Key Takeaways

  • Hallucinations come from training and evaluation incentives that reward confident guessing, so production systems must add the missing incentives for honesty themselves.
  • Retrieval grounding, constrained prompts, structured outputs, and claim-level verification each remove a different failure mode, and they work best stacked together.
  • You cannot improve what you do not measure, so build a golden question set and sample live traffic for faithfulness scoring from the first week.
  • Legal and reputational liability stays with the deploying company, which makes abstention paths and human escalation part of the product rather than an afterthought.

Understanding How to Reduce LLM Hallucinations in Production

How to reduce LLM hallucinations in production means layering retrieval grounding, constrained prompts, claim-level verification, abstention rules, and monitoring so a deployed model’s unsupported statements are caught, measured, and minimized before users see them.

An Interactive From AIplusInfo

How Many Wrong Answers Will Your Assistant Ship?

Set your monthly volume, your baseline hallucination rate, and a mitigation stack to see how many false answers reach customers.

Retrieval and verifier

Wrong answers per month, no controls

4,000

Wrong answers per month, with stack

450

Reduction versus no controls

89%

Planning model, not a measurement. Baseline rates in public reports run from 3% to 16%, and the verifier step assumes it blocks 75% of hallucinated responses. Residual shares for the other stacks (75%, 45%, and 5.6% for the full stack) are illustrative assumptions you should replace with your own golden-set results.


Why Language Models Invent Facts in the First Place

A language model is trained to predict the next token, which means it optimizes for fluent and plausible text rather than for verified truth. When the training data contains a fact many times, the model usually reproduces it correctly. When the fact is rare, ambiguous, or missing, the model still produces a confident-sounding answer, because silence is not something it was ever rewarded for emitting. This gap explains why hallucinations cluster around obscure names, recent events, precise figures, and citations to specific documents. Compression plays a role too, since billions of facts are squeezed into a fixed set of weights that blur at the edges. The result is a system that sounds equally sure whether it is right or wrong.

Researchers at OpenAI argued in Why Language Models Hallucinate that standard training and evaluation reward guessing over admitting uncertainty. Their SimpleQA comparison makes the point concrete, because one model abstained on 52 percent of questions and erred on 26 percent. An older model abstained on just 1 percent of questions and erred on 75 percent, even though it was slightly more accurate at 24 percent against 22 percent. A leaderboard that only counts accuracy will therefore prefer the model that guesses more, even when guessing is exactly what a business cannot afford. Every team that deploys such a model inherits that incentive unless it deliberately counteracts it. The same logic applies inside your own evaluation suite, which is why scoring rules matter as much as model choice.

The practical lesson is that hallucination behavior can be shifted by changing what the system rewards, even when the underlying weights stay fixed. Retrieval changes what evidence sits in front of the model, prompts change what it is allowed to say, and verifiers change what survives to the user. Newer models also appear to be getting better at some tasks while becoming riskier in others, so a model upgrade alone is never a safe plan. Treat the base model as an unreliable narrator and design the surrounding system to compensate for it. That mindset keeps engineering effort focused on controls you own rather than on release notes you do not.

The Hallucination Patterns That Hurt Production Systems Most

Practitioners usually sort hallucinations into three broad and useful families. Fact-conflicting statements contradict the real world, input-conflicting statements contradict the user’s request, and context-conflicting statements contradict the model’s own earlier output. The first family dominates open-ended question answering, while the second and third dominate summarization, extraction, and long multi-turn conversations. Knowing which family you face determines the fix, because retrieval helps most with the first, instruction hygiene helps with the second, and memory management helps with the third. Teams that skip this triage often buy a vector database to solve what is really a prompt problem.

In production the most expensive patterns are rarely exotic or hard to imagine. Invented policies and prices, fabricated citations, and wrong numbers inside correct summaries cause many incidents. Agents that call tools with parameters nobody supplied account for much of the rest that reaches legal or executive review. The common thread is that each of these errors looks perfectly professional, which is why users rarely catch them without a second source. Detection research such as these LLM hallucination detection techniques shows that surface fluency is a poor signal of correctness. Your controls must therefore check substance rather than style, and they must do so automatically on every response that carries risk.

Measuring Hallucination Rates Before Trying to Fix Them

Building on that taxonomy, the first engineering task is to turn a vague worry into a number you can track every week. Start with a golden set of roughly two hundred real user questions, each paired with the approved source passage and a short reference answer written by a subject expert. Include adversarial cases on purpose, such as questions whose answers are absent from your documents and questions built on false premises. Add a few prompts that tempt the model to quote a policy that does not exist, since those mirror the incidents that make headlines. A golden set containing only easy questions will report a flattering score that collapses on launch day. Version the set in source control so every score can be traced to the exact questions that produced it.

Next, you need to define the metric you will report to stakeholders. The most useful production metric is faithfulness, computed by splitting an answer into atomic claims and checking each claim against the retrieved context. As Langfuse explains, the score equals supported claims divided by total claims. A value of 1.0 means every statement traces to evidence, and 0.5 means half of it is unsupported. Binary per-claim decisions are far more stable than holistic one-to-five ratings, which drift between runs and hide exactly which statement failed. The same guidance recommends excluding hedges and explicit “I don’t know” statements from the claim list so that honest abstention is never punished. Reporting the unsupported claims themselves, not just the ratio, gives engineers something concrete to fix.

Metrics only matter if they reflect reality, so calibrate your automated judge against people. Have a domain expert label twenty to fifty answers, compare those labels with the judge’s verdicts, and fix the rubric wording before blaming the judge model. Rubric ambiguity, more than model choice, is the usual cause of poor agreement between a judge and a human reviewer. Once the judge is trusted, you can run it in continuous integration on the golden set and fail a deployment whenever faithfulness regresses. Recalibrate every quarter or whenever the document set changes materially, because a stale rubric quietly drifts away from what reviewers actually consider wrong.

Finally, separate retrieval failures from generation failures, because they demand different repairs. If the supporting passage never reached the model, the retriever or the chunking is at fault, and prompt tweaks will not help. If the passage was present and the model still contradicted it, you have a generation problem that points toward better instructions, structured outputs, or a verification gate. Logging the retrieved passages beside every answer makes this diagnosis a five-minute task rather than a week of guessing. Over time the split between the two failure types also tells you where the next engineering dollar should go. A rising retrieval share argues for better indexing, while a rising generation share argues for stronger constraints.

Grounding Answers With Retrieval That Earns Its Keep

Shifting from measurement to mitigation, retrieval-augmented generation is the highest-leverage control because it changes the evidence the model sees. Instead of asking the model to remember a fact, you fetch the relevant passage from a vetted knowledge base and instruct the model to answer only from it. This works because summarizing a supplied passage is a much easier task than recalling an obscure fact from compressed training data. The trade-off is that your answers are now only as good as your documents and your search. Many teams therefore compare retrieval against fine-tuning before committing to either path. Whichever you pick, budget for ongoing document curation, because stale sources are just another route to confident error.

Retrieval quality is where most of the production engineering effort belongs. Chunk documents along natural boundaries such as headings and clauses, and attach metadata like document version and effective date to every chunk. Combine keyword search with embedding search so that exact identifiers, such as product codes and policy numbers, are not lost in semantic blur. Tune the similarity threshold so that weak matches return nothing rather than something misleading, because a confidently wrong passage is more dangerous than an empty result. An empty retrieval should trigger an abstention path, not a creative guess. Teams that want a working reference can follow this step-by-step RAG chatbot build and then adapt each piece to their own stack.

Always require the model to cite the passage identifiers it used, and then verify in code that each cited identifier was actually retrieved. A citation that points to a document the system never fetched is a reliable sign of fabrication. Stanford researchers noted that a citation can exist and still be irrelevant or contradictory, so citation presence alone is not proof of grounding. Add a second check that the quoted text really appears inside the cited passage, using simple string matching or a fuzzy comparison. Treat citations as an index into your own evidence store that software can verify, not as decoration for the reader. This small habit catches a surprising share of errors before any expensive judge model runs.

Prompt Design That Narrows the Room for Invention

Beyond retrieval, the prompt is the cheapest lever you have, and it is also the one most often written carelessly. A strong production prompt states the role, supplies the evidence, lists what the model must not do, and defines the exact fallback sentence to use when evidence is missing. Tell the model explicitly that it may answer only from the provided passages and that unsupported questions must receive the fallback. Without such an instruction, the model fills every gap with its best guess, because helpfulness is its default posture. Keep the instruction short and unambiguous, since long lists of competing rules tend to be followed unevenly. Place the evidence close to the question so the model does not have to hunt for it.

Low sampling temperature, a small number of refusal examples, and a requirement to quote the supporting sentence before answering all reduce drift. Showing the model two or three examples of correct abstention teaches the behavior more reliably than a paragraph of abstract rules. Practitioners also report that structured reasoning helps on multi-step questions, though it costs extra tokens and should be reserved for the queries that need it. Test every prompt change against the golden set instead of trusting intuition, because small wording edits can move faithfulness in either direction. As your prompts grow, treat the whole context window as a managed resource, since context engineering for LLM agents shows how stale or bloated context quietly degrades answer quality.

Structured Outputs and Constrained Responses

Moving from free text to structure removes whole categories of invention before they can occur. When the model must return a JSON object whose fields are enumerated values, bounded numbers, and passage identifiers, it has far less room to improvise. A schema that says the category must be one of five allowed strings makes a sixth, invented category impossible to emit. Most major providers now support schema-constrained decoding, and many client libraries add automatic retries when validation fails. The result is output your software can trust structurally, even when you cannot yet trust every word of it. Constrained fields also make downstream logging and analytics far easier than parsing paragraphs.

Design the schema so that it carries its own evidence for every answer. Include a field for the supporting quote and a field for the passage identifier. Add an explicit boolean such as answerable that the model sets to false when the context lacks the answer. Your application can then branch on that boolean instead of scanning prose for hedging language. A schema with an answerable flag turns abstention from a vague tone into a typed value your code can route. The same discipline applies to agents, where function calling in LLMs with strict parameter schemas stops the model from inventing arguments that the user never supplied. Validate every tool call against the schema before executing it, and reject calls that reference identifiers the system has never seen.

Verification Layers: Claim Checking and Model Judges

Stepping back from generation, the next control inspects the finished answer before any user sees it. A verification layer extracts the factual claims from the draft, compares each claim with the retrieved evidence, and either approves the answer or sends it back for repair. This design accepts that the generator will sometimes be wrong and builds a second opinion into the request path. It also gives you a natural place to record why an answer was rejected, which feeds your monitoring later. The cost is extra latency and tokens, so most teams apply the full check only to responses that carry real risk.

Managed cloud services now package this verification idea as a feature. Amazon’s contextual grounding check scores whether a response is supported by the reference source and whether it addresses the user’s query, then blocks responses that fall below configurable thresholds. AWS reported that the feature filters over 75 percent of hallucinated responses for retrieval and summarization workloads. Its documentation uses example thresholds of 0.85 for grounding and 0.5 for relevance, and higher thresholds block more responses. Treat those numbers as starting points and tune them against your own golden set, because the right balance between blocked answers and missed errors depends on your tolerance for each. Open-source alternatives follow the same pattern if you prefer to host the verifier yourself.

Whichever verifier you choose, the judge model itself still needs real discipline. Use a model at least as capable as the generator, set the temperature to zero, require structured output, and forbid the judge from using outside knowledge. Langfuse warns that judges tend to mark true statements as supported even when the context never mentioned them. That behavior leaks world knowledge into a check that is meant to test grounding. A detailed walkthrough of evaluating outputs with an LLM judge covers rubric design and bias mitigation. Re-check the judge against human labels whenever you change its prompt or its model.

Guardrails, Abstention, and Graceful Refusals

Looking at the decision layer, every score from your verifier must map to an action that the application can execute without improvising. A sensible policy passes high-scoring answers, regenerates borderline ones once with a stricter prompt, and routes low-scoring ones to a fallback message or a human queue. Writing these rules as plain deterministic code, as described in these deterministic guardrails for AI agents, keeps the most important decisions auditable and testable. A model should never decide by itself whether its own answer is safe to show. Keep the thresholds in configuration so product owners can adjust them without a code release.

Abstention deserves real design attention, because a bad refusal is almost as damaging as a bad answer. Tell users plainly what could not be answered, offer the next step such as a link or a handoff to a person, and avoid apologetic filler that wastes their time. Count a correct refusal as a success in your metrics, because a system punished for saying it does not know will learn to guess. OpenAI’s analysis makes the same point about public benchmarks, recommending that confident errors be penalized more heavily than expressions of uncertainty. Your internal dashboards should follow that advice so that engineers are not quietly incentivized to hide abstentions.

Choosing Between Fine-Tuning, Retrieval, and Larger Models

Given the many options on the table, it helps to be clear about what each lever actually changes. Fine-tuning is excellent for teaching tone, format, and domain vocabulary, and it can include examples where the model correctly says it does not know. It is a poor way to inject a large body of changing facts, because the knowledge is baked into weights that you cannot easily edit or audit. Every policy update would require another training run and another round of evaluation. For fast-moving facts, retrieval is usually cheaper, fresher, and far easier to explain to an auditor.

Larger or newer models can lower hallucination rates, but the gains are uneven and the bills are real. Public leaderboards show wide spreads between models on the same summarization task. A review of AI models with minimal hallucination rates can therefore save weeks of trial and error. Do not assume the biggest model is the safest, because some reasoning-heavy models invent more details when asked for long answers. Run every candidate model through your own golden set, since leaderboard rankings rarely match your documents, your prompts, or your users. Record cost per thousand answers alongside faithfulness so the trade-off is visible to finance as well as to engineering.

The strongest production systems combine the levers instead of choosing one. A common pattern uses retrieval for facts, light fine-tuning for format and refusal behavior, and a mid-sized model with a verifier on top. When questions require connecting facts across many documents, structured approaches such as GraphRAG compared with traditional RAG can improve multi-hop answers at the price of more indexing work. Whichever combination you pick, change one variable at a time and rerun the golden set. That discipline tells you which investment actually moved the number.

Monitoring Hallucinations After Launch

Moving on to life after launch, the golden set stops being enough the moment real users arrive with questions you never imagined. Production monitoring means scoring a sample of live answers, tracking the trend, and alerting when quality slips. Langfuse notes that sampling five to ten percent of traffic is typically enough to see a trend, which keeps judge costs manageable. Sample more heavily on high-risk intents such as pricing, eligibility, medical, legal, and compliance questions. Store the question, the retrieved passages, the answer, and the score together so any alert can be investigated in minutes.

Set alerts on the metrics that matter rather than on raw volume. A drop in average faithfulness, a rise in the share of unsupported claims, or a jump in abstention rate each point to a different problem. A sudden spike in abstentions might mean a document feed broke, while a sudden spike in unsupported claims might mean a prompt or model change slipped through. Trend lines reveal regressions that no single sampled answer ever will. Dashboards should show the five lowest-scoring answers from the last day so engineers can read real failures instead of staring at aggregates. Review them in a short daily ritual until the numbers settle.

Feedback from users and support staff is the second monitoring channel, and it catches errors the judge misses. Add a simple thumbs-down control with an optional comment, and route every report into a labeling queue rather than a bug tracker nobody reads. Support agents often notice recurring false statements long before an automated metric does, so give them a one-click way to flag an answer. Each confirmed error becomes a new golden-set row, which means the test suite grows from real incidents. After a few months the set reflects your actual failure landscape rather than your initial guesses.

Finally, you should watch closely for change events that silently alter behavior. Provider model updates, new document batches, embedding model swaps, and prompt edits can each shift hallucination rates overnight. Pin model versions where the provider allows it, and rerun the golden set automatically whenever any input to the system changes. For teams running agents, the walkthrough on evaluating Bedrock agents with Ragas shows how to score multi-step behavior and not just final text. Treat a quality regression the way you would treat a failed deployment, with a rollback path ready.

Human Review and Escalation Paths

Beyond automated checks, some answers should never ship without a person, and deciding which ones is a product decision as much as an engineering one. Create risk tiers so that low-risk answers such as store hours flow straight to users. Medium-risk answers receive automated verification, and high-risk answers such as refunds, medical guidance, or legal interpretation require human approval or a pre-approved template. Map each intent in your product to a tier and document the reasoning. This keeps reviewers focused on the cases where their judgment matters most. It also gives auditors a clear picture of where automation stops.

Human review works best when it feeds the system, not just the customer. Give reviewers a compact interface that shows the question, the retrieved passages, the draft answer, and the verifier’s unsupported claims side by side. Their corrections should flow into the golden set and, where appropriate, into new refusal examples for the prompt. Research on human in the loop accuracy shows that expert input improves outcomes most when it is captured systematically. A reviewer who fixes the same error ten times without the system learning from it signals a broken feedback loop, not a staffing shortage.

Where Hallucination Controls Fall Short and Which Risks Remain

Despite the layers described so far, no combination of controls reaches zero, and pretending otherwise is a risk in itself. Stanford researchers who tested purpose-built legal research tools found that they still hallucinated about 17 percent of the time even though those products used retrieval. The study examined more than 200 open-ended legal queries, including some built on a mistaken understanding of the law. The vendor disputed the figures and said its own data showed a much lower rate. That disagreement is itself instructive, because it shows how measurement choices change the headline number.

Verification layers also carry their own limits that teams should understand. Judge models can approve a claim because it is true in the real world rather than because the context supports it. They can also miss subtle errors such as a wrong date or a swapped unit. Aggressive thresholds shift the problem from hallucination to over-refusal, which frustrates users and pushes them toward less careful tools. Each extra check adds latency and cost, and a slow assistant that users abandon protects nobody. Calibrating these trade-offs is continuous work rather than a one-time setting.

Long and messy inputs create yet another weakness in these systems. As conversations and retrieved contexts grow, models lose track of details in the middle, a behavior described in this explainer on context rot in large language models. Adversarial users can also craft prompts that coax the model into ignoring its instructions or retrieval evidence. Both problems argue for short, well-curated contexts, input sanitization, and regular red-team exercises. Accept a nonzero residual error rate, measure it honestly, and design the product so that the consequence of the remaining errors is bounded.

Ethics, Liability, and Honest Disclosure

Stepping back from engineering, the ethical baseline is simple: a company is responsible for what its automated systems tell people. Courts and tribunals have started to reject the idea that a chatbot is a separate entity whose mistakes belong to nobody. Customers cannot be expected to know which part of a website is accurate and which part is a generative guess. If your system speaks in your voice, you own its statements, which makes accuracy controls an obligation rather than a nice-to-have. Legal teams should review the intents where a wrong answer creates contractual or regulatory exposure.

Honest disclosure is therefore the companion principle to that basic accountability. Tell users when they are talking to an automated assistant, show the sources behind important answers, and make it easy to reach a person. Keep records of prompts, retrieved passages, and verifier scores so you can reconstruct what happened when a complaint arrives. Broader programs such as responsible AI governance frameworks place these practices inside a structure of accountability, review boards, and escalation. Transparency does not eliminate errors, but it changes how users calibrate their trust and how regulators judge your diligence.

Putting Hallucination Controls Into Practice Across a Real Stack

Turning to implementation, a typical request path has six stages that map neatly onto the controls above. The application classifies the intent and risk tier, retrieves evidence, builds the grounded prompt, calls the model with a schema, verifies the draft, and then either responds or escalates. Each stage writes a structured log entry so the full story of any answer can be replayed later. Keeping the stages modular lets you swap a retriever or a verifier without rewriting the rest. It also lets different teams own different pieces without stepping on one another.

Latency and cost budgets decide how much verification you can afford. Routine low-risk intents can skip the judge or use a small, fast model, while high-risk intents get the full claim-level check and possibly a second retrieval pass. Routing by risk tier keeps average cost low while concentrating scrutiny where a wrong answer is expensive. Cache retrieval results and verifier verdicts for repeated questions, but expire them whenever the underlying documents change. Measure the added latency at the ninety-fifth percentile, because users feel the slow tail more than the average.

You should roll out in stages rather than flipping a single switch. Begin in shadow mode, where the verifier scores answers silently, then enable blocking for a small percentage of traffic, then expand once the golden set and live metrics agree. Keep a kill switch that disables generation for a risky intent and falls back to static content within seconds. Write a short runbook that explains who is paged, how to roll back a model or document change, and how to communicate with affected users. Rehearse the runbook once before launch, because an untested rollback plan is a hope rather than a plan.

The Future of Reliable Language Model Systems

Looking ahead, the most promising shift is in how the field scores models, because incentives shape behavior. If major benchmarks start rewarding calibrated uncertainty and penalizing confident errors, as OpenAI has urged, model developers will have reasons to build systems that abstain more gracefully. Their analysis suggests that today’s accuracy-only scoreboards are a root cause of the guessing habit. Expect abstention rate and error rate to appear beside accuracy on more leaderboards, and expect buyers to ask for them in procurement. When the scoreboard changes, product teams will find the right behavior easier to buy.

Platform vendors are also moving grounding directly into the shared infrastructure. Citations, source attribution, and groundedness scores are becoming standard response fields rather than custom engineering projects, and hosted guardrails make verification a configuration choice. Public leaderboards that track hallucination in summarization let buyers compare models on a common task and watch the trend over time. Smaller, specialized models paired with strong retrieval may deliver better reliability per dollar than general-purpose giants for many enterprise workloads. These developments lower the cost of doing the right thing.

Even so, accountability for the final answer will stay with people. Regulators are asking for documentation, testing evidence, and human oversight, and customers will keep expecting accurate answers whether or not the vendor labels a feature as experimental. The durable advantage will belong to teams that treat reliability as a measured, owned, and continuously improved property of the whole system. Models will keep improving, but the habits described here, from golden sets to risk tiers, will stay useful because they address the structure of the problem. Build the measurement muscle now and every future model becomes easier to adopt safely.

Chart From AIplusInfo

Hallucination Rates Vary Tenfold Across Models and Tasks

Reported rate of unsupported or wrong output, percent. Chart type selected: horizontal bar, because the data compares categories at a point in time.


Source: Vectara HHEM leaderboard, Helicone, and Stanford HAI via LegalDive.


How to Reduce LLM Hallucinations in Production: A Seven-Step Build

Putting the earlier ideas together, the following seven steps form a minimal but complete build that a small team can ship within a few weeks. Each step is deliberately small, testable on its own, and tied to the golden set from the first step so progress is always measurable. The code samples use Python and plain JSON so you can adapt them to any framework or provider. Replace the placeholder functions for embedding and model calls with your own client libraries. Run the golden set after every step and write down the faithfulness score before and after. By the end you will have a retrieval layer, a grounded prompt, a typed output, a verifier, a gate, and a monitor.

Step 1 – Define the failure and build a golden set

Begin by writing down the 3 or 4 wrong answers that would hurt your business most, such as an invented refund rule or a fabricated clause. For each one, collect real user phrasings from logs, support tickets, or interviews. Pair every question with the approved source passage and a short reference answer, and mark whether the correct behavior is to answer or to abstain. Aim for about 200 rows, and make at least a quarter of them unanswerable from your documents so abstention gets tested. Write the reference answers in plain language that a reviewer can compare quickly.

Store the set as one JSON object per line so it diffs cleanly in version control. Give every row an identifier, a risk tier, and the expected route. Have a second person review twenty rows to catch ambiguous questions or wrong references. Tag each row with the product area it belongs to so you can slice scores later. Pro tip: write the unanswerable questions first, because they are the cases teams most often forget and the ones that generate the worst incidents.

{"id": "q-014", "question": "Can I get a bereavement refund after my trip?", "tier": "high", "expected": "answer", "passage_id": "refund-policy-v7", "reference": "Bereavement fares must be requested before travel."}
{"id": "q-077", "question": "Does the premium plan include free international shipping?", "tier": "medium", "expected": "abstain", "passage_id": null, "reference": null}

Step 2 – Index trusted documents for retrieval

Gather the documents that your assistant is allowed to rely on and remove anything outdated, duplicated, or unapproved. Split each document along headings and clauses into chunks of 200 to 400 words, and attach the document identifier, version, and effective date as metadata. Embed the chunks and store them in a vector index, and pair that with a keyword index so exact identifiers match reliably. Set a minimum similarity score below which the retriever returns nothing at all. Rebuild the index automatically whenever an approved document changes, so retrieval never serves a retired policy.

import numpy as np

MIN_SIMILARITY = 0.78

def retrieve(query, index, embed, k=5):
    q = embed(query)
    scored = [(float(np.dot(q, c["vector"])), c) for c in index]
    scored.sort(key=lambda pair: pair[0], reverse=True)
    return [c for score, c in scored[:k] if score >= MIN_SIMILARITY]

Step 3 – Write a grounded prompt with an abstention rule

Draft a system prompt that names the assistant’s role, states that it must answer only from the supplied passages, and defines the exact fallback sentence for missing evidence. Include 2 short examples of correct abstention and 1 example of a well-cited answer, because demonstrations teach behavior more reliably than rules. Ask the model to quote the supporting sentence and the passage identifier before it writes the final answer. Keep the temperature low, and keep the instructions free of contradictions. Insert the retrieved passages into a clearly labeled block so the model can tell evidence from instructions.

Test the prompt against the golden set and compare faithfulness with your baseline. If the model still answers unanswerable questions, strengthen the fallback instruction and add another refusal example rather than adding more rules. Watch for the opposite failure too, where the model refuses answerable questions because the instruction became too timid. Record both the faithfulness score and the abstention rate for every prompt version you try. Pro tip: store prompts in version control with the score they achieved, so every wording change leaves an audit trail.

You are a support assistant for Acme Air.
Answer ONLY from the passages below. Each passage has an id.
If the passages do not contain the answer, reply exactly:
"I could not find that in our documents. I am connecting you with a person."
Before answering, quote the supporting sentence and give its passage id.
Never use outside knowledge, and never invent policies, prices, or dates.

PASSAGES:
{{passages}}

QUESTION:
{{question}}

Step 4 – Constrain the output with a schema

Define a JSON schema that forces the model to return the answer, the supporting quote, the passage identifier, and an answerable flag. Use enumerations for any field with a closed set of values, and set numeric bounds where they make sense. Enable your provider’s schema-constrained decoding if it is available, and add a validation step in your own code for providers that lack it. Reject and retry any response that fails validation, with a limit of 1 retry. After the retry, treat a second failure as an abstention instead of showing malformed output.

{
  "type": "object",
  "required": ["answerable", "answer", "quote", "passage_id"],
  "properties": {
    "answerable": {"type": "boolean"},
    "answer": {"type": "string", "maxLength": 1200},
    "quote": {"type": "string"},
    "passage_id": {"type": ["string", "null"]}
  },
  "additionalProperties": false
}

Step 5 – Add a claim-level faithfulness check

Implement a function that splits the draft answer into atomic claims and asks a judge model whether the retrieved context fully supports each one. The function returns the share of supported claims along with the list of unsupported ones. Instruct the judge to use only the context and to answer with a simple yes or no per claim. Run it on the golden set first, and compare its verdicts with 20 to 50 human labels before you trust it in the request path. If agreement is low, rewrite the rubric wording before changing the judge model.

Keep the judge deterministic by setting the temperature to zero and logging the exact prompt version. Exclude hedges and explicit refusals from the claim list so that honest abstention scores as fully faithful. Cache verdicts for identical claim and context pairs to keep the cost of repeated checks low. Review a handful of judge decisions by hand every week to catch drift early. Pro tip: return the list of unsupported claims to your logs, because engineers fix specific sentences much faster than they fix a bare ratio.

import json

CLAIM_PROMPT = "Split the answer into atomic factual claims. Return a JSON list of strings."
JUDGE_PROMPT = (
    "Context:n{context}nnClaim: {claim}n"
    "Is the claim fully supported by the context alone? Answer YES or NO."
)

def faithfulness(answer, context, llm):
    claims = json.loads(llm(CLAIM_PROMPT + "nn" + answer))
    if not claims:
        return 1.0, []
    unsupported = []
    for claim in claims:
        prompt = JUDGE_PROMPT.replace("{context}", context).replace("{claim}", claim)
        if not llm(prompt).strip().upper().startswith("YES"):
            unsupported.append(claim)
    score = (len(claims) - len(unsupported)) / len(claims)
    return score, unsupported

Step 6 – Gate answers with thresholds and fallbacks

Wrap retrieval, generation, and verification in a single gate function that returns either an approved answer or a fallback with a route. The gate should fall back when retrieval returns nothing, when the model sets the answerable flag to false, and when the faithfulness score is below your threshold. Send fallbacks for high-risk intents to a human queue, and send the rest to a polite message with a link to documentation. Start with a threshold of about 0.9, then tune it using the golden set and shadow traffic. Log the reason for every fallback so you can see which stage blocks the most answers.

FALLBACK = "I could not find that in our documents. I am connecting you with a person."

def answer_with_gate(question, retrieve_fn, generate_fn, judge_fn, min_faith=0.9):
    hits = retrieve_fn(question)
    if not hits:
        return {"text": FALLBACK, "route": "human", "reason": "no_evidence"}
    draft = generate_fn(question, hits)
    if not draft["answerable"]:
        return {"text": FALLBACK, "route": "human", "reason": "model_abstained"}
    score, unsupported = judge_fn(draft["answer"], hits)
    if score < min_faith:
        return {"text": FALLBACK, "route": "human", "reason": "low_faithfulness",
                "unsupported": unsupported}
    return {"text": draft["answer"], "route": "user", "score": score}

Step 7 – Log, sample, and alert on live traffic

Record every request with its question, retrieved passage identifiers, draft, final answer, route, and score where available. Sample about 10 percent of live answers for judge scoring, and increase the rate for high-risk intents. Compute a rolling average of faithfulness and alert the owning team when it falls below your target for a sustained window. Link each alert to the stored records so the on-call engineer can read the failing examples immediately. Redact personal data from the logs before they are stored or shared with reviewers. Review a sample of the stored records each week to confirm the scores still match human judgment.

Close the loop every week by reviewing the lowest-scoring answers and the thumbs-down reports. Add confirmed failures to the golden set, adjust the prompt or retrieval settings, and rerun the suite before deploying the change. Over a few cycles you will see both the faithfulness trend and the abstention rate stabilize. Share the trend with product and legal stakeholders so everyone understands the residual risk. Pro tip: schedule the review as a recurring meeting with a named owner, because monitoring that nobody reads is indistinguishable from no monitoring at all.

import random
import time

SAMPLE_RATE = 0.10
ALERT_BELOW = 0.92

def log_and_sample(record, judge_fn, window, write_line):
    write_line(record)
    if random.random() < SAMPLE_RATE:
        score, unsupported = judge_fn(record["answer"], record["passages"])
        window.append(score)
        recent = window[-50:]
        if len(recent) == 50 and sum(recent) / 50 < ALERT_BELOW:
            return {"alert": "faithfulness below target", "at": time.time()}
    return None

Recommended by AIplusInfo

Books to go deeper on reliable LLM applications

Hand-picked titles that map to the evaluation, retrieval, and prompting work described in the build above.

As an Amazon Associate, AIplusInfo earns from qualifying purchases.

Book

AI Engineering: Building Applications with Foundation Models

A practitioner guide to evaluating, retrieving, and monitoring foundation-model applications, directly useful for the golden sets and verifiers described above.

Buy on Amazon

Prompt Engineering for LLMs: The Art and Science of Building Large Language Model-Based Applications

Book

Prompt Engineering for LLMs: The Art and Science of Building Large Language Model-Based Applications

Covers prompt structure, context assembly, and grounding techniques that narrow the room for invention in production assistants.

Buy on Amazon

Hands-On Large Language Models: Language Understanding and Generation

Book

Hands-On Large Language Models: Language Understanding and Generation

Visual, code-first coverage of embeddings, retrieval, and model behavior that helps teams understand why hallucinations occur in the first place.

Buy on Amazon

Key Insights

  • OpenAI’s SimpleQA comparison found a model abstaining on 52 percent of questions made 26 percent errors, against 75 percent for one that rarely abstained, so honesty cuts errors.
  • Amazon reports that its contextual grounding check filters over 75 percent of hallucinated responses in retrieval and summarization workloads, making a second-pass verifier a high-yield addition to any RAG pipeline.
  • Stanford’s study of more than 200 legal queries found purpose-built research tools still hallucinated about 17 percent of the time despite retrieval, so grounding without verification leaves substantial residual risk.
  • Vectara’s leaderboard spans 1.8 percent to 24.2 percent hallucination rates across models summarizing more than 7,700 articles, showing that model selection alone can change error rates tenfold.
  • Langfuse advises sampling five to ten percent of live traffic for judge scoring and calibrating against twenty to fifty human labels, a cheap routine that makes faithfulness a monitored metric.
  • A Canadian tribunal ordered Air Canada to pay CAD 812.02 after its chatbot misstated a bereavement fare rule, proving that even small hallucinations create real liability for the deploying company.
  • Deloitte agreed to partially refund an AUD 440,000 government report that contained fabricated citations, which shows that unverified generative drafting can damage even the most established professional brands.

Taken together, these figures tell a consistent story about where reliability comes from. Hallucination rates are shaped by incentives, by model choice, and by the evidence supplied at answer time, which means teams control far more of the outcome than the headlines suggest. Verification layers and calibrated judges add measurable protection, yet the Stanford findings show that no single layer is sufficient on its own. Legal and financial consequences land on the deploying organization, so the cost of skipping controls grows with every customer-facing answer. The sensible answer to how to reduce LLM hallucinations in production is a layered system that is measured, reviewed by people where stakes are high, and honest about uncertainty.

Control Layer What It Catches Effort to Add Main Limitation
Retrieval grounding Missing or outdated facts Medium Only as good as documents and search
Constrained prompts Guessing and off-topic answers Low Followed unevenly when rules compete
Structured outputs Invented fields and categories Low Valid structure can still hold wrong values
Citation verification Fabricated or unretrieved sources Low A real citation can still be irrelevant
Claim-level judge Unsupported statements in answers Medium Adds latency and judge cost
Contextual grounding guardrail Answers that drift from the source Medium Threshold tuning needed per use case
Abstention and fallback paths Confident answers without evidence Low Too many refusals frustrate users
Human review and escalation High-stakes errors of any kind High Slow and costly at large volume
Live monitoring and sampling Regressions after launch Medium Detects problems after some users see them

Real-World Deployments Showing Hallucination Controls in Practice

Air Canada’s Website Chatbot

Turning to documented deployments, Air Canada deployed a website chatbot that told traveler Jake Moffatt he could apply for a discounted bereavement fare within 90 days. The airline later refused the request and offered a $200 coupon, so Moffatt took the dispute to British Columbia’s Civil Resolution Tribunal. On February 14, 2024, the tribunal ruled that the chatbot was part of the airline’s website and ordered Air Canada to pay CAD 812.02 covering the refund, interest, and fees. The airline had argued that the chatbot was a separate entity responsible for its own actions, and the tribunal rejected that defense. The core problem was that the bot’s answer was never checked against the correct policy page that sat one click away. Even a simple grounding check would have flagged the mismatch, and the case still stands as a limit on how much legal protection a disclaimer can offer.

Cursor’s Support Assistant Called Sam

Among customer-facing assistants, Anysphere, the maker of the Cursor coding tool, ran an AI support agent named Sam that answered a user who kept getting logged out when switching devices. The bot invented a policy limiting each subscription to a single device and presented it as a security measure, even though no such rule existed. The claim spread on Reddit and Hacker News, and many users threatened to cancel while some actually did. About three hours later the company publicly called the answer a hallucination and confirmed that users could work on multiple machines. That rapid correction limited the damage, yet the episode still showed how a single ungrounded answer can erode trust at a company reportedly earning 100 million dollars in annual revenue. A retrieval check against the real terms of service and a clearly labeled automated agent would have reduced the risk.

Vectara’s Hallucination Leaderboard

Beyond individual incidents, Vectara built a public benchmark that measures how often models introduce unsupported content when summarizing documents. The HHEM leaderboard runs models over a dataset of more than 7,700 articles ranging from about 50 to 24,000 words, then scores factual consistency against each source. In its May 2026 update the lowest listed rate was 1.8 percent and the highest was 24.2 percent. Buyers use that spread to shortlist candidates before testing their own data. Because the board is refreshed as new models appear, it gives teams a cheap, repeatable signal that complements their private golden sets. The main limit is scope, since it measures summarization faithfulness rather than open-ended question answering, so it cannot replace evaluation on your own documents and intents.

Lessons From Costly Hallucination Failures

Case Study: Mata v. Avianca and the Fabricated Citations

Looking at the legal profession, the lawyers in the Avianca case faced a research problem that generative AI seemed to solve. Attorney Steven Schwartz used ChatGPT to find precedents for a personal-injury suit against the airline over a 2019 flight. The filings cited several decisions that simply did not exist. When Judge Castel demanded the nine cited decisions, the lawyers produced the full text of eight, which proved to be fictitious. The court set a hearing for June 8, where both attorneys had to explain their conduct, and the possibility of sanctions loomed over the firm. Schwartz stated that his colleague Peter LoDuca had no role in the research, which shifted attention to how supervision failed. CNBC’s report shows how quickly a plausible-looking citation can escape review when nobody checks it.

The fix is neither exotic nor expensive, because the practical solution is to build citation verification that confirms every cited case exists in a trusted database before anything is filed. A lookup of that kind takes minutes per filing, which is trivial compared with the reputational and professional consequences described in the case. The episode also illustrates the limit of asking a model to police itself, since the lawyer reportedly asked the chatbot whether the cases were real and accepted its answer. Independent verification against an external record is the control that would have worked. Legal teams adopting AI drafting tools now treat citation checking as a mandatory step rather than an optional courtesy.

Turning to vendors, legal research providers faced pressure to prove that retrieval-augmented tools were reliable, because many marketed them as free of hallucinations. Stanford’s Institute for Human-Centered AI tested purpose-built legal tools on more than 200 open-ended queries, some based on a mistaken understanding of the law. The researchers found that the tools still produced incorrect or misleading answers about 17 percent of the time. They also noted that a citation can exist yet be irrelevant or contradictory. An earlier Stanford analysis cited in coverage found that general-purpose ChatGPT erred on legal questions as often as 82 percent of the time. LegalDive summarized the findings and the researchers’ conclusion that legal hallucinations have not been solved.

The recommended solution was public benchmarking and rigorous evaluation so that buyers could verify vendor claims instead of trusting marketing language. LexisNexis contested the result, saying its own data suggested a much lower rate and that Stanford had not contacted it before publication. That controversy matters because it shows how definitions, query sets, and grading rules change headline numbers. For practitioners the lesson is to run an independent evaluation on their own questions before adopting any vendor’s reliability claims. Retrieval clearly helps compared with an unaided model, yet the audit demonstrates that it is not a substitute for verification and monitoring.

Case Study: Deloitte’s Refunded Government Report

Consulting is a business built on trust, and Deloitte Australia struggled with that trust when a report it prepared for the Australian government was found to contain apparent AI-generated errors. The government had paid AUD 440,000, roughly US$290,000, for the work. The report was intended to inform public policy, so accuracy of every citation was essential. Reviewers identified a fabricated quote attributed to a federal court judgment and citations to academic research papers that do not exist. The firm adopted a partial refund as its remedy, and the story reached international news in October 2025 through an Associated Press report carried by CTV and other outlets.

The incident prompted increased scrutiny of how professional services firms disclose and review generative AI use in deliverables. The available coverage did not name the specific tools involved or the refund amount, which limits what outsiders can conclude about root causes. What is clear is that the errors were the kind that reference checking would catch: quotes and citations can be matched against primary records before delivery. A review step that verifies every citation, together with disclosure of AI assistance in the engagement terms, would have addressed the problem. The case shows that hallucination risk is not confined to chatbots, and that it reaches any workflow where generated text is treated as finished work.

Frequently Asked Questions About Reducing LLM Hallucinations in Production

What causes LLM hallucinations in production systems?

Language models predict plausible next tokens rather than verified facts, so gaps in their training data get filled with confident guesses. Standard training and evaluation also reward guessing over admitting uncertainty, which pushes models toward answering every question. Rare facts, recent events, and precise figures are the most common triggers for invented content. Production systems add risk when retrieval returns weak passages or when prompts leave too much room for invention.

Can retrieval-augmented generation eliminate hallucinations?

No, because retrieval narrows the evidence a model sees without forcing the model to follow it. Stanford researchers found that purpose-built legal research tools using retrieval still produced incorrect or misleading answers about 17 percent of the time. Citations can also point to real documents that do not actually support the claim being made. Pair retrieval with verification and abstention rules to catch what slips through.

How do you measure an LLM hallucination rate?

Build a golden set of around two hundred real questions with approved source passages and reference answers, including questions that your documents cannot answer. Score each answer by splitting it into atomic claims and checking every claim against the retrieved context. Faithfulness equals the number of supported claims divided by the total number of claims. Track the score every week and fail a deployment when it regresses.

What is a good faithfulness target for a production assistant?

There is no universal threshold, because acceptable risk depends on what a wrong answer costs your business. Teams usually set stricter targets for legal, medical, and financial answers than for casual product questions. Start by measuring your baseline on the golden set, then set a target that improves on it each release. Route anything below the target to a fallback message or a human reviewer.

Does lowering the temperature stop hallucinations?

Lower temperature makes outputs more deterministic, but it does not make them more truthful. A model can repeat the same wrong answer every single time at temperature zero. Treat a low temperature as a small stabilizer that helps with reproducibility and testing. The larger gains in how to reduce LLM hallucinations in production come from grounding, abstention rules, and verification layers.

How does a model-based judge help reduce hallucinations?

A judge model reads the answer and the retrieved passages, then decides whether each claim is supported. It runs after generation, so it can block or flag an answer before the user sees it. Calibrate the judge against twenty to fifty human-labeled answers and refine the rubric until agreement is high. Judges add latency and cost, so many teams run them on every high-risk answer and only a sample of the rest.

What are contextual grounding checks?

Contextual grounding checks compare a generated answer with the source passages and the user question. Amazon reports that its Bedrock grounding check filters over 75 percent of hallucinated responses in retrieval and summarization workloads. You set thresholds for grounding and relevance, and responses that fall below them are blocked or replaced. They work best as one layer among several rather than as a standalone fix.

Should the model be allowed to say it does not know?

Yes, and abstention is one of the most effective controls available to a production team. OpenAI’s SimpleQA comparison showed a model that abstained on 52 percent of questions making 26 percent errors, while a model that rarely abstained made 75 percent errors. Give the model an exact fallback sentence and a typed answerable field so your code can route unsupported questions. A polite refusal costs far less than a confident falsehood that reaches a customer.

How often should I sample live traffic for scoring?

Langfuse suggests sampling five to ten percent of live traffic for judge scoring. Raise the rate for high-risk intents, new releases, and any topic where complaints are rising. Store the unsupported claims alongside the scores so engineers can see exactly what failed. Review a small batch of judged answers by hand each week to confirm the judge still agrees with people.

When is fine-tuning better than retrieval for reducing hallucinations?

Fine-tuning helps when you need consistent tone, format, or domain vocabulary, but it does not reliably add new facts. Retrieval is usually the better choice for knowledge that changes, because you can update documents without retraining. Many teams combine both, using fine-tuning for behavior and retrieval for facts. Compare the two on your own golden set before committing budget to either.

Do larger models hallucinate less than smaller ones?

Not always, because size alone is a weak predictor of how faithful a model will be on your documents. Vectara’s leaderboard shows rates ranging from 1.8 percent to 24.2 percent across models summarizing the same articles. Newer models can improve on some tasks while becoming riskier on others. Test candidates on your own documents rather than relying on a public ranking.

Who is legally responsible when a chatbot gives a wrong answer?

In most disputes so far, the deploying company has been held accountable for what its chatbot said. In 2024 a Canadian tribunal ordered Air Canada to pay CAD 812.02 after its chatbot misstated a bereavement fare rule. The tribunal rejected the argument that the bot was a separate entity. Disclaimers offer limited protection when the wrong answer sits beside the correct policy on your own website. Consult counsel for your jurisdiction, since rules differ and are still developing.

How do I handle hallucinations in agents that call tools?

Define strict schemas for every tool and validate each call before executing it. Reject calls that reference identifiers the system has never seen, and require confirmation for actions that cost money or change records. Log every tool call with its arguments so you can trace a bad action back to the step that caused it. Deterministic guardrails outside the model catch errors that no prompt can fully prevent.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button