Evaluating LLM Selection: A Methodology from Scenarios to Metrics

    A practical framework for choosing large language models: why leaderboards are the wrong question, how to map tasks to capability dimensions, how to build an in-house eval set, and how to combine routing, fallback, and quality–latency–cost trade-offs.

    1. “Which model is best?” is the wrong question

    In production, debates about general-purpose LLMs often collapse into leaderboard comparisons: who scored higher on a public benchmark, who looks “smarter” in a given release. That comparison is inefficient because it treats a model as a single scalar. Real workloads need a constrained set of metrics: answer quality, output stability, time to first token, cost per token, context window, structured-output success rate, and data-compliance constraints.

    Model capability is also not static. Different tiers from the same provider typically trade off reasoning depth, latency, and price. For the same tier, prompt, temperature, and tool-calling setup can matter more than the gap between models. The right question is: on my task distribution, which model stably meets the quality bar within acceptable cost and latency.

    2. An evaluation frame: task type × capability dimensions

    First, unpack “capability” into operable dimensions:

    • Reasoning and planning: multi-step logic, math, constraint satisfaction, problems that need backtracking.
    • Code: completion, cross-file refactor, unit-test generation, error localization, strict instruction following.
    • Long context: retrieval over long documents, cross-section consistency, reference tracking in long chats.
    • Multimodal understanding: extraction and description from images, charts, and scans.
    • Generation quality: style control, factual consistency, hallucination rate.
    • Structured output: JSON Schema adherence, function-call argument correctness.
    • Engineering properties: throughput, rate-limit policy, availability, version-change policy.

    Second, map tasks onto those dimensions. A customer-support summarizer mainly needs long context plus factual consistency; a coding assistant needs code ability, structured output, and low latency; a document-extraction pipeline needs multimodal plus structured output. Mapping gives evaluation a target.

    3. From public leaderboards to an in-house eval set

    Public leaderboards are useful for screening, not for decisions. Item mix rarely matches production, and contamination and prompt sensitivity are real. What matters is an in-house eval set:

    1. Sampling: draw real requests from production logs, stratify by scenario, keep tail and edge cases (empty input, oversized input, multilingual, sensitive fields).
    2. Labeling: give each sample a reference answer or a decidable rubric; for subjective items use multi-rater blind scoring and measure agreement.
    3. Fixed config: freeze and version temperature, max output length, system prompt, and tool definitions, or results are not reproducible.
    4. Regression: rerun when the model or prompt changes; track trends, not one-off scores.

    Record both quality and cost:

    1. # Illustrative eval structure only; not tied to any vendor
    2. @dataclass
    3. class Case:
    4. id: str
    5. scene: str # business scenario tag
    6. prompt: str
    7. reference: str | None
    8. rubric: dict # scoring dimensions and weights
    9. @dataclass
    10. class Result:
    11. case_id: str
    12. quality: float # normalized quality score
    13. latency_ms: int # end-to-end latency
    14. tokens_in: int
    15. tokens_out: int
    16. json_valid: bool # whether structured output parses
    17. def run_eval(cases: list[Case], client, workers: int = 8) -> list[Result]:
    18. # concurrent run + retry on failure + persist results for reproducibility
    19. ...
    20. def summarize(results: list[Result]) -> dict:
    21. # group by scene: quality mean/variance, P50/P95 latency, cost per request
    22. ...

    Reports should include variance, not only means. High quality variance implies heavier post-processing and fallback—hidden cost that is often ignored.

    4. Engineering constraints that are easy to underweight

    • Latency structure: time to first token drives interactive feel; total latency drives batch throughput. Measure both.
    • Cost model: unit price is not enough. Convert to expected tokens per successful task, including retries and validation.
    • Rate limits and quotas: concurrency caps and burst policy drive capacity planning and degradation design.
    • Version policy: behavior drifts with versions; pin versions or gate on regression.
    • Data compliance: whether inputs are used for training, log retention, and data residency are hard constraints, not optimizations.
    • Replaceability: easiest to ignore and most expensive later.

    5. Architecture: adapter, routing, and fallback

    Do not let one vendor’s API shape leak into business code. Keep a thin adapter:

    1. class LLMClient(Protocol):
    2. def chat(self, messages: list[dict], **opts) -> str: ...
    3. class Router:
    4. def __init__(self, clients: dict[str, LLMClient]): ...
    5. def pick(self, task: str, need_json: bool, budget_ms: int) -> LLMClient:
    6. # choose backend by task type, structured-output need, and latency budget
    7. ...
    8. def chat_with_fallback(router: Router, messages, **opts) -> str:
    9. client = router.pick(opts.get("task", "general"),
    10. need_json=opts.get("json", False),
    11. budget_ms=opts.get("budget_ms", 3000))
    12. try:
    13. return client.chat(messages, **opts)
    14. except (TimeoutError, RateLimitError):
    15. return router.pick("general", False, 10000).chat(messages, **opts)

    Pair this with three practices: structured-output validation and one-shot repair (retry once with the parse error), quality gating (rules or a light model as a second check), and end-to-end observability (scenario tag, backend id, tokens, latency, failure reason). On platforms such as Baidu AI Cloud, these are typically assembled from containers, logging and monitoring, and object storage for eval sets and archives—generic product categories, not a bind to a specific model.

    6. Trade-offs by scenario

    • Coding and structured generation: prioritize strict instruction following and low latency; validate with compile/tests/JSON Schema; replace subjective “strength” with verifiability.
    • Long documents and knowledge Q&A: prioritize long-context stability and citation traceability; use retrieval to cut hallucination; score whether answers are supported by source text.
    • Writing and style: highly subjective; use small-sample blind review plus style-consistency checks; multiple backends in parallel is acceptable.
    • Multimodal extraction: field-level accuracy and layout fidelity; low-confidence samples go to human review.
    • High-volume, low-value tasks: smaller models plus cache and batching; reserve stronger models for the long tail.

    7. Implementation checklist

    1. In about a week, build a 200–500 case stratified eval set from production logs.
    2. Freeze config and versions; run a reproducible eval pipeline.
    3. Produce a quality–latency–cost comparison and mark variance.
    4. Add an adapter plus routing and fallback so any backend is replaceable.
    5. Gate model or prompt changes on eval.
    6. Rerun quarterly; capability frontiers and pricing both keep moving.

    The conclusion is simple: model selection is not a one-time brand call. It is ongoing data engineering. With evaluation and a decoupled architecture in place, “which model” becomes a config you can change at any time.