Evaluating LLMs for Structured Output: Model Selection and Cost Control
As Large Language Models (LLMs) transition from proof of concept to production deployment, teams must balance task reliability with operational costs. This article explains how to evaluate LLMs for converting unstructured text into structured data, compare model costs, and implement intelligent routing to optimize both performance and budget.
When LLMs move from proof of concept (PoC) to production, the challenges teams face evolve. The focus shifts from whether the model can complete a task to whether it can do so reliably at an acceptable cost. Using the task of “extracting unstructured text into structured tables” as an example, this article illustrates how to design evaluations, compare model costs, and build intelligent routing. Note that the figures provided are illustrative; you should replicate the tests with your own data rather than applying them directly to your business.
Why Do Enterprises Face Both Capability and Cost Constraints?
Converting financial reports, contracts, and support tickets into Excel or CSV is a common enterprise requirement. Because the output is directly consumed by downstream systems, strict requirements apply to field names, delimiters, and data types. Such tasks demand strong instruction following, information location, and format control, but usually do not require peak reasoning capabilities.
Many teams default to flagship models. Flagship models excel at complex reasoning but come with high unit prices. Routing both simple and complex tasks through flagship models will cause the bill to scale linearly with call volume, while the quality gains may be marginal. Therefore, an evaluation method is needed to answer two questions: Which tasks require flagship models, and which can be handled by lightweight models?
How to Evaluate Structured Output Tasks?
The evaluation set must cover real business inputs. It is recommended to use stratified sampling based on document type, text length, and field count, retaining sufficient samples for each stratum. The smaller the sample size, the more susceptible the conclusions are to random factors.
Scoring is divided into two dimensions: quality and cost.
The quality dimension is broken down into three metrics:
- Field-level accuracy: The number of correctly extracted fields divided by the total number of fields to be extracted. Comparing field by field exposes issues better than simply checking if the entire table passes.
- Format compliance rate: The proportion of samples whose output can be directly parsed. Parsing rules should align with downstream systems, such as CSV quote escaping and consistent column counts in Markdown tables.
- Task pass rate: The proportion of samples where both field-level accuracy and format compliance rate meet the thresholds. These thresholds must be determined with stakeholders before the project begins.
The cost dimension is calculated using the following formula:
Cost per call = Input Token count × Input unit price + Output Token count × Output unit price
Token counts should be taken from the usage field returned by the model, not estimated by character count. Unit prices should be based on the vendor’s current public price list. The evaluation report must record the price version and date, as prices are subject to change.
It is recommended to record the results for each model in a table:
| Model | Price Version | Sample Size | Field-level Accuracy | Format Compliance Rate | Avg Input Tokens | Avg Output Tokens | Cost per Call | P95 Latency |
|---|---|---|---|---|---|---|---|---|
| Model A (Flagship) | Enter Date | Enter | Enter | Enter | Enter | Enter | Enter | Enter |
| Model B (Lightweight) | Enter Date | Enter | Enter | Enter | Enter | Enter | Enter | Enter |
The “pass” in the table only means the model meets the standard under this specific test set and scoring rules. Using a different batch of documents or different format requirements may yield different results.
Where Do Cost Differences in the Same Task Come From?
Cost differences primarily originate from three areas. The first is unit price. The second is input tokens, which depends on instruction length, the number of few-shot examples, and input text length. The third is output tokens, which depends on whether the model outputs redundant explanatory text. A model with a low unit price might ultimately prove expensive if it outputs excessive commentary. Therefore, all three factors must be evaluated simultaneously; looking only at the price list will lead to incorrect conclusions.
If several models have similar task pass rates on the same test set but significantly different costs, their capabilities for this type of task are comparable. This is where intelligent routing yields the most obvious benefits. Conversely, if a lightweight model’s pass rate is noticeably low, it should not be set as the default choice.
How to Choose Thresholds for Intelligent Routing?
Intelligent routing refers to a gateway distributing requests to the appropriate model based on request characteristics. Many cloud vendors offer unified interfaces for multiple models, or enterprises can build their own gateways. Regardless of the approach, routing strategies should be based on measurable metrics.
Here is a sample decision table; the thresholds must be calibrated using your own evaluation data:
| Task Type | Context Length | Token Budget | Preferred Model Tier | Format Failure Handling | Escalation Condition |
|---|---|---|---|---|---|
| Structured extraction with fixed fields | < 4K Tokens | Output limit based on field count | Lightweight model | Retry once | Escalate to flagship model after two consecutive format failures |
| Multi-step calculation or cross-segment reasoning | < 16K Tokens | Relaxed output limit | Flagship model | Retry once | None, use flagship model directly |
| Long document extraction | > 32K Tokens | Split first, then extract | Model supporting long context | Retry once | If split still fails, escalate to manual review |
Three points require attention during implementation:
- Set an upper limit for retries. Each retry incurs costs; unlimited retries can make the total cost exceed that of directly calling a flagship model.
- Complete format validation within the gateway. Trigger retries after JSON or CSV parsing fails to prevent erroneous results from entering downstream systems.
- Retest routing rules periodically. After model version updates or price adjustments, original thresholds may no longer be optimal.
After deployment, continuously monitor the following metrics:
- Format success rate: The percentage of outputs that can be parsed after a single call.
- Spot-check accuracy: Manual review of a certain proportion of live samples weekly.
- Flagship escalation rate: The percentage of requests routed to the flagship model. A continuously rising rate usually indicates that the routing rules for the lightweight model need adjustment.
- Retry rate: The percentage of requests requiring a retry.
- P95 latency: The response time upper limit for 95% of requests. Retries will push this metric higher.
- Cost per call: Statistics categorized by task type, rather than just looking at the total bill.
Can Caching and Fine-tuning Reduce Costs? Are There Boundaries?
Prompt simplification and fixed output formats are the most direct cost-reduction methods. Removing redundant explanations and placing output format constraints in the System Prompt can reduce input tokens.
Semantic caching is effective for repeated or highly similar queries. When a cache is hit, historical results are returned directly without calling the model. However, caching must handle privacy and data isolation properly:
- Cache keys must include tenant IDs and permission scopes to prevent one customer’s data from being read by another.
- Content containing personal information or trade secrets should be anonymized before caching, or not cached at all.
- Set expiration times to ensure timely invalidation when source data is updated.
- If the semantic similarity threshold is set too low, false hits will occur, returning irrelevant results.
Fine-tuning is another approach. If a task requires numerous few-shot examples to ensure formatting, you can use a small amount of high-quality data to perform Supervised Fine-Tuning (SFT) on a lightweight model. This transfers the formatting requirements from the prompt into the model’s capabilities, shortening the input length for each call.
The costs of fine-tuning include data labeling, training, evaluation, and model version maintenance. Fine-tuned models may also gradually degrade when data distribution changes. It is suitable for stable tasks with high call volumes and long, irreducible few-shot examples. For low call volumes or rapidly changing business requirements, optimize prompts and routing before considering fine-tuning.
Frequently Asked Questions
How to evaluate structured output?
First, build a stratified evaluation set. Then, compare models using three metrics: field-level accuracy, format compliance rate, and task pass rate. Simultaneously, record actual token usage and calculate costs to make an informed decision.
