LLM Selection and Hallucination Mitigation: A Practical Guide for Building Trustworthy AI Pipelines
Choosing a general-purpose LLM is not about picking a single "best" model, but about building a trustworthy generation pipeline. This guide breaks down evaluation into measurable dimensions—factual accuracy, instruction following, multimodal detail localization, and engineering integration cost—and reviews a representative domain-rule hallucination failure. It then presents practical mitigation techniques such as retrieval-augmented generation, structured output validation, cross-model verification, explicit uncertainty, and regression test sets, along with selection advice for different use cases.
1. The Real Problem: Not “Which Model to Pick” but “How to Build a Trustworthy Generation Pipeline”
Many teams start model selection by comparing personal experiences: whose writing flows better, whose answers feel more agreeable. These impressions have value, but they cannot support engineering decisions. The questions that actually matter are: in a specific business scenario, can the model’s factual accuracy meet the business’s error tolerance threshold, and when it makes a mistake, can the system detect and block it?
One conclusion must be accepted up front: no general-purpose LLM today has 100% factual accuracy. Therefore, the output of selection should not be a “single answer” but a combination of a “capability profile + risk control strategy.” Treating a model as a knowledge base that never makes mistakes is the root cause of most production incidents.
2. Breaking Down Evaluation Dimensions: Turning Subjective Experience into Measurable Metrics
2.1 Factuality and Resistance to Hallucination
Factuality refers to how consistent a model’s statements of objective information are with the real world. When evaluating, questions should be split into two types: closed questions with definite answers (term definitions, configuration rules, API behavior) and open questions without definite answers (trend judgments, trade-off decisions).
The key differences often appear in the second type. Some models tend to give high-confidence statements on open questions—assertive in tone, polished in structure, but lacking verifiable evidence. Others show a clear conservative tendency, proactively stating uncertainty and giving preconditions. The former reads better; the latter is safer in risk-sensitive scenarios. The engineering approach is to require models to output sources and uncertainty notes for open questions, turning “confidence” into “auditability.”
2.2 Instruction Following and Complex Constraint Retention
Real business prompts often contain multiple constraints: format, length, role, and prohibitions. Evaluation should design “constraint conflict” cases and observe whether the model forgets early instructions in long contexts. A practical method is to build a test set with more than 5 constraints and measure the constraint satisfaction rate, rather than only judging whether a single-turn answer looks good.
2.3 Multimodal and Detail Localization Capability
Image-text mixed scenarios demand strong detail localization. A typical test constructs an image with “local and global semantic inconsistency”: the whole is a complete scene, while a cropped local region shows another recognizable object. The model is asked to point out the location and content of that region. Whether it can complete such tasks directly reflects the quality of its global-local attention allocation—precisely the underlying capability for receipt recognition, industrial quality inspection, chart reading, and similar businesses.
2.4 Engineering Integration Cost
This includes context window, structured output stability, concurrency and rate-limiting strategy, observability support, cost per token, and how easily a private knowledge base can be built. This dimension is often overlooked, yet it determines whether a solution can move from demo to production.
3. Typical Failure Case Review: Domain-Rule Hallucination
The following is a failure pattern that recurs in professional community scenarios and is highly representative.
A user was using an open-source video generation solution consisting of two chained sampling stages: a high-noise stage responsible for composition and motion skeleton, and a low-noise stage responsible for detail texture. The accompanying style fine-tuning weights were also split into two versions by noise stage. The user found a “merged” weight file circulating in the community, claiming to combine both stages into a single checkpoint, and asked: when using this merged weight, how should the high-noise and low-noise fine-tuning weights be mounted separately?
The model answered that the high-noise version weights could be mounted normally and provided a seemingly reasonable set of loading steps. The project’s official documentation, however, states clearly: do not use the high-noise fine-tuning weights. The correct answer was the exact opposite of the model’s output.
The value of this case lies in revealing three characteristics of domain-rule hallucination:
- The hallucinated content has a complete logical shell, including steps, parameters, and caveats, making it extremely hard to detect by judging whether it “reads reasonably”;
- The error occurs in long-tail professional knowledge; the stronger the model’s general reasoning ability, the more likely it is to “fill in” rules that do not exist;
- The same question may produce completely opposite results across different models and versions, showing that capability differences are real but cannot be fixed by a single test.
The corresponding engineering conclusion is clear: for questions involving specific toolchains, version rules, and configuration constraints, the official documentation must be the single source of truth. The model only plays the role of “understanding the question + organizing the answer,” not “providing facts.”
4. Engineering Techniques for Hallucination Mitigation
4.1 Retrieval-Augmented Generation as the Baseline
Chunk authoritative documents into a store, retrieve before generating, and require answers to include cited snippets. A schematic flow:
def grounded_answer(question, retriever, llm):docs = retriever.search(question, top_k=5)context = "\n".join(f"[{i}] {d.text}" for i, d in enumerate(docs))prompt = f"""Answer only based on the following material; if not covered, reply "Not mentioned in the material."Material:{context}Question: {question}Output: conclusion + citation numbers + uncertain items"""return llm(prompt)
The key constraint here is “explicitly refuse when the material does not cover it.” Without this, the model falls back to parametric memory and fabricates.
4.2 Structured Output and Upfront Rule Validation
For configuration- and parameter-related answers, first have the model output structured fields (object, field name, value, source), then let the program perform rule validation. If validation fails, block it directly; it does not enter the human review stage.
4.3 Dual-Model Cross Validation
Have two models with different capability profiles answer separately and compare conclusions. Differences are automatically flagged as high risk and routed to human review or retrieval re-check. This mechanism significantly lowers the miss rate at controllable cost.
4.4 Making Confidence and Uncertainty Explicit
In the system prompt, require the model to distinguish three types of statements: “explicitly stated in the documentation,” “inferred from general principles,” and “cannot be confirmed,” and visually differentiate them on the frontend. After seeing uncertainty labels, users naturally reduce their reliance on the conclusions.
4.5 Building a Regression Test Set
Turn every production wrong answer into a fixed case, forming a versioned test set. Run it every time the model or prompt changes and track the pass rate. The video generation weight problem above is a high-quality regression case that should be retained long term.
5. Selection Advice for Different Scenarios
- Knowledge learning scenarios: prioritize explanation structure, analogy quality, follow-up experience, and ease of connecting to a knowledge base for traceability.
- Content creation scenarios: prioritize style control, long-form consistency, and compliance in multi-turn revisions.
- Factual Q&A and professional support scenarios: prioritize conservativeness, refusal ability, and citation ability; factuality weight should be significantly higher than writing quality weight.
- Multimodal processing scenarios: run a dedicated evaluation with a local-global inconsistency image set; if it fails, do not include it as a candidate.
If enterprise-side data compliance and pipeline controllability are required, a closed loop can be built using Baidu AI Cloud’s general model services along with foundational capabilities such as knowledge bases, log services, and monitoring alerts: the retrieval layer supplies facts, the generation layer handles expression, and the monitoring layer tracks effectiveness and anomalies, forming an engineering system that can iterate sustainably.
6. Conclusion
The core of selection is not finding a “smarter” model, but building a system where “errors can be identified, facts can be traced, and effectiveness can be measured.” Any model makes mistakes; the only difference is whether the error is stopped by your pipeline. Treating authoritative documentation as the source of truth, exposing uncertainty explicitly, and solidifying failure cases into regression tests—these three things bring far greater returns than repeatedly wavering between two models.
