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:

    1. Sample: stratified sample of 150–300 real requests from the last three months, covering high-frequency, long-tail, and edge cases.
    2. Label: define expected outputs and checkers per sample; prefer programmatic judges over human scoring when possible.
    3. Dual-track eval: full offline baseline; 5%–10% online traffic for canary comparison.
    4. Metrics: task success rate, format-compliance rate, P95 latency, cost per successful task, human takeover rate.

    Illustrative eval skeleton:

    1. # Pseudocode: model abstraction + eval runner
    2. from dataclasses import dataclass
    3. @dataclass
    4. class Case:
    5. prompt: str
    6. schema: dict | None
    7. checker: callable # programmatic judge
    8. weight: float = 1.0
    9. def evaluate(model, cases: list[Case]) -> dict:
    10. ok = total = 0.0
    11. fmt_fail, latency = 0, []
    12. for c in cases:
    13. t0 = time.perf_counter()
    14. out = model.generate(c.prompt, schema=c.schema)
    15. latency.append(time.perf_counter() - t0)
    16. if c.schema and not valid(out, c.schema):
    17. fmt_fail += 1
    18. ok += c.weight * bool(c.checker(out))
    19. total += c.weight
    20. return {
    21. "success_rate": ok / total,
    22. "schema_fail_rate": fmt_fail / len(cases),
    23. "p95_latency": percentile(latency, 95),
    24. }

    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

    1. Application code
    2. ↓
    3. Unified model gateway (auth / rate limits / cache / logs / metering)
    4. ↓
    5. Routing (by task type, complexity, cost budget)
    6. ↓
    7. 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

    1. Using public leaderboards instead of your own evals: mismatched distributions distort conclusions.
    2. Looking only at token price: ignoring retries and human review.
    3. Assuming a larger window is always better: poor mid-context recall injects noise.
    4. One-time selection: fast model iteration without a regression set repeats the same failures.
    5. 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.