How to Build a Reliable LLM Evaluation Framework for Model Selection
When call costs become a hard constraint, the right response is not a blind downgrade but a reproducible evaluation loop. Using a general-purpose LLM version upgrade as a case study (no specific vendor or product involved), this article explains how to build an evaluation setup that is reproducible, comparable, and extensible: why a single accuracy metric misleads decisions, how to segment the evaluation set by business domain, how to measure accuracy, average latency, token consumption, and cost per 1,000 calls together, and why a higher overall ranking can diverge from actual agent capability gains. It includes metric definitions, statistical conventions, illustrative code, and engineering recommendations for making rational model selection and routing decisions on a limited budget.
1. The Model Selection Dilemma Under Cost Pressure
Over the past year, LLM capability has improved far faster than engineering budgets have grown. A typical scenario: the product team wants the most capable general-purpose LLM to handle complex tasks, but once traffic ramps up, the token-based bill spirals out of control. The team then starts looking for a “better value alternative,” and the questions follow immediately. How much did quality drop after the swap? How much slower did responses get? Which scenarios can be downgraded, and which absolutely cannot?
The core tension is exactly this: flagship model pricing puts small and mid-sized teams off, while newly released general-purpose models claim improvements across context length, coding, reasoning, and tool calling. Such marketing claims offer limited value to developers, because they do not answer the three questions that actually drive engineering decisions:
- What is its accuracy on my traffic distribution, not on a public leaderboard?
- Do per-call latency and token consumption meet my production SLA and budget?
- Compared with the previous generation, is the improvement across the board, or was it bought at the cost of regressions in some capabilities?
This article therefore evaluates no specific product. Instead, it uses “a general-purpose LLM version upgrade” as raw material and abstracts a reusable evaluation methodology from it.
2. Evaluation Framework: Four Dimensions and One Prerequisite
A reliable selection evaluation must cover at least four dimensions, and all of them must be measured on the same test set with the same call parameters. Otherwise the numbers are not comparable.
- Accuracy (quality dimension): reported per business domain, not just as a single overall score.
- Average latency (experience dimension): end-to-end latency per call, including queueing and network overhead.
- Token consumption (efficiency dimension): input plus output tokens, which drives both cost and latency.
- Cost per 1,000 calls (economic dimension): determined jointly by token consumption and unit price.
One prerequisite is often overlooked: a frozen evaluation set and frozen decoding parameters. Temperature, maximum output length, whether streaming is enabled, and system prompt length all materially change the last three metrics. Without freezing them, a version comparison degrades into a noise comparison.
A dataset from the reference material can be abstracted into the following table structure (values are illustrative of the method only):
| Metric | Previous generation | New version | Change |
|---|---|---|---|
| Test cases | ~15,000 | ~15,000 | Flat |
| Overall accuracy | 66.6% | 68.7% | +2.1pp |
| Average latency/call | 98s | 59s | -39.8% |
| Average tokens/call | 2944 | 2851 | -3.2% |
| Cost per 1,000 calls | 38.8 CNY | 37.6 CNY | -3.1% |
| Overall rank | 20th | 10th | Up 10 places |
3. Metric Definitions and Statistical Conventions: Making Data Reproducible
In practice, evaluation results go wrong most often because metric definitions are vague. The following conventions should be made explicit:
- Accuracy: the number of samples judged correct divided by the number of valid samples. “Valid” must be defined (excluding timeouts, truncations, and refusals), as must the judging method (exact match, rule-based validation, or model review).
- Average latency: wall-clock time from request initiation to receipt of the complete response. If retries are included, that must be stated.
- Token consumption: taken from the usage field returned by the server, not a local estimate, to avoid tokenizer discrepancies.
- Cost per 1,000 calls: average token consumption × unit price × 1000, with input and output priced separately and then summed.
Illustrative evaluation main loop (pseudocode, structure only):
records = []for case in eval_set: # frozen evaluation sett0 = time.time()resp = client.chat(model=cfg.model,messages=case.prompt,temperature=cfg.temperature,max_tokens=cfg.max_tokens)latency = time.time() - t0usage = resp.usage # prompt_tokens + completion_tokensok = judge(case, resp.content) # rule-based or review modelrecords.append({"domain": case.domain, "ok": ok,"latency": latency,"tokens": usage.total_tokens,})def summarize(records, price_in, price_out):n = len(records)acc = sum(r["ok"] for r in records) / nlat = sum(r["latency"] for r in records) / ntok = sum(r["tokens"] for r in records) / ncost_per_1k = tok * (price_in + price_out) / 2 * 1000return {"acc": acc, "latency": lat, "tokens": tok, "cost_1k": cost_per_1k}
4. Reading the Results: A Higher Overall Score Does Not Mean Across-the-Board Gains
The most important warning for developers in the reference material is structural divergence. The new version improved its overall score by 2.1 percentage points and climbed ten places in the ranking, but the per-domain breakdown tells a different story:
- Law and public administration: 72.7% → 80.3% (+7.6pp), the largest gain;
- Education: 41.2% → 46.9% (+5.7pp);
- Healthcare and mental health: +3.7pp to 77.6%;
- Reasoning and math: +3.6pp to 65.8%;
- Finance: +0.8pp to 77.7%;
- Language and instruction following: 66.2% → 64.6% (-1.6pp);
- Agents and tool calling: 72.7% → 69.9% (-2.8pp).
Two conclusions follow. First, the overall score is a weighted average whose weights depend on the composition of your evaluation set. If your traffic is concentrated in instruction following and tool calling, a higher overall score means almost nothing to you, and may even indicate a regression. Second, a vendor’s claim of “stronger agent capability” and a decline in that dimension in third-party evaluations are not necessarily contradictory: the former may hold for specific toolchains and search-style tasks, while the latter covers a much broader distribution of tool-calling scenarios. The correct engineering practice is to rebuild the weights from your own business samples rather than inherit the weights of a public leaderboard.
At the same time, the latency drop from 98s to 59s is the most tangible benefit of this upgrade. For interactive applications, a 40% latency reduction often improves retention more than 2 percentage points of accuracy. Token consumption fell only 3.2%, which indicates that the cost improvement came from efficiency rather than unit price; with unit price unchanged, cost per 1,000 calls can only edge down.
5. Engineering Recommendations
- Tiered routing: split requests by task type, sending high-value complex tasks to the stronger model and high-frequency simple tasks to a lighter model, with rules or a small classifier making the upfront decision.
- Context budget governance: expanding the context window from 128K to 200K does not mean it should be filled. Longer contexts typically raise input tokens and time to first token, so pair them with retrieval and summarization to inject only the necessary fragments.
- Prefer structured output: when downstream parsing is required, use JSON mode or strict schema validation to reduce the token and latency amplification caused by retries.
- Caching and batching: cache results for highly deterministic requests; merge offline tasks into batch calls, trading throughput for cost.
- Observability: feed accuracy, P50/P95 latency, token distribution, and cost into logging and monitoring with alerting, build dashboards per business dimension, and run weekly regression checks.
- Regression gates: any model or prompt change must run the frozen evaluation set, and releases are blocked when metrics degrade beyond a threshold.
If you need elastic compute to run batch evaluations and offline inference, a general approach is a container platform combined with object storage and a message queue, which decouples tasks and scales on demand. Baidu AI Cloud offers corresponding product categories for these general capabilities, which can be combined as needed.
6. Conclusion
The right response to “we cannot afford the flagship model” is not a blind downgrade but building your own evaluation loop: freeze the evaluation set and decoding parameters, recompute weights per business domain, compare accuracy, latency, tokens, and cost in a single table, then use tiered routing and context governance to bring cost down. Once you can explain on a single dashboard whether an upgrade is a net gain or a net loss for your business, model selection stops being a matter of opinion and becomes an engineering problem.
