Business

A/B Testing Model Routing Rules Without Breaking Production

Antonio Evans10 min read

A split-screen scene in a network operations center.
Key points

Key points

  1. 1Run the candidate routing policy in shadow mode, where it sees a copy of real requests but its answers never reach users.
  2. 2Decide the cost and quality gates before the test starts, then stop when the sample is large enough to clear noise.
  3. 3Log the routing reason, the selected model, token counts and cost for every decision so both policies are compared on the same requests.
  4. 4Score quality on the actual task output, not on how cheap the request looked, and promote only when both gates are met.

Why routing changes need a shadow test, not a hard cutover

A routing rule looks like a small configuration edit. In practice it changes which model answers which request, and that means it changes cost per request, output quality, latency and failure behavior all at once. Teams that ship a new threshold straight to production find out about a bad threshold from users, and they find out weeks later because a wrong answer often still reads as plausible.

Shadow mode is the standard answer to that. Production traffic and data run through the new version of a service or model without that version returning its response to customers; the live version keeps serving, and the candidate's results are captured for analysis. The two reasons to do this are to confirm the service handles inputs as intended and to confirm it can handle the incoming load, as described in this guide to deploying models in shadow mode.

The failure statistics explain why this matters more than it sounds. RAND researchers, interviewing 65 experienced data scientists and engineers, found that more than 80 percent of AI projects fail, twice the rate of IT projects that do not involve AI, with one listed cause being models optimized for the wrong metrics or that do not fit the overall business workflow, per RAND's root-cause analysis. A routing threshold is exactly that kind of wrong-metric risk: the rule optimizes for predicted cost before anyone has checked the output.

There is a second reason to mirror rather than split. A live A/B split sends one group of users to an untested policy. A shadow test sends every user to the policy you already trust and keeps a copy of the traffic for the candidate. You pay for the extra inference, and in return you get a comparison on identical inputs with zero user exposure.

What a routing policy actually decides

Before you can compare two policies, name the decision each one makes. A router is a function from request features to a model or provider, and most production systems stack several patterns: direct calls, provider fallback, conditional rules, weighted traffic splits and sticky assignment, as catalogued in these LLM routing strategies.

Useful inputs for a conditional rule include language, geography, subscription tier, interaction type, safety level, context length, modality and session depth, and the condition should have a product reason and an observable outcome. That last point is the one teams skip. A rule such as "long prompt equals expensive model" can be wrong for a simple summarization task, and the only way to know is to log the matched condition alongside cost, latency and the product result.

A practical policy definition has four parts:

  1. The condition that fires, expressed over request metadata.
  2. The model tier or specific endpoint the condition selects.
  3. The fallback behavior when the first attempt fails or is slow.
  4. The logging fields that let a reviewer reconstruct why this request went where it did.

If you cannot express the change as a diff on those four parts, the shadow test will not produce a readable result. "We lowered the threshold from X to Y" is testable. "We improved the router" is not.

Designing the shadow harness

The harness mirrors a representative slice of live requests to both policies. Representative is doing the work in that sentence. If the candidate policy only ever sees your easiest traffic, its quality scores will look great and mean nothing.

Three design choices decide whether the test is worth running.

Sampling. Start with a percentage of traffic rather than everything, because you are paying twice for each mirrored request. A five percent mirror on a steady workload gives you a large sample within days and bounds your worst-case bill to a known multiple of current spend. Exclude requests that must not be duplicated: anything with side effects such as sending an email, writing a record, charging a card, or calling a tool that mutates state.

Synchrony. A synchronous mirror adds the candidate's latency to the live path and can take production down. Send the mirror asynchronously, after the live response is returned, and accept that the two policies see the same input but not the same timing.

Logging. Every decision needs a record that joins the two policies on the same request ID.

{
  "request_id": "req_9f2c",
  "policy": "candidate",
  "matched_condition": "tier=free AND intent=summary",
  "selected_model": "reported by the gateway",
  "input_tokens": 3120,
  "cached_input_tokens": 0,
  "output_tokens": 410,
  "reasoning_tokens": 0,
  "retries": 0,
  "cost_usd": 0.0,
  "latency_ms": 1840,
  "quality_score": null,
  "scored_at": null
}

The token buckets matter as much as the total. A bill is the sum of uncached input, cache writes, cache reads, output and any separate tool charges across every billed attempt, and reasoning tokens are counted inside output usage on some endpoints even when the text is hidden, per this pricing guide. Logging output as a single number hides the two things most likely to have changed when you edited a threshold.

There is an observability argument here too. LLMs break traditional monitoring because billing is per token and the same request can vary wildly in consumption, so cost and usage tracking has to be instrumented rather than inferred from invoices, as this OpenTelemetry guide for LLM systems explains. A shadow harness is a small on-ramp to that instrumentation, and the fields you add for the test are the fields you will want permanently.

Setting the gates before you look at the data

The most common way a shadow test fails is not a technical bug. It is that the team looks at the results, decides the numbers are "probably fine," and ships. Pre-agreeing the gates removes that discussion.

A gate has three parts: the metric, the threshold, and the rule for when the evidence is sufficient.

GateMetricPre-agreed thresholdWhy it is on the list
CostMedian cost per request, candidate vs currentCandidate at or below target on matched request classesThe whole point of a threshold change
Cost tail95th percentile cost per requestNo worse than currentCatches a few expensive misroutes
Task qualityPass rate on the automated check for the taskWithin a pre-agreed band of currentStops cheap-but-wrong answers
Format validityShare of responses that parse against the schemaEqual or betterCheap to measure, fails loudly
Escalation rateShare of requests that needed a retry or fallbackNo worse than currentExposes hidden cost and hidden failure

Two of these deserve emphasis. First, compare cost per request, not total spend. Total spend moves with traffic volume and will make a good policy look bad during a busy week. Second, quality must be measured by scoring the output, not by trusting the router's own signal. As Braintrust's routing guide puts it, pre-response signals select a model before any output exists, so prompt complexity and pricing can estimate cost but cannot show whether the selected model returned an accurate, relevant and correctly formatted response.

The scale of the risk is not hypothetical. A product team shipped an AI feature tied to a major release and finance found a $44,000 line item increase tied to the feature, well beyond what anyone modeled, because nothing in the stack attributed cost at the level of detail needed to catch it earlier, per this account of AI ROI measurement. Shadow logging at the request level is that level of detail, applied before the change instead of after.

Worked example with numbers

Take a support assistant handling 200,000 requests a month. The current policy costs $0.011 per request on average, so $2,200 a month. The candidate policy sends short, low-risk tickets to a cheaper model and keeps the rest where they are. You mirror 5 percent of traffic, which is 10,000 requests a month, and you pay for each mirrored request at the candidate's rate.

Suppose the candidate comes in at $0.006 per request on the mirrored sample, a saving of $0.005, which projects to $1,000 a month across all traffic. The mirror itself costs about $60 a month at the candidate rate, so the test pays for itself roughly twice over in the first month if the policy is promoted, and costs $60 if it is not.

Now the quality side. The automated check passes 94.0 percent of current-policy responses and 93.2 percent on the candidate, on the same 10,000 requests. With roughly 10,000 paired observations, the standard error on a proportion near 0.93 is about 0.26 percentage points, so a 0.8 point drop is roughly three standard errors and is not noise. That is a real regression, and the decision rule should say what happens next: either narrow the condition so the cheaper route covers fewer request classes, or keep the current policy. Widen the sample only when the gap is smaller than noise, not when it is unfavorable.

Note how the arithmetic is done. Cost difference times volume gives the benefit. The paired quality difference divided by its standard error tells you whether the difference is real. Both numbers come from the same mirrored requests, which is why the pairing matters.

Comparing quality without lying to yourself

Cost is arithmetic. Quality is a judgment, and the shadow harness will happily collect a judgment-free number if you let it.

The safe pattern is to classify requests into classes and give each class its own check. A routing threshold should apply to one query class because each task has a different definition of quality and cost of failure, and combining an easy task with a hard one lets strong results on the easy task conceal a serious regression in the other, per Braintrust's classification guidance.

Then choose the cheapest check that can actually fail:

  • Deterministic checks for anything with a right answer: schema validity, required fields present, numbers that must reconcile, links that must resolve.
  • Model-graded checks with a fixed rubric for open text, applied identically to both policies with the same grader so the grader's bias cancels.
  • Human spot checks on a small random subsample, used to calibrate the automated checks rather than to score every request.

Run the automated checks against both policies on the same request IDs. A grader that sees only the candidate's output has no baseline and will drift toward "looks fine."

One more trap: do not let the shadow test double as a load test unless you have sized it. Mirroring a large share of traffic to a secondary provider can hit rate limits you did not know about, and the resulting errors look like quality failures. Cap concurrency on the mirror and log throttling separately from content failures.

Promoting, rolling back and watching after

Promotion is a sequence, not a switch.

  1. Confirm both gates were met on the pre-agreed metrics with the planned sample.
  2. Promote in steps: the same small percentage of live traffic first, then wider, holding each step long enough to see the tail metrics.
  3. Keep the old policy configurable and one edit away, and define the rollback trigger in advance, for example a quality pass rate more than a set margin below the current policy for a full hour.
  4. Re-check cost after promotion, because a live route sees a different traffic mix than the mirror did.

That last point is why post-promotion monitoring is not optional. AI spend rarely shows up as one clean attributable number: a gateway can aggregate traffic and strip the caller's identity before it reaches the provider, and a shared cluster can serve several products at once, which is why attribution is the hard half of AI ROI measurement, per DoiT's analysis. The gateway configuration that made your shadow test readable is what makes the live route readable afterward.

Reliability also deserves its own gate, because routing changes touch failover. Error fallback and latency fallback solve different problems, and a latency fallback can create simultaneous or sequential spend, so the timeout should come from the application budget and the primary route's normal p95, per Inworld's routing guide. If your threshold change alters when fallback fires, that belongs in the test.

A checklist you can run this week

StepOutputDone when
Write the policy diffCondition, tier, fallback, logging fieldsA reviewer can read the change in one paragraph
Pick the request classesClasses with separate quality checksEach class has a check that can fail
Fix the gatesMetric, threshold, sample sizeSigned off before any data is collected
Build the mirrorAsync duplicate with side effects excludedMirror failures never affect the live response
Log per requestRouting reason, token buckets, cost, scoreBoth policies join on request ID
Score outputsDeterministic checks first, then gradedGrader is identical for both policies
DecidePromote, narrow the condition, or stopDecision matches the pre-agreed rule
Promote in stepsSmall share first, then widerTail cost and escalation rate hold

If you are routing across several providers and model families, the mirror is easier when every model sits behind one key and one billing line. Quanta Inference exposes text, image, video, audio and embedding models through one OpenAI-compatible API with prepaid pricing in US dollars, which means the candidate and current policies can be logged against one cost ledger instead of reconciling several invoices.

FAQ

FAQ

Is shadow mode the same as a canary release?

No. A canary sends a small share of real users to the new version and measures what happens to them. Shadow mode sends no users to the new version at all; the candidate sees copies of requests while the current policy keeps serving, which is the definition used in this shadow-mode guide. Canary is the step after shadow, once the evidence supports exposure.

How much traffic do I need to mirror?

Enough that the difference you care about is larger than sampling noise, and no more. Size the sample from the smallest quality gap you would act on, then stop when you reach it. In the worked example, 10,000 paired requests made a 0.8 point quality difference clearly distinguishable from noise, while a 0.1 point difference would have needed far more.

Can I skip quality scoring and just watch cost and error rates?

You can, and you will promote cheap policies that quietly degrade output. Error rates catch crashes, not wrong answers. Routing exists to cut cost only where the cheaper model preserves the task's required accuracy, relevance, safety and output format, which is a claim about output quality that error rates do not test, as Braintrust notes.

What should I do if the candidate wins on cost but loses on quality?

Narrow the condition so the cheaper route covers only the request classes where quality held, then re-run the mirror on the narrowed rule. Treat it as a scoping problem, not a verdict on cheaper models. A transparent static rule often beats a complex selector the team cannot audit, per Inworld.

How do I stop the mirror from doubling my bill?

Cap the mirrored share, exclude expensive and side-effecting requests, and treat the mirror cost as a line item in the business case for the change. A five percent mirror bounds the extra spend to a known multiple of current traffic, and the projected saving on all traffic usually covers it within the first month, as the worked example shows.

Sources

Sources

  1. Deploying Machine Learning Models in Shadow Mode
  2. The Root Causes of Failure for Artificial Intelligence Projects and ...
  3. LLM Routing Strategies: Conditional Routing, Failover, and ...
  4. How LLM Token Pricing Works: A Complete Guide to API ...
  5. OpenTelemetry for LLMs: Complete SRE Guide for 2026
  6. How to cut LLM costs with model routing without hurting quality
  7. How to Measure AI ROI When You Can't See Where Tokens ...
About the author

About the author

Antonio Evans
Antonio Evans

Antonio Evans is the founder of Quanta Intelligence and a fractional CTO who builds HIPAA-ready AI systems for health and life-science companies. Before that he was technical co-founder of FriendsEAT for twenty years, CEO of Socialdraft, and a data engineer at IBM. Antonio lives with his dog Santino in Lisbon, Portugal.

All articles