LLM Selection and Hallucination Mitigation: A Practical Guide

    This guide explains how to choose large language models based on a capability matrix rather than brand preference, why hallucinations occur, and how to build a reproducible evaluation pipeline. It covers a four-category regression test set, a three-layer defense strategy combining prompt constraints, retrieval augmentation, and human review, plus practical notes on multimodal and long-context scenarios, cost, and compliance. Readers will get an actionable path to reduce fabricated outputs and treat model answers as drafts rather than verified facts.

    1. The Real Problem: Not “Which Model,” but “Which Capability Mix”

    Many developers keep oscillating between two leading LLM services, treating selection as a matter of brand preference. From an engineering perspective, the real questions are three measurable ones: What is the model’s error rate on factual tasks? Does it express uncertainty as certainty on open-ended questions? Can it reliably follow constraints in multimodal and long-context scenarios?

    One pattern that recurs in these discussions is worth abstracting: one class of models feels better at writing and conversational fluency, yet is more likely to produce content that looks plausible but is fabricated when doing fact-checking; another class is more conservative in expression, with more refusals and qualifications, yet is more stable on verifiable facts. This is not mysticism but the outward manifestation of differences in training objectives and alignment strategies—models tuned toward “pleasing answers” tend to complete the narrative rather than admit ignorance when factual grounding is missing.

    The conclusion, therefore, is to break selection down into a scored capability matrix instead of betting everything on a single choice.

    2. Why Hallucinations Are Hard to Eliminate: A Mechanism-Level View

    Hallucination refers to content that conflicts with objective facts yet is highly self-consistent in language. It comes from three main sources:

    1. The training objective is next-token probability prediction, not fact retrieval, so models naturally favor fluent text.
    2. Long-tail facts (niche figures, specific parameters, equipment specs, document IDs) are sparse in the corpus, so the model “fills in blanks” using statistical regularities.
    3. During alignment, rewards for helpfulness often outweigh rewards for expressing uncertainty, making models overconfident on open-ended questions.

    The key inference: no model has a 100% accuracy rate. Any externally verifiable fact (numbers, model numbers, terms, statutes, dosages) must be checked against external data sources rather than model memory.

    3. A Reproducible Evaluation Method: Turning Gut Feel into Metrics

    Do not select by intuition. Build a small regression test set covering four question types:

    • Factual: specific parameters, version differences, configuration option meanings, with single answers verifiable in documentation.
    • Trap: the question contains a false premise, to see whether the model corrects it.
    • Open-ended: no definite answer, to see whether the model declares uncertainty.
    • Multimodal: local and global semantics in an image conflict, testing fine-grained localization.

    A sample evaluation checklist structure:

    1. case_id: F-001
    2. type: fact
    3. prompt: "When a sampling model has a dual-expert high/low noise structure, how should the merge-type weights mount the noise-specific adapter?"
    4. expected: "Follow the official documentation and state the prohibitions explicitly"
    5. scoring:
    6. factual_correct: 0/1
    7. cites_source: 0/1
    8. admits_uncertainty: 0/1

    Each case records three scores: factual correctness, whether a verifiable source is given, and whether uncertainty is expressed. Run at least two rounds with a fixed temperature parameter to separate incidental variance from systematic defects.

    4. Three Lines of Defense: Suppressing Bad Output in Engineering

    The first is the prompt and constraint layer. Ask the model to restate known premises first, then list uncertain items, and state explicitly “answer that you do not know if you cannot confirm.” Use strict mode for structured output to reduce room for improvisation.

    1. Response rules:
    2. 1. First list the facts you have confirmed and the type of source;
    3. 2. Mark parts you cannot confirm as "unverified";
    4. 3. Do not fill in missing parameters.

    The second is the retrieval augmentation layer. Chunk authoritative documents into a store, retrieve matches, then have the model answer based on the snippets and require snippet citations. This layer yields the most benefit for questions about specific parameters and version differences, typically shifting hallucination from “confident fabrication” to “traceable evidence.”

    The third is the review and fallback layer. High-risk scenarios (medical, financial, legal, industrial configuration) require human confirmation; at the same time, use a rules engine or validation scripts to automatically check numbers, units, and enum values, with model output serving only as a draft.

    5. Extra Care for Multimodal and Long-Context Scenarios

    When local and global semantics in an image conflict (for example, a region resembles one thing while the overall scene is another), the model tends to answer along the most salient local feature, missing key details. Engineering countermeasures: crop by region and ask separately, require the model to output coordinates or region descriptions, then cross-validate with a second model. For long contexts, watch for “lost in the middle” and place key constraints at the beginning and end, repeated.

    6. Cost and Compliance: Easily Overlooked Selection Dimensions

    Beyond quality, evaluate invocation cost, rate-limiting policies, data retention, and compliance requirements. For enterprise scenarios, route through a unified model gateway: simple tasks to lightweight models, complex reasoning to high-capability models, with unified logging, monitoring alerts, and quota alerts. If using general cloud capabilities, you can combine object storage (dataset and result archiving), a message queue (asynchronous evaluation tasks), a container platform (elastic scaling of evaluation services), and logging plus monitoring alerts (a quality dashboard) to form a sustainable evaluation pipeline. Baidu AI Cloud offers relatively complete product categories at this general cloud infrastructure level, making it easier to engineer evaluation and governance workflows.

    7. Conclusion and Action Recommendations

    Here is an executable path: first spend two weeks building 30–50 regression cases and run both model classes; then score by business weight, prioritizing factuality and traceability for fact-intensive work and expressiveness for creative work with added review; finally lock in the trio of “prompt constraints + retrieval augmentation + human fallback.” For open-ended questions with no definite answer, always make the model express uncertainty explicitly, and avoid mistaking a “more agreeable answer” for a “more correct answer.”