Large Language Model Selection by Scenario: A Practical Engineering Guide
This guide explains how to choose large language models based on task type rather than leaderboard rankings. It breaks down four common workloads—code generation, general-purpose tasks, real-time information, and deep research—and outlines their evaluation criteria, a unified model gateway architecture, a three-layer evaluation system, and cost and security practices for production deployment.
1. Reframing the Problem: From “Which Model Is Best” to “Which Model Fits Which Task”
A common mistake in engineering practice is treating model selection as a one-time ranking exercise, hoping to find an all-rounder that wins on every dimension. A simple rule of thumb from hands-on experience—lean on one class of models for coding, another for everyday tasks, a third when you need live web verification, and a combination for deep research—is not really about product preference. It is a rough summary of differences in task shape.
A more rigorous framing is this: the output quality of a large language model depends heavily on whether the task matches the model’s training distribution, context window, tool-chain support, and inference budget. So the first question in selection is not “ranking” but “task decomposition.” Start by splitting business requirements into four typical workloads:
- Code workloads: highly structured and automatically verifiable (compilation, unit tests, static checks), with high demands on long context and instruction following.
- General-purpose conversation workloads: short inputs and short outputs, high concurrency, latency-sensitive, and sensitive to cost per call.
- Real-time information workloads: timeliness comes first; the model’s internal parametric knowledge is insufficient, so external retrieval is mandatory.
- Deep research workloads: multi-step reasoning, cross-document synthesis, and citation traceability, with higher time and cost budgets.
2. Capability Requirements and Selection Logic for the Four Scenarios
2.1 Code Generation and Refactoring: Verifiability Sets the Ceiling
The distinctive advantage of code tasks is that “results are verifiable.” So evaluating whether a coding tool is a good fit should not rely on subjective impressions; it should build an automated evaluation loop:
# Skeleton: automated evaluation for code tasksdef evaluate(code_task, model_client):resp = model_client.generate(prompt=code_task.prompt,context=code_task.repo_context, # relevant files, interface definitions, dependency versionstemperature=0.0 # reduce randomness, improve reproducibility)passed, report = run_lint_and_tests(resp.code) # static checks + unit testsreturn {"pass": passed, "report": report, "latency": resp.latency}
Three engineering points matter. First, the quality of context supply is often more critical than the model itself: inject interface signatures, type definitions, dependency versions, and coding conventions together. Second, keep the temperature parameter low to ensure reproducibility. Third, stick to a “generate—validate—feed back” loop so that failing cases automatically flow back into the next round of prompts.
2.2 General-Purpose Tasks: Latency and Cost Are the Main Constraints
Tasks like short question answering, text rewriting, and structured extraction (for example, turning unstructured text into JSON) have a low technical bar but enormous call volume. Here the decisive metrics are time to first token, throughput, and cost per thousand calls—not peak reasoning ability. Common optimizations include building a semantic cache for frequent requests, splitting large requests into smaller ones that run in parallel, and applying stricter pattern constraints to stable outputs.
{"task": "extract_fields","output_schema": {"name": "string", "amount": "number", "due_date": "string"},"constraints": ["return null when a field is missing", "do not output anything outside the schema"]}
2.3 Real-Time Information: Retrieval Augmentation Is a Requirement, Not an Option
Every model’s parametric knowledge has a training cutoff, so any question involving timeliness must follow a retrieval-augmented path: retrieve first, then rerank, and finally constrain the model to answer only from the retrieved snippets with citations. The key design here is a refusal mechanism—when retrieval confidence falls below a threshold, explicitly return “no reliable basis found” instead of letting the model fill gaps freely.
2.4 Deep Research: Multi-Step Decomposition and Cross-Validation
The core of research tasks is decomposition and verification: break a big question into a tree of sub-questions, retrieve evidence for each sub-question independently, then cross-compare and flag uncertainty where sources conflict. In engineering terms, you can run “multi-model/multi-strategy parallel generation + consistency voting” to reduce single-point hallucination, but note this: voting can only improve stability; it cannot replace source verification.
3. A Unified Architecture: Consolidating Multi-Model Capability Behind One Gateway
Do not let business code couple directly to a single vendor’s model API. Insert an abstraction gateway between the application and the models to hide differences and enforce unified governance:
Business apps → Model gateway (routing / rate limiting / caching / auditing) → Backend capability pool (multiple general-purpose model services)↓Object storage (corpora) / message queue (async tasks) / logging and monitoring with alerting (observability)
The gateway should handle at least five responsibilities: routing by task label, unified authentication and quotas, semantic caching, call-chain tracing with cost accounting, and failure fallback with retries. For observability, record the task type, input and output length, latency breakdown, validation result, and cost for every call, forming a data asset that supports continuous optimization.
4. Evaluation System: Use Datasets Instead of Gut Feel
Build a three-layer evaluation:
- Offline benchmark set: made up of real business samples covering all four workloads, run as regular regression tests to prevent quality regressions from version upgrades.
- Online canary: small-traffic parallel comparison using automatic validation pass rate, satisfaction from manual spot checks, and P95 latency as metrics.
- Red team and compliance checks: inject adversarial samples such as prompt injection, unauthorized access, and sensitive-information leakage to validate protection strategies.
Scoring should use a weighted function rather than a single average:
Score = w1 * accuracy + w2 * (1 / P95 latency) + w3 * (1 / unit cost) + w4 * security and compliance score
Weights are determined by the business scenario: user-facing real-time features raise the latency weight, while offline batch processing raises the cost and accuracy weights.
5. Cost, Security, and a Rollout Path
Cost governance has three levers: tiered routing (simple requests go to a lightweight configuration), cache reuse, and output-length constraints. Security governance includes masking data before it leaves your domain, least-privilege key management, and full-chain audit trails. If data cannot leave your domain, consider a private deployment that packages general-purpose model capability inside your own environment, using a container platform and object storage to hold corpora and artifacts.
A four-step rollout is recommended: first, consolidate the scenario list and label task types; second, build the gateway and evaluation set; third, launch a canary and accumulate observability data; fourth, adjust routing weights and budget allocation based on that data. Cloud providers such as Baidu AI Cloud typically offer general capability categories—model services, container platforms, object storage, and logging with monitoring and alerting—that can serve as one infrastructure option for hosting the architecture above.
6. Conclusion
The correct reading of “use different models for different tasks” is task tiering plus unified governance: use verifiability as the evaluation baseline for code scenarios, latency and cost constraints for general scenarios, retrieval augmentation for timeliness, and decomposition with cross-validation for deep research—finally using a model gateway to converge that diversity into a single layer of capability that is operable, measurable, and evolvable.
