LLM Selection for Production: A Practical Guide from Evaluation to Deployment
This article explains how to treat large language model selection as an engineering decision rather than a leaderboard exercise. It covers defining scenario constraints, breaking down evaluation dimensions, building a task-specific evaluation set, estimating real cost, and designing an abstraction layer that makes models replaceable.
1. Why Model Selection Is an Engineering Decision
LLM capabilities have iterated rapidly over the past year, and the number of available model options has increased significantly. Different models have different strengths in Chinese understanding, code generation, long-context processing, inference speed, and price. For developers, there is no longer a fixed answer to “which model is best.” The more practical question is: “Under my business scenario, budget, and compliance requirements, which model can consistently achieve acceptable results?”
A wrong selection decision costs more than simply switching models. Prompts need to be retuned, output formats need to be revalidated, cost estimates need to be recalculated, and user experience may fluctuate after launch. Therefore, model selection should be treated as an engineering decision that needs to be documented and reproducible.
2. Define Scenarios and Constraints First
Before selecting a model, write down the requirements clearly. This usually starts from five aspects.
- Task type. Q&A customer support, document summarization, code assistance, structured information extraction, multi-turn dialogue, and agent tool calling place very different demands on model capabilities. Extraction tasks place more value on stable output formats; coding tasks place more value on syntax correctness and context understanding; long-document tasks place more value on context window and information recall.
- Latency requirements. Interactive products usually require the time to first token to fall within a range acceptable to users, while batch tasks are more concerned with total throughput.
- Cost budget. Estimating monthly usage based on billed input and output units is much more reliable than estimating by feel.
- Data compliance. For data involving personal information, trade secrets, or industry regulation, you need to confirm the deployment method, data retention policy, and access permissions.
- Language and domain. Chinese expression conventions, industry terminology, and coverage of professional knowledge directly affect final results.
Organize these constraints into a table, and you will have a basis for screening candidate models.
3. Break Down Evaluation Dimensions
Capability evaluation should not rely only on aggregate leaderboards. Leaderboards reflect results on specific test sets and may not align with your business data. It is better to examine the following dimensions one by one.
- Instruction following: whether the model can strictly follow the required format, length, and tone.
- Reasoning and calculation: accuracy on multi-step reasoning, math, and logic tasks.
- Coding ability: success rate in generating, fixing, and explaining code, tested with real project snippets.
- Chinese capability: understanding of idioms, colloquial expressions, official document writing, and similar content.
- Context window: the actually usable length, as well as recall of information in the middle of long texts.
- Tool calling: whether function parameters are accurate and whether the model can correctly decide when to call tools in multi-turn dialogue.
- Structured output: whether formats such as JSON can reliably pass parsing, which is especially important for backend integration.
- Stability: result variance across multiple calls with the same input, as well as the service’s availability record.
Non-capability factors are equally important, including whether the API protocol is compatible with common invocation methods, whether documentation is complete, whether rate-limit policies are clear, and whether license terms permit your intended use.
4. Build Your Own Evaluation Set
The most reliable basis for selection comes from your own data. Building an evaluation set can be divided into four steps.
Step 1: Collect real samples. Extract typical requests from business logs, covering high-frequency scenarios, long-tail scenarios, and error-prone scenarios. The sample size does not need to be large; a few hundred labeled examples are enough for an initial comparison, but the distribution should be close to real traffic.
Step 2: Define scoring criteria. For tasks with standard answers, you can use exact match, keyword hits, or regex validation. For open-ended tasks, design a rubric, such as scoring factual accuracy, completeness, and language style separately, with manual sample review.
Step 3: Standardize test conditions. Only with the same system prompt, the same temperature parameter, and the same input order can you ensure a fair comparison. At the same time, record the latency, input and output length, and failure reason for each call.
Step 4: Analyze and archive the results. Do not look only at the average score; also examine the distribution of error types and performance on extreme samples.
Below is a general evaluation framework outline. The model invocation function needs to be implemented according to the API you actually use.
import timefrom dataclasses import dataclass, field@dataclassclass EvalCase:prompt: strexpected_keywords: list[str] = field(default_factory=list)def score_answer(answer: str, case: EvalCase) -> float:"""Score by keyword hit rate; return a value between 0 and 1."""if not case.expected_keywords:return 0.0hits = sum(1 for kw in case.expected_keywords if kw in answer)return hits / len(case.expected_keywords)def run_eval(call_model, model_name: str, cases: list[EvalCase]) -> dict:"""call_model is a function that invokes the model with signature (prompt: str) -> str."""scores, latencies = [], []for case in cases:start = time.perf_counter()try:answer = call_model(case.prompt)except Exception:scores.append(0.0)continuelatencies.append(time.perf_counter() - start)scores.append(score_answer(answer, case))return {"model": model_name,"avg_score": sum(scores) / len(scores) if scores else 0.0,"avg_latency_s": sum(latencies) / len(latencies) if latencies else None,"failures": sum(1 for s in scores if s == 0.0),}
Keyword matching is only a starting point. For complex tasks, another model can act as a judge, but the judge model itself may have biases, so human spot checks should still be retained.
5. Estimate Real Cost
For most usage-based model services, cost is determined by the number of input and output tokens. The cost of a single call can be estimated as follows.
Single-call cost = input tokens × input unit price + output tokens × output unit price
Monthly cost = single-call cost × average monthly request volume
Assume a summarization task has an average input of 2,000 tokens and an output of 300 tokens, with 100,000 requests per day. You then need to plug in the actual unit prices of each candidate service for calculation. The numbers here are only used to illustrate the method; specific unit prices are subject to the prices published by the service provider.
The following points are often overlooked in cost estimation.
- The longer the prompt, the higher the input cost per call. Trimming system prompts can often directly reduce spending.
- Failed retries are billed again, so the retry rate needs to be tracked.
- When output length is uncontrollable, a maximum output length limit should be set.
- Caching high-frequency requests with stable results can significantly reduce the actual number of calls.
6. General Principles for Integration Design
To make the model replaceable at any time, it is recommended to add an abstraction layer between business code and the model service.
- Unified interface. The business layer should depend only on an internally defined invocation interface and should not directly couple to any single provider’s SDK.
