LLM Selection and Engineering Practices: A Practical Guide
This guide reframes large language model selection as a constrained optimization problem rather than a leaderboard contest. It breaks model differences down by capability dimension, shows how to build an internal evaluation benchmark, and outlines robust architecture patterns, cost and compliance pitfalls, and a phased rollout plan for production LLM applications.
1. The Real Problem: From “Which Model Is Best” to “Which Combination Fits”
Early model comparisons often relied on anthropomorphic labels, summarizing each model’s “personality” in a witty one-liner. That works for casual conversation but fails in engineering decisions: it provides no reproducible evaluation conditions and says nothing about task type, context length, tool-calling needs, or cost constraints. The professional approach is to restate selection as a constrained optimization problem—given a task distribution, latency budget, unit cost ceiling, and compliance requirements, choose the model or model combination that maximizes overall return.
The first conclusion to make explicit: there is no universal best choice. A model that excels at code completion may be poor at long-document extraction; a model with natural writing style may be mediocre at structured output and function-calling reliability. So the first step is not to look at leaderboards, but to decompose your business into a measurable set of tasks.
2. Breaking Down Model Differences by Capability
2.1 Code and Structured Generation
Coding tasks break down into completion, cross-file refactoring, unit test generation, defect localization, and migration or upgrades. Evaluation should go beyond “can it produce a runnable snippet” and look at three things: first, dependency tracking in long contexts—can it locate the real call chain within tens of thousands of lines; second, adherence to tool calling and schema constraints—can it reliably return structured results that match a given schema; third, self-verification tendency—does it proactively construct edge cases and run validation.
A sample snippet for constrained output:
schema = {"type": "object","required": ["action", "target", "params"],"properties": {"action": {"enum": ["create", "update", "delete"]},"target": {"type": "string"},"params": {"type": "object"}}}# Declare the output schema explicitly on the request side, then validate the response locally and retry
The more reliable engineering pattern is “model output + local validation + bounded retries,” rather than blindly trusting the model to return a valid result on the first try.
2.2 Long-Context Understanding and Writing
For writing tasks, the key metrics are factual consistency, instruction following, and style controllability. Prepare three sample types for evaluation: summarization tasks that require strict citation of the source, polishing tasks that require multiple rounds of revision, and normalization tasks that require consistent terminology. The focus is on whether the model loses constraints in the middle sections of a long context, and whether it tends to mask missing information with ornate phrasing.
2.3 Tiering Reasoning and Cost
Reasoning intensity and expense are basically positively correlated. A workable strategy is to split requests into three tiers: a lightweight tier for classification, extraction, and format conversion; a middle tier for routine Q&A and code completion; and a heavy tier reserved for complex reasoning and difficult defect analysis. Routing most traffic to the low-cost tier is the most effective way to control the bill.
2.4 Multimodality and Ecosystem Integration
If the business involves images, tables, or scanned documents, pay attention to the model’s understanding of layout structure and the precision of its output localization. Also consider whether the cloud ecosystem is complete—object storage, message queues, container platforms, logging services, and monitoring and alerting are common categories that determine whether an application can move from demo to production.
3. Build Your Own Evaluation Benchmark
Leaderboards are only for initial screening. Build an internal evaluation set of 100 to 300 items that covers the real business distribution, and define automatically verifiable acceptance criteria for each sample:
Suggested evaluation weights (example)- Task success rate (automatically verifiable) 40%- Human preference score (double-blind review) 25%- P95 latency 15%- Cost per task 15%- Safety/compliance block rate 5%
Fix versions and parameters during evaluation, and record temperature, max output length, and system prompt; otherwise the data is not comparable. Rerun on every model or prompt change to form a trend curve, rather than a one-time conclusion.
4. Robust Design at the Architecture Level
Dependence on a single model is a common source of production incidents. Three patterns are recommended: primary-backup switching, where the system automatically degrades when the primary model errors or times out; capability dispatch, routing by task label to different models; and cross-validation of results, using a second model to review high-risk outputs. Combined with a caching layer and request batching, this can significantly reduce repeated overhead.
Observability is equally critical. Log request IDs, model IDs, prompt versions, token usage, latency segments, and failure reasons, and set cost budget alerts. Without fine-grained logs, neither cost optimization nor security auditing is possible.
5. Cost, Compliance, and Common Pitfalls
Common pitfalls include: looking only at unit price while ignoring the hidden cost of retries; treating demo performance as production stability; overlooking the nonlinear cost growth caused by context expansion; and sending sensitive content to external services without data classification. For compliance, define data residency, masking policies, and audit trails clearly, and for sensitive scenarios prefer controllable private or dedicated resource options.
6. Recommended Rollout Path
Step one: define the task list and acceptance criteria. Step two: build a small-scale evaluation set and run a baseline. Step three: implement routing, caching, and degradation. Step four: roll out gradually and keep running regression tests. Step five: re-evaluate quarterly, because model capabilities iterate quickly and conclusions from six months ago are often already outdated. If you use Baidu AI Cloud capabilities, you can reuse its model services and general cloud infrastructure directly, focusing your effort on the evaluation system and business refinement rather than rebuilding underlying operations.
