LLM Hallucination: Root Causes and Engineering Practices to Suppress It
This article explains why hallucinations in large language models are a structural feature of autoregressive generation rather than an occasional defect, and breaks down four main causes: knowledge boundaries and long-tail sparsity, error amplification in chain-of-thought intermediate steps, ambiguity in context and prompts, and decoding randomness. It then presents engineering practices for suppressing hallucinations, including retrieval-augmented generation with citations, structured constraints with tool calls instead of generation, a dual-channel verification loop, decoding control with uncertainty expression, and observability with continuous evaluation. It closes with common pitfalls, a recommended implementation order, and the core principle of generating from evidence rather than memory.
1. Background: Why “Plausible Errors” Are the Most Dangerous
As language model capabilities iterate quickly, the metric developers and enterprise users care about most has shifted from “can it generate” to “can what it generates be trusted.” A typical phenomenon noted in the source material: a model fabricates implementation details that do not exist in an intermediate step of its chain-of-thought (CoT). The final answer reads fluently and is well formatted, but a key fact is wrong. Such errors are more dangerous than obvious garbled output, because they pass coarse-grained manual spot checks yet trigger cascading failures in downstream pipelines.
One basic point needs to be clear: hallucination is not an occasional defect of a particular model version, but a structural characteristic of the current autoregressive generation paradigm. The model is essentially doing sequence modeling under conditional probability. What it optimizes is whether “the next token is natural within the training distribution,” not whether “this sentence is true in the objective world.” When the training corpus itself has gaps, conflicts, or long-tail sparsity, the model fills the void with the statistically smoothest completion, which produces plausible-looking fabricated content.
2. Four Main Causes of Hallucination
2.1 Knowledge Boundaries and Long-Tail Sparsity
General-purpose corpora cover high-frequency concepts well, but cover internal systems, private data structures, and version-specific behavior differences very little. When pressed for details, the model tends to extrapolate based on “common industry practice” rather than admit it does not know.
2.2 Amplification Effect in Chain-of-Thought Intermediate Steps
Chain-of-thought improves complex reasoning performance, but it also moves errors forward from the “conclusion layer” to the “process layer.” Once an intermediate step contains a fabricated premise, subsequent reasoning unfolds self-consistently around that wrong premise, producing output that is “logically rigorous but wrong in conclusion.” This problem is especially visible in tasks that require multi-hop reasoning.
2.3 Ambiguity in Context and Prompts
When a prompt contains unclear references, conflicting constraints, or implicit assumptions, the model picks one interpretation on its own and follows it to the end without proactively asking for clarification. When new and old information inside the context window conflicts, the model may also retain an incorrect earlier fragment.
2.4 Decoding Strategy and Sampling Randomness
With a higher sampling temperature and no constrained decoding, output diversity rises while factual stability drops. Getting different details across repeated calls to the same question is itself an unreliability signal.
3. Engineering Suppression: From Single-Point Prompting to System-Level Verification
3.1 Retrieval Augmentation: Replace “Memory” with “Checkable Citations”
For fact-intensive tasks, external knowledge should be injected into the context via retrieval, and the model should be required to provide a citation source for each item. The key is not “retrieval was added,” but that every factual assertion in the answer can be traced back to a specific passage.
def grounded_answer(query, retriever, llm):docs = retriever.search(query, top_k=6)context = "\n".join(f"[{i}] {d.text}" for i, d in enumerate(docs))prompt = ("Answer only based on the material below; anything the material does not cover must be answered with 'not mentioned in the material'.\n"f"Material:\n{context}\n\nQuestion: {query}\n""Output requirement: mark the basis with [number] after each conclusion.")return llm.generate(prompt)
3.2 Structured Constraints and Replacing Generation with Tools
Anything that can be obtained through deterministic computation or a query should not be left to the model to “write from memory.” Handing verifiable actions to function calls, a rules engine, or a query interface, and letting the model only organize language and select parameters, can significantly compress the space for fabrication.
SCHEMA = {"type": "object","required": ["action", "params", "assumption"],"properties": {"action": {"enum": ["query_metric", "list_resource", "unknown"]},"params": {"type": "object"},"assumption": {"type": "string"}}}# The model must output a structure that conforms to SCHEMA; when action=unknown, it must not fabricate params
The assumption field is a practical trick: forcing the model to explicitly write out the assumptions it relies on exposes implicit premises at the verification stage instead of hiding them inside the chain-of-thought.
3.3 Dual-Channel Verification Loop
Decouple generation from verification: the generation channel produces output, while the verification channel independently performs fact-checking, structure validation, and conflict detection, without sharing the same reasoning context, to avoid “self-confirmation.”
def verified_pipeline(query, retriever, llm, critic):draft = grounded_answer(query, retriever, llm)report = critic.review(query, draft) # outputs a list of unsupported_claimsif report.unsupported_claims:draft = grounded_answer(query + "\nNote the corrections: " + report.summary(),retriever, llm)return draft, report
3.4 Decoding and Uncertainty Expression
Lowering the sampling temperature, enabling constrained decoding, and restricting key fields to enumerations are the lowest-cost stability measures. The model should also be allowed to express uncertainty: when retrieval coverage is low or evidence conflicts, it should output “low confidence / manual confirmation needed” instead of forcing a definite answer. Confidence tiers can be produced with simple heuristic rules, for example based on citation coverage and the number of unsupported claims from the verification channel.
3.5 Observability and Continuous Evaluation
Making hallucination governance a closed loop requires three pieces of infrastructure: a logging service that retains complete prompts and outputs for traceability; monitoring and alerting with thresholds on metrics such as “ratio of assertions without citations” and “verification failure rate”; and an evaluation set that covers long-tail and adversarial samples, with regression runs after every change. Without measurement there is no optimization, and tuning prompts by feel cannot converge reliably.
4. Implementation Advice and Common Pitfalls
- Pitfall 1: assuming that “switching to a larger model” eliminates hallucination. Scale improves coverage and reasoning but does not change the nature of probabilistic generation.
- Pitfall 2: handing verification entirely to the model itself. Without external evidence and an independent channel, the recall of self-verification is usually low.
- Pitfall 3: optimizing only the final answer. Process-layer errors must be exposed through structured intermediate artifacts and explicit assumptions.
- Suggested order of practice: first tier the tasks (factual / generative / computational), then introduce retrieval and citations for factual tasks, then add structured constraints and the verification loop, and finally build evaluation and monitoring.
In general engineering practice on cloud platforms such as Baidu AI Cloud, the capabilities above are typically carried by combinations of common product categories such as object storage, message queues, container platforms, logging services, and monitoring and alerting. The focus is on putting “generation” inside a system that is searchable, verifiable, and observable, rather than expecting a single call to produce absolutely reliable output.
5. Conclusion
Hallucination cannot be completely “fixed,” but it can be systematically compressed into a range the business can accept. The core idea is a single sentence: make the model assert less from memory and generate more from evidence, and place every assertion in a chain that is checkable, traceable, and measurable.
