How to Choose an LLM Rationally: Engineering Practices to Reduce Hallucinations

    This article explains how to select a large language model based on its worst-case behavior rather than benchmark rankings, and how to control hallucinations in production. It covers a three-part veto checklist, a measurable breakdown of hallucination types with a regression test skeleton, moving numeric reasoning into a code sandbox, evaluation dimensions for image generation and Chinese-language rendering, and architecture patterns such as a unified inference gateway that make quota and pricing changes observable. A four-step action list and a monthly re-evaluation cadence are included.

    1. The Real Problem: You Are Not Choosing the “Strongest” Model, You Are Choosing the Highest Floor

    When the budget only allows one of two options, many teams instinctively turn to public leaderboards. But leaderboards reflect average performance, while production incidents are determined by the worst case. Three criteria are therefore more reasonable: whether the model is willing to say “I don’t know” when information is insufficient; whether it hands numeric work to deterministic tools instead of guessing; and whether its multimodal output can be consumed directly by the business. Treating these three as veto conditions is usually more effective than running dozens more general-purpose Q&A samples.

    It is worth stressing that this capability landscape shifts fast, and the overall standing of different vendors can be reshuffled within a month or two. A selection decision should therefore be treated as an engineering assumption valid at a given point in time, not a permanent conclusion, and it must be paired with a repeatable evaluation process and periodic re-assessment.

    2. Hallucination Control: Breaking “Defensive Accuracy” into Measurable Metrics

    Hallucination is not a single phenomenon. It can be split into at least three types: factual fabrication (nonexistent papers, parameters, vendors), numeric fabrication (statistics, unit conversions, metric calculations), and citation fabrication (invented sources and links). For high-risk retrieval scenarios involving medical, materials, or compliance documents, the first and third types are fatal.

    The practical approach is to build a small regression set that covers the question distribution of your actual business, and to label every output:

    1. # Skeleton of a minimal hallucination regression evaluation
    2. cases = load_cases("domain_eval.yaml") # real business questions + expected "answerable / not answerable"
    3. for c in cases:
    4. r = call_model(c.prompt, tools=["search"], temperature=0)
    5. assert_json_schema(r, c.schema) # structural constraint
    6. if c.answerable is False:
    7. assert r.refused or r.evidence == [] # key: allow and encourage "not found"
    8. else:
    9. assert supports(r.answer, r.evidence) # conclusions must be backed by evidence

    The three most effective engineering constraints are: first, enforce “no evidence, no answer” by requiring the model to provide evidence before the conclusion, and to output an explicit not-retrieved message when there is none; second, push the temperature parameter to a low value and fix randomness, reducing the tendency to fill in gaps just to appear knowledgeable; third, apply structural constraints to the output (fixed fields, enumerated values) so that a missing field fails outright instead of being masked by natural language.

    3. Numeric Trustworthiness: Let Code Execution Replace “Mental Math”

    The easiest trap in ad-hoc personal data analysis is a model that directly produces a plausible-looking number. The reliable approach is to externalize the computation path: the model only generates analysis code and interprets the results, the actual numbers come from a code interpreter or sandbox, and the execution output is fed back into the conclusion.

    1. # Numeric conclusions must go through execution; the model may not produce numbers directly
    2. plan = model.plan(goal="compute mean and confidence interval grouped by cohort")
    3. result = sandbox.run(plan.code) # executed in the sandbox, with resource and network limits
    4. summary = model.summarize(result.stdout, evidence=result.log)
    5. # if the summary contains a number absent from stdout, treat it as untrustworthy and fall back

    Supporting engineering details include: limiting runtime and memory in the sandbox, blocking outbound network access to prevent data leakage, fixing random seeds for stochastic processes, and retaining full execution logs for review. This way, even if the model errs during reasoning, the error surfaces in an auditable execution layer rather than being disguised as a conclusion.

    4. Multimodal and Chinese-Language Context: Dimensions for Evaluating Image Generation

    If the business involves anime-style artwork, domestic game settings, or Chinese text layout, the focus of image capability evaluation has nothing to do with general aesthetics and everything to do with controllability: whether Chinese characters render correctly, whether setting details (costumes, color schemes, prop structure) follow the instructions, and whether a local edit affects only the specified region without breaking global consistency. Evaluation should fix the same batch of prompts and the same batch of edit instructions, with human raters scoring three dimensions—instruction adherence, detail consistency, and iteration cost—rather than judging the appeal of a single generated image.

    5. Cost and Risk: Write Quota Volatility into Your Architecture Assumptions

    Beyond model capability, long-term cost is also affected by changes to quota policies. Some AI coding tools have reduced the available quota for specific invocation modes in a version update without noting it in the changelog, and different services each have their own restriction policies. The rational architectural response is to build replaceability into the design:

    • Abstract a unified invocation layer that hides differences in authentication, rate limiting, and error codes across services;
    • Keep a fallback path for critical flows, switching to a backup implementation when the primary service is unavailable;
    • Set up monitoring and alerting for quota and latency, turning “silent downgrades” into observable events;
    • Decouple prompts, evaluation sets, and post-processing rules from any specific service to keep migration costs manageable.

    A sketch of the unified invocation layer:

    1. business code -> unified inference gateway (auth / rate limiting / retry / audit)
    2. |- adapter A: general chat and tool calling
    3. |- adapter B: code sandbox execution
    4. |- adapter C: image generation

    6. Conclusion and Action Checklist

    In a two-option, high-risk document retrieval scenario, prefer the option that is restrained about verification, admits uncertainty without evidence, and delegates numbers to code execution; it has the highest floor and the fewest traps. Image and Chinese-language capabilities should be evaluated separately as business-weighted items. Implementation proceeds in four steps: build a regression evaluation set that matches your business; write “no evidence, no answer” and structural constraints into the system prompt and the validation layer; move all numeric computation into the sandbox; and use a unified gateway plus monitoring to make quota volatility explicit. Because the capability landscape can change within a month or two, re-evaluate monthly against the fixed evaluation set so that selection decisions always rest on data rather than impressions.