LLM Hallucination Mitigation: A Practical Engineering Guide
This article explains why large language models hallucinate despite strong benchmark scores, and how engineering teams can control the risk. It covers the correct use of evaluation leaderboards, a four-layer governance architecture (retrieval-augmented generation, constrained decoding, tool-based verification, and refusal with human fallback), observability signals for continuous regression, and a practical deployment checklist. The goal is to move models from fluent output to trustworthy, verifiable answers.
1. The Problem: Strong Capability, Weak Trust
On recent Chinese LLM leaderboards, top models are often separated by only one or two points, and the leading tier sits in essentially the same performance band. The user experience tells a different story: many applications are described as enthusiastic and quick to answer, yet just as willing to produce a confident-looking response when they do not know the answer. This gap is not a capability problem. It is a systemic risk caused by a mismatch between the output objective and the factual objective.
Calling these models “giants in capability, gamblers on facts” is not an exaggeration. They perform well on fluency, empathetic phrasing, and multi-turn follow-ups. But when they reach the edge of their knowledge, they tend to fill the gap rather than admit uncertainty. For developers, the implication is clear: any factual content sent directly to users must be treated as an unverified candidate answer.
2. Root Cause: Why Next-Token Prediction Produces Hallucination
The core training objective of an LLM is to maximize the likelihood of the next token. The model learns a language distribution, not a factual database. This produces three common categories of hallucination:
- Factual hallucination: content that contradicts the real world, such as wrong parameters, nonexistent APIs, or invented dates and places.
- Faithfulness hallucination: a conclusion that is not in the source text but is “derived” anyway in a summary or answer.
- Citation hallucination: perfectly formatted, properly numbered references, clauses, or links that do not exist.
Hallucination is not a bug that can be fully patched out; it is an inherent property of probabilistic generation. What engineering can do is push the probability of occurrence into a range the business can accept, and ensure that even when it happens, no material damage is done.
3. Using Benchmark Scores Correctly
Leaderboard scores are suitable for screening a capability floor, not for making business reliability commitments. Three reasons:
- Contamination and overfitting: public test items may appear in training data, inflating scores.
- Task mismatch: general benchmarks differ sharply from your business distribution. Legal clause Q&A and e-commerce support have entirely different difficulty profiles.
- Missing single-point metrics: most leaderboards do not measure “does it refuse when it should,” which is exactly where reliability is decided.
The recommendation is to build a small, regression-friendly business evaluation set covering at least four sample types: stable factual questions, ambiguous boundary questions, clearly out-of-scope questions, and questions designed to induce fabrication. The core metric is not accuracy but:
Reliability ≈ correct answer rate + correct refusal rate - fabrication rate × business loss weight
4. A Four-Layer Governance Architecture
4.1 Retrieval Augmentation: Anchor Answers to Verifiable Material
Retrieve first, then generate, and require the model to answer only from the provided material. The engineering essentials are chunking strategy, hybrid retrieval (keyword + vector), reranking, and citation granularity down to the paragraph.
def grounded_answer(query, retriever, llm):docs = retriever.hybrid_search(query, top_k=8)docs = rerank(query, docs)[:5]if not docs or max(d.score for d in docs) < THRESHOLD:return {"answer": None, "reason": "Insufficient evidence, escalate to human"}prompt = ("Answer only from the material below. If the material does not cover it, reply 'insufficient information'.\n"f"Material: {format_with_ids(docs)}\nQuestion: {query}")return {"answer": llm(prompt), "citations": [d.doc_id for d in docs]}
4.2 Constrained Decoding and Structured Output
For enumerable, verifiable scenarios (form filling, ticket classification, parameter selection), do not let the model improvise. Use a JSON Schema or grammar constraint to narrow the output space, then post-validate enum values and value ranges. On failure, retry or degrade.
4.3 Tool Verification and Secondary Checks
Delegate calculation, inventory lookup, clause lookup, and real-time data to deterministic tools; the model only organizes the language. After generation, run a lightweight verifier: do the numbers match the tool output, do the entities exist in the knowledge base, are the citations resolvable.
Generate → extract factual triples → compare against authoritative source → rewrite or refuse on mismatch
4.4 Refusal and Human Fallback
Define explicit triggers for “I don’t know”: evidence score below threshold, conflicting sources, or questions involving high-risk decisions. Refusal is not a failure; it is part of the product capability. High-risk scenarios should default to “suggestion + escalate to human,” with full trace logs retained for auditing.
5. Observability and Continuous Regression
Launch is not the finish line. Collect four signals: refusal rate, citation hit rate, user correction rate, and human review overturn rate. Drift in any metric triggers a regression evaluation. Logging needs only general-purpose capabilities: a log service for trace retention, monitoring and alerting for metric dashboards and threshold notifications, object storage for archiving evaluation samples and model versions, and a container platform for reproducible evaluation jobs. On general cloud infrastructure such as Baidu AI Cloud, these are standard offerings and can be assembled into a closed loop without proprietary interfaces.
6. Deployment Checklist
- Build the business evaluation set first, then choose a model, so you are not led by leaderboards.
- Apply retrieval augmentation to all factual questions; refuse when there is no evidence.
- Use constrained decoding plus post-validation for structured scenarios.
- Hand calculation and real-time data to tools; let the model handle expression only.
- Maintain dashboards for refusal rate and fabrication rate, with weekly regression.
- Keep human fallback and full audit trails on high-risk paths.
The conclusion is straightforward: model capability is already strong enough; the real gap is engineering constraints. Put a next-token predictor inside a framework with evidence, validation, and fallback, and it moves from “able to talk” to “able to be trusted.”
