LLM Selection for Production: Taming Hallucination and Ensuring Stability
This article reframes large language model selection around worst-case operability rather than benchmark averages. It breaks the decision into five dimensions, explains how to turn hallucination defense into measurable metrics with evidence-first prompting and explicit abstention, shows how to route numerical work to a sandboxed interpreter, outlines controllability checks for multimodal generation, and gives a cost model based on cost per successful task along with a practical rollout order.
1. The Real Problem: Choose the Best Floor, Not the Strongest Model
When the budget only allows two candidates, most teams start by comparing general-purpose leaderboards. For real business workloads, a more important metric is the floor: under the most uncertain inputs, does the system stay controllable? A model that is occasionally impressive but fabricates omitted details is often unusable in healthcare, finance, and legal settings. A model that says “not found” when it cannot find something may look mediocre at its ceiling, yet it significantly reduces review costs.
The selection objective should therefore be rewritten from “average performance” to “worst-case operability,” split into at least five dimensions:
- Factual consistency: whether the model tends to invent entities, numbers, and sources when evidence is insufficient.
- Retrieval restraint: whether it can correctly express “no conclusion” instead of forcing an answer.
- Tool-based computation: whether numerical tasks are handed to an interpreter rather than relying on the model’s mental math.
- Multimodal generation: how well generation tasks such as images handle Chinese-language context, proprietary settings, and local edits.
- Engineering stability: predictability of quota policies, rate limiting, account rules, and billing.
2. Hallucination Governance: Make Defensive Accuracy a Measurable Metric
Hallucination is not a single defect but a stack of three problems: a training objective that favors fluent continuation, insufficient contextual evidence, and the absence of an external verification step. The actionable approach is “evidence first, abstention allowed.”
State evidence boundaries and abstention semantics explicitly in the system prompt:
Rules:1. Answer using only the content provided in <context>, and cite the source number at the end of each sentence.2. If <context> is insufficient to support a conclusion, output only: INSUFFICIENT_EVIDENCE.3. Do not speculate about material parameters, vendors, batches, standard numbers, or any other entities not present in the context.4. All numerical conclusions must be produced by tools; mental arithmetic is prohibited.
Build the evaluation set with stratified sampling by “answerable / unanswerable,” at least 100 items per category, and track three metrics: accuracy on grounded answers, fabrication rate without evidence (lower is better), and correct abstention rate. In practice, the correct abstention rate and the unsupported fabrication rate are strongly negatively correlated; improving the former usually means lowering the latter.
3. Numerical and Data Analysis: Let the Interpreter Do the Math
For statistics, unit conversion, and experiment data processing, position the model as a “code generator plus result interpreter.” Execution goes to a sandboxed interpreter so the model never outputs numbers directly.
# Example: a constrained numerical analysis pipelinedef analyze(df, question: str, run_code):plan = llm.generate(f"Output pandas code only; hardcoding any numeric value is prohibited. Question: {question}")result = run_code(plan, df) # sandboxed execution with timeout and resource limitsreturn llm.summarize(result) # interpret the real output only
Engineering requires three guardrails: sandbox isolation with timeout limits, pinned dependency versions, and logging of both results and code so runs can be recomputed. This way, even a flawed analysis plan from the model surfaces at execution time instead of flowing downstream disguised as a precise number.
4. Multimodal Generation: Controllability Over a Single Stunning Image
The core pain point of generation tasks is that “fixing one spot breaks everything else.” Fix a test set covering Chinese-language context, proper nouns, complex layouts, and local edits, then evaluate instruction following, text and structural stability, consistency across repeated samples, and whether the content safety and copyright compliance chain is complete. Production also needs content moderation, generation log retention, and quota management so uncontrollable output never reaches the business directly.
5. Cost and Stability: Write Rule Predictability into the Selection Sheet
The real cost of an LLM service is more than unit price; it also includes retries, long context, rate-limit waiting, and human review. Account for it as cost per successful task: total cost = (number of calls × unit price + failed-retry cost + review labor) / number of successful tasks. Also check the notification mechanism for quota and policy changes, the completeness of changelogs for version updates, and whether common cloud components such as monitoring and alerting, logging services, and message queues are available to absorb rate limiting and degradation. If your organization already uses relevant common capabilities from Baidu AI Cloud, you can bring quota monitoring, audit trails, and degradation policies into a unified governance scheme, reducing migration risk from vendor lock-in.
6. Conclusion and Rollout Order
When the budget is tight, prioritize the option with better defensive accuracy, more stable tool calling, and more predictable rules, and defer ceiling concerns to phase two. Suggested rollout: first build a 100–200 item stratified evaluation set and an abstention spec, then add sandboxed computation and logging, and finally complete multimodal and cost monitoring. Keep in mind that industry capabilities reshuffle every two to three months, so any conclusion should be bound to an evaluation set and a version number, using reproducible data instead of long-term promises.
