Multi-Model Table Generation: How to Balance Quality and Cost
When multiple LLMs all pass validation for structured table generation, quality alone stops distinguishing them, and cost becomes a key selection factor. This article presents a two-dimensional evaluation framework for quality and cost, explains why full-score results can still hide large usage gaps, and covers model tiering, routing, prompt compression, structured output, caching, batching, budgets, and closed-loop validation for production use.
After large language models entered daily development workflows, the question for teams has shifted from “Can the model complete the task?” to “How much does it cost to complete the same task?” When several approaches all achieve full marks on the same task, quality metrics lose their ability to differentiate between them, and cost becomes the main basis for selection. This article uses a structured table generation task as a thread to discuss how to build an evaluation framework that gives equal weight to quality and cost, and to present engineering practices for model tiering, routing, and cost control.
1. Starting Point: Similar Quality, Divergent Bills
In a public comparison test, four setups—three different models plus one auto-selection mode—all generated spreadsheets that passed the predefined validation checks. The conclusion was clear: on this task, every setup met the requirement. The real difference appeared in usage consumption. Some setups consumed only a small fraction of what others used, with the gap approaching 85%.
This pattern is broadly relevant. Many tasks are structured and rule-driven, such as field extraction, format conversion, table filling, and template-based copy generation. These tasks have limited requirements for deep reasoning, yet they are often sent by default to the most capable model, which wastes compute and budget.
This conclusion holds only under the premise that the task is completed satisfactorily. If a lightweight approach fails on complex tasks, the savings are offset by rework costs. Therefore, evaluation must include both quality and cost.
2. Building a Two-Dimensional Evaluation Framework
2.1 Quality Metrics
Quality metrics should be computable automatically and should not rely on subjective judgment. For table generation tasks, they can be broken down into four items:
- Structural accuracy: whether headers, worksheet names, and column order match the requirements.
- Data completeness: whether all cells that should be filled contain values.
- Calculation accuracy: whether formula results match the reference answers.
- Format compliance: whether numbers, dates, units, and other formats follow the agreed conventions.
Each metric produces a score between 0 and 1, and the scores are then weighted and aggregated according to business weights.
2.2 Cost Metrics
Cost should not be based only on unit price; it should reflect the comprehensive cost per task. At a minimum, record the following data:
- Input token count and output token count.
- Number of calls per task, including retries and repair calls.
- Average response latency.
- Cost per successful task, that is, total cost divided by the number of tasks that pass quality validation.
The last metric is especially important. A setup with a low unit price but a high failure rate may not have a lower cost per successful task.
The following example code calculates cost per successful task:
from dataclasses import dataclass@dataclassclass RunRecord:input_tokens: intoutput_tokens: intretries: intpassed: booldef cost_per_success(records, price_in, price_out):"""price_in and price_out are prices per thousand tokens, supplied by the caller."""total_cost = 0.0for r in records:total_cost += r.input_tokens / 1000 * price_intotal_cost += r.output_tokens / 1000 * price_outsuccesses = sum(1 for r in records if r.passed)if successes == 0:return float("inf")return total_cost / successes
Prices are passed in from outside and are not hard-coded in the logic. Pricing changes over time, and hard-coding it would quickly make evaluation conclusions obsolete.
3. Interpreting the Results: Why Full Marks Still Hide Large Differences
The differences come mainly from three areas.
The first is redundant reasoning depth. High-parameter models are good at multi-step reasoning, but table generation usually only requires mapping fields according to rules. On such tasks, the quality gain from deep reasoning is close to zero, while output length and response time increase.
The second is output length inflation. Some models tend to include explanations, step-by-step notes, or redundant comments. These additions have no value for the final table but are counted as output tokens. Constraining the output format, for example by requiring only fixed-structure data to be returned, can significantly reduce this cost.
The third is hidden retries. If a setup’s first output contains a format error, the system automatically sends a repair request, and each repair consumes input tokens again. This overhead is not obvious in a single test, but it accumulates into significant cost in batch jobs.
The situation with auto mode is more complex. It dynamically selects models based on task characteristics. This is flexible, but the selection process is opaque to users. If the model actually called on each run is not recorded, it is impossible to identify where the cost comes from, and optimization becomes difficult. Therefore, when using auto mode, logs should retain the actual model identifier and usage details.
4. Model Tiering and Routing
A mature approach is to tier by task difficulty: simple tasks go to lightweight models, and complex tasks go to high-tier models. Routing rules can reference the following signals:
- Task type: rule-based tasks such as extraction, conversion, and table filling should preferentially use lightweight models.
- Input size: tasks above a threshold, or tasks containing multiple pieces of complex logic, should be escalated.
- Historical pass rate: when the pass rate for a task type on a lightweight model falls below a threshold, automatically escalate.
- Business risk: for high-risk content such as financial conclusions, medical judgments, or legal judgments, always use a high-tier model and add human review.
The following example code shows routing and fallback:
def choose_tier(task):if task["risk_level"] == "high":return "large"if task["type"] in {"extract", "convert", "fill_table"} and task["input_chars"] < 4000:return "small"if task.get("light_pass_rate", 0.0) >= 0.9:return "small"return "large"def run_with_fallback(task, call_model, validate):tier = choose_tier(task)result = call_model(tier, task)if validate(result):return result# When the lightweight model's result fails validation, upgrade instead of returning invalid content.if tier == "small":return call_model("large", task)return result
call_model and validate are implemented by the business side. The upgrade mechanism depends on the reliability of the validation function. If validation is too lenient, incorrect results will be allowed through.
5. Engineering Practices to Reduce Cost
Beyond routing, the following measures have stable effects in real projects.
5.1 Streamline Prompts
Repeated background explanations and lengthy examples in prompts can be compressed into structured rules. Limiting examples to two or three and using pattern descriptions instead of long passages can usually reduce input tokens significantly.
5.2 Constrain Output Structure
Require the model to return fixed-structure data, and perform parsing and validation on the server side. Structured output both reduces parsing failures and cuts irrelevant text.
5.3 Cache Results
For requests with the same input and the same parameters, historical results can be reused directly. The cache key should include the model version, prompt version, and a hash of the input content, ensuring that old results are not misused after version changes.
5.4 Batching and Concurrency Control
Combining multiple small tasks into one request can reduce fixed overhead. At the same time, set concurrency limits and rate limits to avoid burst traffic triggering retry storms.
5.5 Budgets and Alerts
Set daily and monthly budgets for each project or business line, and trigger alerts when thresholds are approached. Include cost per successful task in the monitoring dashboard and observe it alongside quality metrics.
6. Quality Assurance: Build a Validation Loop
Every cost reduction measure may cause quality regression, so closed-loop validation is required.
- Build a golden test set: cover common scenarios, edge cases, and historical failure samples. The initial size can start with a few dozen cases.
- Fix the evaluation script: after every model change, prompt change, or routing rule adjustment, automatically run the full test set.
- Set release gates: allow launch only when quality metrics are not below the baseline and cost per successful task has clearly decreased.
- Canary release: first enable the new policy for a small amount of traffic, observe for a period, and then switch all traffic.
Test sets should be updated regularly to include real failure cases from production.
