LLM Evaluation: From Capability Scores to Cost per Successful Task
Structured-output tasks can achieve full correctness across multiple LLM services while consuming several times different token budgets and costs. This article proposes a three-layer evaluation framework covering correctness, completeness and robustness, and cost; explains how to build a reproducible task set; attributes cost to context redundancy, output redundancy, retry amplification, and parameter settings; provides measurement pseudocode; and outlines model routing, context compression, constrained output, caching, batching, and closed-loop governance to make cost a first-class evaluation metric.
1. The Real Problem Behind the Phenomenon: Passing Quality Is Only the Baseline
In real projects, teams often see evaluation results like this: the same structured-output task—for example, generating a table file with a standardized format and complete fields from a natural-language requirement—is sent to multiple LLM services. The final outputs may all score full marks on field completeness, format compliance, and content accuracy. On the surface, the model-selection problem appears solved. But when the bills are compared, token consumption and cost for completing the same batch of tasks may differ by several times.
This shows two things:
- Capability dimensions have converged. For medium-difficulty structured generation tasks, mainstream LLM services can generally meet the requirements. Comparing only “which one gets it right” no longer provides differentiation.
- Cost has not yet been included in evaluation. Most teams’ evaluation scripts only validate outputs. They do not record input/output tokens, retry counts, or failure fallback paths, so cost remains a black box.
Therefore, the evaluation system must upgrade from “single-objective scoring” to “effectiveness–cost dual-objective measurement,” treating cost as a first-class metric.
2. Three-Layer Metric Design for Evaluation
It is recommended to split metrics into three layers and narrow them down layer by layer:
Layer 1: Correctness
- Structural validation: whether fields are complete, types are correct, and required fields are non-empty;
- Format validation: whether the file can be parsed normally by standard libraries, and whether encoding, delimiters, and headers are consistent;
- Content validation: whether numerical calculations, units, and date ranges are self-consistent.
Layer 2: Completeness & Robustness
- Instruction following: whether all constraints in the requirement are covered, including sorting, deduplication, and null-filling strategies;
- Boundary robustness: degradation behavior under overly long inputs, missing fields, and ambiguous wording;
- Consistency: variance across multiple samples of the same input, such as 3 runs, used to judge stability.
Layer 3: Cost
- Input tokens, output tokens, and cache-hit tokens are measured separately;
- Retry count and failure rate per task;
- Cost per successful task = total cost / number of successful tasks, not total number of calls.
The key point is that the denominator in the third layer must be the “number of successful tasks.” If only call fees are counted, a scheme with frequent failures and retries may look cheap, while its actual cost per effective output is high.
3. Task Set Construction: Making Evaluation Reproducible
The evaluation set must meet three conditions: it can be scored automatically, it covers the real distribution, and its scale is controllable.
Task set structure (illustrative){"id": "T-0007","instruction": "Summarize sales by region; output headers fixed as region/sales/percentage","input_ref": "dataset/sales_0007.txt","constraints": ["sort by sales descending", "keep percentage to two decimal places", "total row must be present"],"validator": "table_schema_v2","difficulty": "medium"}
Decoupling the grader from the task has an advantage: the same batch of tasks can be reused across different models, different prompt versions, and different parameter configurations, forming a comparable baseline.
4. Cost Attribution and Measurement Basis
Cost differences usually come from four sources. They must be recorded separately during evaluation; otherwise, the cause cannot be located:
| Source | Manifestation | Measurement method |
|---|---|---|
| Context redundancy | Input tokens far exceed the effective information volume | Input tokens / effective characters |
| Output redundancy | Output contains a large amount of explanatory text | Share of effective structure in output tokens |
| Retry amplification | Full regeneration after validation failure | Retry count × tokens per attempt |
| Improper parameters | High sampling temperature causes format drift | Correlation between failure rate and temperature |
Pseudocode for a unified measurement basis:
for task in eval_set:for attempt in 1..max_retry:resp = call_model(prompt=build_prompt(task),temperature=cfg.temperature)usage = resp.usage # input / output / cachedcost = usage.input * p_in + usage.output * p_outif validate(resp.content, task.validator):record(success=true, cost=cost, attempts=attempt)breakelse:record(success=false, cost=accumulated)report(metric = total_cost / success_count)
The unit prices p_in and p_out should be injected as configuration items rather than hardcoded, so that horizontal comparison across different cloud providers and billing models is possible. On platforms such as Baidu AI Cloud, general logging and monitoring/alerting capabilities can be used to report token usage and cost for each call, creating cost dashboards by business line and scenario.
5. Four Engineering Approaches to Cost Reduction
- Model routing: Tier tasks by difficulty. Route simple structured tasks to lightweight models and complex reasoning tasks to more capable models, using rules or a small classifier for front-end routing.
- Context compression: Remove duplicate instructions, first perform extractive summarization on long documents, and consolidate fixed instructions into a system prompt with cache reuse.
- Constrained output: Use explicit schema descriptions to constrain the output structure and reduce the generate–validate–retry loop. This is the most effective way to reduce retry amplification.
- Caching and batching: Cache results for high-frequency repeated requests; use batch interfaces for offline tasks, which usually have lower unit cost.
6. Closed-Loop Governance Process
Evaluation is not a one-time action. It should be solidified into a pipeline: version the task set → trigger regression whenever prompts or model parameters change → apply dual-threshold gates for output effectiveness metrics and cost metrics, for example, effectiveness not lower than baseline and cost per successful task not higher than 1.1× baseline → block release if thresholds are not met and output an attribution report. This turns “bill differences” from an after-the-fact surprise into something controllable in advance.
7. Implementation Checklist
- Separate the grader from the task set to ensure reproducibility;
- Use “cost per successful task” as the core cost metric;
- Instrument the four cost sources separately to avoid vague attribution;
- Include effectiveness and cost dual gates in the release process;
- Make unit prices and routing policies configurable to preserve horizontal comparison capability.
In summary: when multiple models all score full marks on the same task, model selection competition has shifted from “can it do it right” to “how much does it cost to do it right.” Bringing cost into the evaluation basis, together with routing, compression, constrained output, and cache reuse, is the key to translating technical selection into real engineering returns.
