LLM Selection and Scenario-Based Implementation: A Practical Guide
This article reframes large language model selection from a subjective "which model is best" debate into an engineering process. It breaks model capabilities into evaluation dimensions, organizes the technology stack by task rather than by model, and shows how to combine routing and fallback across models. It also covers building a regression-friendly evaluation suite, converting token pricing into business-level cost, engineering fallbacks for stability, and common pitfalls to avoid. Readers will get an actionable framework for choosing and operating models across evolving generations.
1. Reframing the Problem: From “Which Model Is Strongest” to “Which Combination Fits Best”
Once generative AI moved into the engineering phase, the most common question from teams shifted from “Can the model do the job?” to “Which one should we pick?” The original discussion listed models across different generations and sizes and reached a simple conclusion: use overall performance for general tasks and code capability for programming tasks. The direction is right, but the conclusion lacks an executable decision process. Without an evaluation set, a cost model, and a fallback plan, selection degrades into a debate over personal preference.
A better approach is to break the problem into three sub-problems: whether tasks can be clearly classified; what quality, latency, and cost constraints apply to each class; and how to combine multiple models through routing and fallback when a single model cannot satisfy all requirements. This article focuses on these three points.
2. Breaking Down Capability Dimensions: Do Not Decide on a Single Aggregate Score
Differences between models are often not about who is “smarter,” but about trade-offs across several dimensions. Build an evaluation table covering at least the following:
- Instruction following and structured output stability: whether valid JSON is produced consistently, whether fields are missing, and whether enum values drift.
- Effective utilization of long context: the context window length is only an upper bound; what matters is whether mid-context recall and cross-segment reasoning degrade.
- Code capability: this covers four sub-tasks—completion, cross-file refactoring, test generation, and error localization—which do not improve in lockstep.
- Trade-off between reasoning depth and latency: deeper thinking usually means higher latency and higher cost per call.
- Multimodal capability: image understanding, chart reading, and UI screenshot parsing are not isomorphic to pure text capability.
- Security and compliance: content filtering policy, data residency requirements, and completeness of audit logs.
Any claim of “ranked first overall” holds only under a specific evaluation distribution. Engineering decisions should be based on measurements against your own business distribution.
3. Scenario Tiering: Organize the Stack by Task, Not by Model
A stable practice is to tier tasks first, then bind candidate models to each tier.
- Interactive Q&A and content generation: prioritize response speed and natural expression; typically use a general model with lower latency.
- Code and structured extraction: prioritize syntactic correctness and format stability; requires strict mode constraints and validation.
- Complex reasoning and solution review: accept higher latency in exchange for stronger multi-step reasoning.
- Batch offline processing: throughput and unit price are the core metrics; queuing and retries are acceptable.
The routing pseudocode below illustrates the principle of “classify first, validate next, fall back last”:
def route(task):if task.type in ("code", "extract"):primary, fallback = code_model, general_modelelif task.type == "reason":primary, fallback = deep_model, general_modelelse:primary, fallback = general_model, cheap_modelfor model in (primary, fallback):out = model.invoke(task.prompt)if validate(task, out): # structural + business rule validationreturn outreturn degrade(task) # explicit degradation, not silent failure
4. Evaluation System: Replace Subjective Impressions with a Small, Regression-Friendly Sample
Subjective experience cannot support a procurement decision. Build a three-layer evaluation:
- Smoke set (dozens of cases): run on every change, covering core formats and red-line scenarios.
- Business set (hundreds of cases): sampled from desensitized real logs, stratified by intent, with reference answers or judgment scripts.
- Adversarial set: ambiguous instructions, extremely long inputs, injection attacks, mixed languages, and other edge cases.
Beyond accuracy, record P95 latency, cost per thousand calls, format failure rate, and human takeover rate. Evaluation must be regression-friendly: any change to the model or prompt triggers a full batch run, avoiding the situation where “the prompt changed and another scenario broke.”
5. Cost and Capacity: Convert Unit Price into Business Unit Cost
When comparing models, differences in input and output token pricing are often underestimated, and the amplification from retries and long context is even more pronounced. Use “cost per thousand successful business requests” as a unified measure, factoring in failed retries, validation overhead, and manual review time. Engineering measures include trimming prompts and history, semantic caching, batching requests, pre-filtering with a small model, and moving deterministic logic from the model to a rules engine.
6. Stability and Engineering Fallbacks
Model services are external dependencies and must support degradation: retry backoff for timeouts and rate limits, cross-model fallback, result caching, and rule-based fallbacks for critical paths. Also establish observability by bringing request volume, failure rate, reasons for format validation failures, and per-call consumption into logging, monitoring, and alerting to close the loop.
7. Engineering Implementation: An Example Using General Capabilities from Baidu AI Cloud
At the implementation level, you usually do not need to build infrastructure from scratch; you can reuse general-purpose cloud capabilities: object storage for evaluation sets and artifacts; a message queue for peak shaving and asynchronous batch processing; a container platform to host routing and validation services; logging and monitoring with alerting for observability; key management and access control for credential handling; and data masking and encryption for compliance. The capabilities Baidu AI Cloud offers in these general categories can serve as the foundation for building the pipeline described above; refer to the official documentation for specific specifications and pricing.
8. Common Pitfalls
- Using leaderboards instead of your own tests: conclusions do not transfer when distributions differ.
- Comparing only unit price and not success rate: failed retries eat up the cost advantage.
- Assuming longer context is always better: added noise lowers effective utilization.
- Lacking a degradation path: single-point dependency exposes failures directly to users.
- Tightly coupling prompts with models: version prompts and include them in regression.
9. Conclusion
Selection is not a one-time conclusion but a continuously running process: task tiering, dimension-based evaluation, cost conversion, routing and fallback, and an observability loop. Once this mechanism is in place, the impact of model generation turnover is confined to local configuration, and the team can focus on the long-term work of business and data quality.
