How to Choose a Large Language Model and Reduce Hallucinations: A Practical Guide
This guide explains how to select a large language model based on task-specific evaluation rather than general impressions, and how to control hallucinations through layered prompt, retrieval, validation, and review mechanisms. It covers common capability dimensions, the causes of hallucination, handling overconfidence on open-ended questions, building a reproducible evaluation set, validation methods for multimodal and structured output, and cost and engineering considerations. Readers will find practical constraints, code skeletons, and recommendations for building a reliable system that combines a model with retrieval, validation, and human review.
1. The Real Problem: Not “Which Model Is Stronger,” but “Which One Fits Your Task Distribution”
When choosing among general-purpose LLM services, many teams rely on an overall impression. That kind of judgment has high variance. A more rigorous approach is to break business tasks into measurable capability dimensions and design test cases for each one. Common dimensions include factual question answering, long-form writing and rewriting, code generation and debugging, multimodal image understanding, structured output stability, long-context consistency, and refusal and safety boundaries.
A contradiction that keeps coming up in reader feedback is this: a model may be more pleasant in writing fluency and interaction, yet it will “confidently fabricate” in factual scenarios. This is not an isolated defect but a systematic tendency created by training objectives—preference alignment pushes the model toward complete, readable, and satisfying answers, and when information is insufficient, a complete answer can only be filled with plausible content. So the first principle of model selection is to score readability and verifiability separately.
2. Causes of Hallucination and Layered Governance
Hallucinations can be grouped into three layers:
- Factual hallucinations: specific numbers, model IDs, names, organizations, and parameters generated out of thin air;
- Citation hallucinations: seemingly well-formed document sections, links, or function names that do not actually exist;
- Reasoning hallucinations: correct premises but a jump in the derivation, so the conclusion looks reasonable yet cannot be reproduced.
Governance should be implemented in layers:
- Prompt layer: enforce evidence first, requiring the model to list known premises and missing information, and to declare uncertainty when information is missing;
- Retrieval layer: connect an enterprise knowledge base or document retrieval so answers stay within citable fragments;
- Validation layer: apply regex and allowlist checks to numbers, model IDs, and version numbers, and run reachability checks on citations;
- Process layer: route high-risk conclusions to a human review queue, with the model producing only drafts and confidence annotations.
A sample constraint prompt and validation skeleton:
SYSTEM = """You are a rigorous technical assistant.Rules: 1) Answer only based on the provided material; 2) When the material is insufficient, you must answer "insufficient material" and must not speculate;3) Annotate the source fragment ID after every conclusion; 4) Do not fabricate version numbers, parameters, or links."""def verify(answer: str, allowlist: set[str]) -> list[str]:issues = []for token in extract_numbers_and_ids(answer):if token not in allowlist:issues.append(f"Unauthorized identifier: {token}")if "insufficient material" not in answer and not has_citation(answer):issues.append("Missing source annotation")return issues
3. Overconfidence on Open-Ended Questions
When a question has no definite answer, some models still deliver categorical conclusions. This is the most dangerous bias in selection evaluation because it amplifies both error and trust. The engineering response is to route open-ended questions explicitly:
if is_open_ended(query):return {"mode": "scenario", "require": ["assumptions", "both sides", "uncertainty statement"]}
It is also advisable to include “unanswerable questions” and “questions with false premises” in the evaluation set to observe whether a model can clarify and ask back. A mature system should proactively ask follow-up questions when information is insufficient, rather than filling in the narrative.
4. A Reproducible Evaluation Set: Turning Subjective Feelings into Metrics
Build your own task set of 100–300 items covering the six dimensions above, each with an input, a reference answer, and a scoring script. Metrics can include:
- Factual accuracy (automatic field comparison for verifiable fields)
- Citation validity (whether citations really exist and are relevant)
- Refusal accuracy (whether the model refuses when it should)
- Task completion rate and human preference score (1–5)
Keep the temperature parameter, prompt version, and model snapshot fixed, and retain raw outputs for regression. Example:
cases = load_cases("eval/tasks.jsonl")report = {}for name, client in clients.items():rows = [run(client, c) for c in cases]report[name] = {"fact": accuracy([r for r in rows if r.kind == "fact"]),"refuse": refusal_accuracy([r for r in rows if r.kind == "no_answer"]),"pref": mean([r.human_score for r in rows]),}
5. Validation Methods for Multimodal and Structured Output Scenarios
Image understanding tasks often show a “answer anyway even when the target is not visible” pattern. An effective practice is to require the model to first output a bounding box or region description, then answer attribute questions; if it cannot locate the target, it should explicitly return not detected. For images where local and global semantics conflict (for example, a region resembles one thing while the overall scene is something else), the prompt should require distinguishing “local similarity” from “global recognition,” with coordinates or grid IDs used for cross-validation.
For structured output, enforce schema constraints and run a second parse:
schema = {"type": "object", "required": ["answer", "confidence", "sources"]}obj = json.loads(strict_parse(raw))assert 0 <= obj["confidence"] <= 1 and isinstance(obj["sources"], list)
6. Cost and Engineering Support
When the budget allows only one service, tiered calls can reduce cost: send simple intent classification and formatting tasks to a lightweight model, and complex reasoning and high-risk tasks to a stronger model, with caching and deduplication in between. On the engineering side, a logging service retains requests and outputs, monitoring and alerting track sudden spikes in refusal rate and validation failure rate, object storage holds evaluation samples and regression baselines, a container platform runs the evaluation pipeline, and a message queue smooths peak loads for batch offline evaluation. If you need elastic compute for fine-tuning or batch inference, you can evaluate the general container and storage product combinations offered by Baidu AI Cloud.
7. Concluding Recommendations
Do not decide based on a single experience. Run a two-track comparison on the same evaluation set over two weeks to two months, focusing on factual accuracy, citation validity, and refusal accuracy first, then subjective items such as writing experience. No model has a 100% accuracy rate; for high-risk content in medical, financial, legal, and similar domains, human final review and traceable sources must be retained. The goal of model selection is not to find a model that never makes mistakes, but to build a reliable system of “model + retrieval + validation + review.”
