↓ Skip to main content

Cutting the Cost of Classification: Small Models and Strict Schemas

·2649 words·13 mins·Mathusuthan

High-volume applications like classification, routing have high number of input tokens and less output. While we cannot reduce input costs, we can try to limit the output tokens since they are charged 5x times the cost of input tokens!. This post breaks down the cost with and without the architecure fix and explains the change you can make to reduce costs.

What kind of application is this ?
#

This archetype reads a piece of unstructured text and returns a short, fixed answer. The text can be a support email, a call transcript or a seller’s product feed. The answer is a label, a queue name, a yes/no flag or a list of data types. Software reads the answer and acts on it. Usually, no person reads it.

Each call is a single request with no memory of earlier calls. The work is high volume: a large retailer can have millions of items each week. Each answer must also be fast, because a customer or a queue is waiting for it.

The deck gives three use cases. The prompts below are the ones the NovaMart lab used, except where a card says otherwise.

1

Omnichannel support

Read each new ticket from email, chat or voice. Choose the queue, the priority and the next action.

Input

"My office chair order shows label created, awaiting carrier pickup for 5 days. I need a scan trace and a new delivery date before Friday."

Prompt

NovaMart Tier-1 Triage Classifier. Classify the payload strictly according to the JSON schema. Emit only compact schema fields. Do not repeat input text.

Output

{
  "queue": "shipping_logistics",
  "priority": "P2_MEDIUM",
  "auto_action": "route_specialist"
}

2

PII and compliance masking

Find personal data in the text, for example card numbers, phone numbers and tax IDs. Mark it, so that it can be hidden before the text goes to other teams.

Input

"…my Visa card 4532-8910-4421-0099 got charged twice. Call me back at 415-555-0194 or email priya.nair@customer-demo.example…"

Prompt written for this post

Find the personal data in this message. Return true or false for contains_pii. List each type you find. Choose types only from: PAYMENT_CARD, PHONE, EMAIL, AADHAAR, TAX_PAN_ID, BANK_ROUTING.

Output

{
  "contains_pii": true,
  "pii_categories": [
    "PAYMENT_CARD", "PHONE", "EMAIL"
  ]
}

In the lab, the model only finds the types. A fixed pattern-matching step then replaces the values with [REDACTED]. That step is fast and gives the same result each time.

3

Catalog tagging

Read a seller's new product listing. Choose its category. Check if the listing contradicts itself or is missing a safety certificate.

Input

A kurta listed as "100% pure mulberry silk". The scan of its care label says "80% polyester / 20% viscose".

Prompt

NovaMart Tier-1 SKU Gate Classifier. Classify category, hazmat class, contradictions, and publish status strictly according to the JSON schema. Emit only schema fields.

Output

{
  "leaf_category": "apparel_ethnic_kurtas",
  "contradiction_detected": true,
  "compliance_status":
    "SUPPRESS_CONTRADICTED_FACET"
}

How I tested it. The NovaMart lab built two of these tasks: support ticket triage and seller SKU tagging. NovaMart is a made-up retailer, and all of its data is synthetic. There were 12 test items, 6 for each task. Each item has a known right answer on 3 or 4 fields, 42 fields in total. I ran four set-ups on every item, three times each. That is 144 live calls to the model APIs. This is a small sample, so read the results as what I saw in one lab, not as a benchmark.

The token profile and cost dynamics
#

The deck gives this profile for the archetype:

INPUT PER CALL
500 to 1,500 tokens
Tickets, emails, transcripts, product feeds
OUTPUT PER CALL
10 to 100 tokens
Labels, routing tags, masked fields
INPUT TO OUTPUT
20:1 to 50:1
The deck calls this “heavy input asymmetry”
OUTPUT PRICE
5 × input price
True for both Sonnet 5.5 and Haiku 5.5

“Heavy input asymmetry” means the model reads much more than it writes. An output token costs 5 times as much as an input token. But at 20 input tokens for each output token, the input still makes 80% of the bill (20 ÷ (20 + 5)). At 50:1, the input makes 91%. So in this archetype, the input should drive the cost.

That is only true when the output stays short. A short output does not happen by itself. The prompt must ask for it.

Here is a real example from the NovaMart lab. A customer’s parcel is stuck at the warehouse. The system prompt asks for a “thorough, helpful” analysis in four parts. It does not list the allowed queues or priorities.

Example: one support ticket, free-text answer (Sonnet 5.5)

System prompt

Ticket (the user message)

Answer

The prompt and the ticket were 336 tokens. The answer was 2,456 tokens, more than 7 times the input. 97% of the cost of this call came from the output. It took about 20 seconds. And after all that text, the router still does not have the values it needs. It needs one value from a fixed list for each field. The answer says “Fulfillment Operations / Carrier Exceptions” and “P2 (High)”. Neither is in the list. A second model could map the queue to shipping_logistics. It could not map the priority, because in NovaMart’s list P2 means medium, not high.

This was not one bad answer. In all 72 free-text runs, the median answer was 2,283 tokens on Haiku and 2,739 tokens on Sonnet.

The free-text answer turns this archetype upside down. It is no longer input-heavy. It is output-heavy, and output is the expensive part.

The architectural lever
#

The deck’s lever for this archetype is: “Route to Flash/Lite models with strict JSON schema output and batching to cut unit cost by more than 80%.” This lever has three parts. You can use each part alone, but they work best together.

1. Use a small model
#

Flash and Flash-Lite are Google’s small Gemini models. Haiku is Anthropic’s small model. A small model costs less for each token and answers faster. Most providers have one.

ModelInput ($ per million tokens)Output ($ per million tokens)
Claude Sonnet 5.52.0010.00
Claude Haiku 5.50.100.50

Haiku costs 20 times less for each token. A classification task does not need deep reasoning. The model must read the text and choose one value from a short list. A small model can do that well. In the lab, Haiku did the same job for 95% less than Sonnet. It was also faster: 1.4 seconds against 2.0 seconds.

You do not have to choose only one model. With model routing, the small model takes all items first. Only the hard cases go to a larger model.

2. Ask only for the fields, and enforce a JSON schema
#

A JSON schema is a list of the fields you need. For each field, it gives the allowed values. You send the schema with the request. The API then makes sure that every answer matches the schema. This is called structured output.

This is the schema for support triage, shortened:

{
  "queue":       ["replacements", "billing_payouts", "trust_and_safety",
                  "shipping_logistics", "general_support"],
  "priority":    ["P0_CRITICAL", "P1_HIGH", "P2_MEDIUM", "P3_LOW"],
  "contains_pii": true | false,
  "auto_action": ["escalate_security", "hold_and_audit",
                  "auto_replace", "route_specialist"],
  "reason_code": ["TRANSIT_DAMAGE", "SETTLEMENT_HOLD_LEGAL",
                  "ACCOUNT_TAKEOVER", "POLICY_INQUIRY", "DELIVERY_DELAY"]
}

The schema does two things. It stops the long write-up, because the model can only fill in the fields. And it makes every answer usable, because each value comes from the allowed list.

Compare the two answers for the same stuck-parcel ticket. Choose a model, then read the request and the answer for each design.

Same ticket, two designs

Without Free-text write-up

System prompt

Answer

Fields the router can use

    With Fields only, JSON schema

    System prompt (the schema is sent with it)

    Answer

    Fields the router can use

      Recorded answers from the lab (first of three runs). Cost is for this one ticket. To decide if a free-text answer gives a usable field, a separate model (Opus 5.5) read it without the right answer.

      The schema request has more input: 934 tokens against 336, because the schema goes with every call. But the output falls from 2,456 tokens to 89. On Sonnet, the cost of this ticket fell by 89%. The answer arrived in under 2 seconds, not 20.

      The chart shows the same change across all the lab runs. It compares the deck’s profile with the median call for each design. Use the buttons to change between token counts and cost.

      Where the tokens and the cost go, for each call

      Medians from the lab runs. Cost shares are the same on Sonnet 5.5 and Haiku 5.5, because on both models an output token costs 5 times an input token.

      With the schema, the call goes back to the profile the deck expects: input makes most of the cost again.

      What saves the money: the schema or the short request? The lab also tried a third design. It asked for the same fields as plain text lines, with the allowed values in the prompt, but with no schema. It got the same fields correct as the schema design and cost about 23% less, because it sends no schema. So most of the saving comes from asking only for the fields. The schema adds a little input cost. In return, it guarantees that every answer has the right format.

      3. Batch the work that can wait
      #

      Not every item needs an answer in two seconds. New product listings can wait until tomorrow morning. A daily audit of yesterday’s tickets can wait too. For this work, use batching.

      You send many requests in one batch job. The provider runs them when it has spare capacity and returns the results later, within 24 hours. In return, the price is 50% lower, for both input and output. The prompt, the schema and the answers stay the same. Only the price and the wait change.

      DesignModelCost per 1,000 items ($)With the Batch API ($)
      Fields, JSON schemaSonnet 5.53.771.88
      Fields, JSON schemaHaiku 5.50.1880.094

      The lab did not run a batch job. These batch prices are calculated from the published 50% discount.

      Do not batch live work. A customer on chat, or a fraud ticket like “my account was hacked”, needs the answer now.

      4. Does the small model give the same quality?
      #

      With the schema, almost. The chart shows how many of the 126 checked fields each design got right (42 fields, 3 runs each).

      Fields correct, of 126

      Higher is better

      Each field is compared with the known right answer. For a free-text answer, a field counts only if one allowed value can be read from it.

      Three points stand out:

      • The schema raises quality on both models. The free-text answers got 69 of 126 fields on both models. Often they gave a sensible answer that was not in the allowed list, for example “P2 (High)” or “Hold, pending verification”. No free-text answer named an allowed automatic action (0 of 18 on both models).
      • With the schema, the models are close. Sonnet got all 126 fields. Haiku got 120. All 6 misses were on 2 of the 12 items. On a seller payout dispute, Haiku chose “critical” and “escalate to security” twice, where the right answer was “high” and “hold and audit”. On a damaged-goods ticket, it chose the wrong queue and action once.
      • Why the gap is small. The schema gives both models the same short list of choices. The task becomes “pick one of four values”, not “write a good analysis”. A small model is good at picking from a list. The schema also removes format errors: in 72 schema runs, every answer was valid.

      Before you switch models, test the small model on your own items with known answers. If a few hard item types fail, send only those to the larger model.

      The cost savings
      #

      The chart starts with a free-text write-up on Sonnet. Each step adds one part of the lever. Select a step to see what it saves.

      Cost of the same classification work, step by step

      Lower is better

      Show as a table

      Average cost from 36 runs per design, at the rate card above. NovaMart's story has 5 million items a week; the weekly figures multiply the lab's cost per item. The batch step is calculated, not run.

      The two biggest steps are the first two. Asking for fields with a schema cuts 87% on Sonnet. Moving that work to Haiku cuts 95% of what is left. Together they take the cost from $29.50 to $0.19 per 1,000 items, a 99.4% cut, and the fields correct go up from 69 to 120. The deck’s claim of “more than 80%” holds with a large margin. Each of the first two steps clears 80% by itself.

      The order matters less than you might think. If you move the free-text write-up to Haiku without the schema, the cost falls 96%, to $1.25 per 1,000 items. But the quality stays at 69 of 126, and the answers are still slow and hard to parse. A cheaper model does not fix a bad request.

      Bonus architectural lever
      #

      A language model writes its answer one token at a time, and you pay for each one. A decision model works differently. You send the text and a fixed set of questions. Each question has a fixed set of options. The model returns a choice for each question. It writes no text, so there are no output tokens to pay for.

      The NovaMart lab tried one: Gemini Decision 1, through a decisions API. It ran on the same 12 items, three times each.

      Decision model against the best language-model designs

      Weekly cost at 5 million items. The decision model's price ($0.10 per million input tokens, $0 output) comes from the lab's code. I did not check it against a published price list.

      The decision model cost about half as much as Haiku with the schema (−47%), and it answered in about half a second. It got 123 of 126 fields. All 3 misses were the same: on a business customer’s invoice request, it said there was no personal data, in all three runs. The ticket had a company email address.

      Three points before you use one:

      • Its questions were not the same as the schema. For example, it gave a severity score from 0 to 3, and the lab mapped that score to a priority. The two designs are close, but not an exact like-for-like test.
      • The Batch API closes the gap. Haiku with the schema on the Batch API is $0.094 per 1,000 items, about the same as the decision model. So the decision model is most useful for live traffic, where you cannot wait for a batch.
      • It can only choose. It cannot explain a decision, write a reply or handle a new field without a new question. Keep a language model for the cases that need text.

      Cost Estimator
      #

      Use this calculator for your own workload. It starts with Haiku 5.5 and the token counts measured in the lab. Change the prices to the rates of the model that you use.

      Classification cost estimator

      Prices, $ per million tokens
      Compare with a free-text answer
      Your workload

      Defaults are lab medians for Haiku 5.5: 1,388 input and 98 output tokens with the schema, 790 input and 2,283 output tokens for a free-text write-up. The schema adds input tokens, because it is sent with each call. If you use prompt caching or long prompts with a higher rate, your bill will differ.