LLM Selection: An Evaluation Framework and Engineering Playbook
Choosing a large language model for production is an engineering decision, not a leaderboard ranking. This article outlines a four-dimension evaluation framework (capability, engineering, cost, and compliance), scenario-specific metrics, how to build an in-house eval set, a replaceable gateway architecture, common pitfalls, and a two-week rollout plan.
1. The real problem: selection is an engineering decision, not a ranking
Many teams frame model selection as “which model is strongest.” That question does not translate into a production decision. Capability is a multi-dimensional vector: reasoning depth, code correctness, long-context stability, multimodal understanding, instruction following, structured-output reliability, latency, per-token cost, and data-compliance boundaries. Leading on any single axis is not enough.
A more realistic premise: model release cycles are already measured in months or weeks. Today’s best option can be obsolete after the next version. The right goal is not “pick the one best model,” but a repeatable evaluation process plus a swappable integration architecture, so selection becomes an ongoing capability rather than a one-off event.
2. A four-dimension evaluation framework
2.1 Capability
- Reasoning and planning: accuracy on multi-step logic, math, and constraint-satisfaction tasks, and whether errors are detectable.
- Code: not only whether generated code runs, but whether it follows existing style, dependency versions, and interface contracts.
- Long context: the advertised window size is not the point; mid-context recall is. A large window with severe mid-span loss is a liability for long-document analysis.
- Instruction following and structured output: stable schema-compliant JSON, field-missing rate, and format-error rate.
- Multimodal: image and document understanding on real business assets, not public demos.
2.2 Engineering
API compatibility and migration cost, streaming support, concurrency and rate-limit behavior, timeout and retry semantics, SDK maturity, observability (token usage and latency breakdowns), and options for private or dedicated-cloud deployment.
2.3 Cost
Cost = input tokens × unit price + output tokens × unit price + retry waste + human review. A cheap model with a high format-error rate often costs more end to end. Measure cost per successful task, not price per token.
2.4 Compliance
Whether data is used for training, log retention, region and certification requirements, and content-safety filtering. This dimension is often a hard veto and should be first in the process.
3. Capability emphasis by scenario
| Scenario | Primary metrics | Secondary metrics |
|---|---|---|
| Coding assistant | Unit-test pass rate, patch correctness | Latency, context length |
| Document analysis and summarization | Mid-context recall, factual consistency | Cost |
| Structured extraction | Schema compliance rate | Latency |
| Content creation | Style control, instruction following | Multi-turn consistency |
| Multi-step agents | Tool-call correctness, task completion | Total cost per task |
There is no universal first choice—only a best-for-scenario model plus a fallback.
4. An in-house eval set is the only trustworthy signal
Public leaderboards almost never match your traffic mix. A practical process:
- Sample: stratified sample of 150–300 real requests from the last three months, covering high-frequency, long-tail, and edge cases.
- Label: define expected outputs and checkers per sample; prefer programmatic judges over human scoring when possible.
- Dual-track eval: full offline baseline; 5%–10% online traffic for canary comparison.
- Metrics: task success rate, format-compliance rate, P95 latency, cost per successful task, human takeover rate.
Illustrative eval skeleton:
# Pseudocode: model abstraction + eval runnerfrom dataclasses import dataclass@dataclassclass Case:prompt: strschema: dict | Nonechecker: callable # programmatic judgeweight: float = 1.0def evaluate(model, cases: list[Case]) -> dict:ok = total = 0.0fmt_fail, latency = 0, []for c in cases:t0 = time.perf_counter()out = model.generate(c.prompt, schema=c.schema)latency.append(time.perf_counter() - t0)if c.schema and not valid(out, c.schema):fmt_fail += 1ok += c.weight * bool(c.checker(out))total += c.weightreturn {"success_rate": ok / total,"schema_fail_rate": fmt_fail / len(cases),"p95_latency": percentile(latency, 95),}
checker and schema come from the product team. The eval set becomes a team asset you can rerun as models change.
5. Integration architecture: design for replaceability
Application code↓Unified model gateway (auth / rate limits / cache / logs / metering)↓Routing (by task type, complexity, cost budget)↓Primary pool + lightweight pool + fallback model
Three principles:
- One abstract interface: the product layer depends only on
generate(prompt, schema, options); model differences live in adapters. - Tiered routing: simple classification and extraction on lightweight models; hard reasoning on stronger models; automatic degrade-and-retry on failure.
- Caching and batching: semantic cache for high-duplication traffic; batch APIs for offline jobs, which usually cut unit cost.
On a public cloud, generic building blocks can host this design: object storage for eval sets and logs, a message queue for async work, containers for the gateway, and logging plus alerting for quality and cost. Generic cloud categories from providers such as Baidu AI Cloud can serve as that substrate; the actual choice should still follow your compliance and cost analysis.
6. Common mistakes
- Using public leaderboards instead of your own evals: mismatched distributions distort conclusions.
- Looking only at token price: ignoring retries and human review.
- Assuming a larger window is always better: poor mid-context recall injects noise.
- One-time selection: fast model iteration without a regression set repeats the same failures.
- Hard-coupling to a single vendor: without an abstraction layer, migration cost grows over time.
7. A two-week rollout
- Days 1–3: lock compliance boundaries, collect real samples, define checkers.
- Days 4–7: stand up a unified gateway and adapters; connect 2–3 candidates.
- Days 8–11: run full offline evals; produce a four-dimension comparison and cost per successful task.
- Days 12–14: small-traffic canary; auto-rollback on success-rate and P95 latency thresholds.
8. Closing
Mature selection means the same eval set can onboard and judge a new model within a week. Investing in eval sets, an abstraction layer, routing, and observability compounds more than chasing any single “strongest” model.
