Forward Deployed EngineeringAI EngineeringModel Routing and Cascades

Design a multi-model router or cascade that cuts cost without dropping below a quality floor.

Question 62 of 73 · Updated

On this page

Interview-ready answer#

I would optimize expected cost per request subject to measured quality and operational constraints, not simply send easy-looking questions to the cheapest model. The quality floor is an application-level requirement on delivered outcomes, not a provider benchmark or a guarantee from a confidence score.

A router chooses a model before generation, using features such as task type, input size, language and required capabilities. A cascade starts with a cheaper model and escalates when independent validation or a calibrated risk estimate indicates that its result is unsuitable. I would combine the two: route mandatory high-risk or complex tasks directly to a suitable model, cascade eligible routine tasks, and retain an explicit abstention or human-review path when no approved model can satisfy the contract.

I would learn the routing policy using matched outcomes from all relevant models, tune thresholds on a calibration set, and validate the final policy on a separate representative holdout. Cost savings must survive the cost of routing, verification, escalation, retries and review. If the quality floor or latency budget cannot be demonstrated, I would not automatically promote the policy.

1. Router versus cascade#

DecisionRouterCascade
WhenBefore model inferenceAfter seeing a cheap model's candidate
SignalsTask, input complexity, permissions, language, context and capability requirementsCandidate validity, evidence support, uncertainty and task-specific checks
Main benefitAvoids paying for a cheap attempt on known hard tasksExploits output-dependent evidence of whether a cheap attempt succeeded
Main riskMisclassifies a difficult request as easyPays for multiple attempts; verifier misses an incorrect answer
LatencyUsually one selected inference plus routingEscalated requests incur sequential processing unless parallelized

Use explicit capability filtering before cost-based selection. A model lacking the required context capacity, modality, data-processing approval, output contract or reliability for a particular task is not a candidate merely because its price is attractive.

Do not confuse escalation to a stronger model with authorization to perform a more privileged action. Model capability selection must be independent of business permissions.

2. Architecture and escalation policy#

Loading diagram…

For structured extraction, enforce schema and check important fields against the source. For document QA, assess evidence sufficiency and claim support. A model's self-reported confidence is not an acceptance contract. Escalate when verification fails, information is insufficient, the risk estimate is outside its validated domain or a hard policy requires it. Escalation should not be used to bypass a mandatory abstention or access denial.

The stronger model must also be validated. Passing the second model's answer through the same flawed verifier can reproduce the original error. For missing or corrupted source data, additional inference may not help; retrieve authoritative evidence or route to review instead.

3. Optimize against a quality floor#

For request x, let a routing policy π select a model or sequence of models. Define Q as the task-specific utility or correct-outcome indicator, C as total serving cost and L as end-to-end latency. A practical constrained objective is:

Minimize E[C(π, x)] subject to E[Q(π, x)] ≥ , P(L(π, x) > deadline) ≤ ε, and required risk-slice and safety gates.

The expectation is over the intended production traffic distribution, not an arbitrary balanced benchmark. Define whether appropriate human handoffs count as correct outcomes and report automation coverage separately. Otherwise an apparent quality improvement may simply mean the system escalates every case.

The quality floor can be an absolute customer requirement, or a non-inferiority margin against a validated strong-model baseline. Critical policy and security invariants remain separate hard constraints; an average quality floor does not permit prohibited effects.

For a router, estimate the expected success and cost of each eligible model conditional on request features. For a cascade, estimate the cheap model's acceptance probability, quality among accepted cheap results, and the strong model's quality specifically among escalated cases. The threshold should be chosen using the measured end-to-end policy outcomes, not two independently reported model accuracies.

Worked example: why conditional quality matters#

Assume a hypothetical 1,000-case workload, with a cheap call costing $0.002 and a strong call costing $0.010. These are illustrative per-request costs, not provider prices. Ignore shared routing, validation and review costs initially.

PathRequestsCorrect outcomes
Cheap result accepted700686 (98%)
Cheap result rejected, strong result returned300270 (90%)
Cascade total1,000956 (95.6%)

Expected cascade cost = $0.002 + 0.30 × $0.010 = $0.005 per request, compared with $0.010 for always calling the stronger model. Its observed quality is 0.70 × 0.98 + 0.30 × 0.90 = 95.6%.

In this synthetic example, the stronger model correctly answers 970 of the original 1,000 requests when used alone (97%). Substituting 97% for its success rate on escalated requests would overstate the cascade's quality. Escalated examples are selected precisely because the cheaper path was uncertain or inadequate. This is a conditional failure problem, not independent model retries.

A 95% quality floor is met by the point estimate, but not necessarily by a prespecified confidence-bound requirement. Use the independent holdout and appropriate interval before claiming the production policy meets that floor. If routing and validation add $0.001 per request, expected cost becomes $0.006; the saving falls from 50% to 40% against the same baseline.

4. Tested Python: select a feasible cascade threshold#

For each labeled calibration case, store cheap-model acceptance features, independent correctness verdicts for both models, observed costs, latencies and a non-negotiable cheap-result acceptance gate. The following finite-grid search chooses the minimum empirical cost threshold subject to a quality floor and an upper bound on the fraction of requests exceeding a two-second deadline.

PYTHON
from fractions import Fraction as F def choose(rows, thresholds, floor, max_slow): # rows: (score, cheap_ok, strong_ok, cheap_cost, strong_cost, # cheap_ms, strong_ms, hard_ok); costs in integer microdollars if not rows: raise ValueError('empty calibration set') best = None for t in thresholds: cost = good = slow = 0 for score, cheap_ok, strong_ok, c, s, lc, ls, hard_ok in rows: accept = hard_ok and score >= t cost += c + (0 if accept else s) good += cheap_ok if accept else strong_ok slow += lc + (0 if accept else ls) > 2000 n = len(rows) if F(good,n) >= floor and F(slow,n) <= max_slow: key = (F(cost,n), -F(good,n), t) if best is None or key < best: best = key return None if best is None else best[2]

Use trusted normalized calibration records and validated thresholds, floors and latency budgets. This is an offline policy optimizer, not a runtime authorization service. It assumes every rejected cheap result can escalate; the strong verdict already includes its independent output checks. The example models sequential inference, excludes verifier and routing overhead, and uses uniformly weighted cases. Include those costs, deadline-dependent review outcomes, sampling weights and per-slice constraints in a real replay. Runtime budget exhaustion must produce an approved fallback rather than an unvalidated answer.

Executed verification: Python 3.13.5 passed 2,306 local checks: 2,304 exhaustive two-case combinations of scores, model outcomes, hard gates, quality floors and deadline-miss limits against an independently enumerated path-selection oracle, one 1,000-case worked example, and one empty-dataset rejection. The worked example selects threshold 1 from candidates 0, 1 and 2 at a 95% empirical floor, producing 95.6% correctness and $0.005 mean inference cost.

For T candidate thresholds and N rows the search takes O(TN) time and O(1) auxiliary space, excluding the input. If no threshold is feasible, return None rather than silently relax the quality floor. Freeze the chosen threshold and independently evaluate it; searching many thresholds on the same test set can overfit the reported quality.

5. Calibrate the router and account for correlated failures#

Collect paired outputs from every eligible model on a representative labeled dataset. Include easy, difficult, out-of-distribution, long-context and high-consequence examples. Model scores can be useful ranking signals, but calibrate their relationship to actual task correctness with a separate labeled set. Use risk-coverage curves and subgroup reliability checks to establish where cheap acceptance is justified. See FDE-0051 for judge calibration and FDE-0054 for abstention evaluation.

The major production trap is selective feedback: once a router sends easy tasks to the cheap model and difficult tasks to the strong model, their observed success rates are not directly comparable. Collect approved paired shadow samples or carefully controlled exploration on eligible requests to estimate counterfactual outcomes; do not experiment with unapproved high-risk routes.

Models often share training-data patterns, retrieval defects or reasoning weaknesses. Two models agreeing can still be wrong. A useful escalation model may be one with complementary strengths, not simply the model with the highest aggregate score. Measure residual failure rates for each escalation path; keep independent evidence checks and human review for uncertainty that inference cannot resolve.

6. Latency and capacity constraints#

A cascade can lower cost while worsening tail latency. If the cheap attempt takes 400 ms and the strong attempt 900 ms, an escalated request needs at least 1,300 ms of sequential inference under that illustrative timing, before verification, queueing and network overhead. Actual stage durations vary and are correlated; do not estimate end-to-end p95 by adding stage p95 values.

Reserve enough time for the escalation path, and route directly to the strong model when the predicted difficulty or remaining budget makes a cheap attempt unlikely to help. Apply bounded retries, circuit breakers and separate capacity budgets per model. A sudden increase in escalation can overload the strong-model endpoint precisely when the cheap model is struggling.

Parallel speculative calls can reduce time to a validated result but may pay for both models even when only one is used. Use them only for latency-sensitive workloads where measured savings in deadline misses justify the additional cost. Do not make fallback routing violate residency, capability or authorization restrictions.

7. Production acceptance and monitoring#

Compare always-strong, always-cheap, direct routing and the proposed cascade on the same tasks. Report total cost per request and per correct completed task, quality with uncertainty, risk-slice regressions, automation coverage, escalation precision, latency percentiles and deadline misses. Run load tests with realistic traffic mix and provider limits, including a cheap-model failure surge and a degraded strong-model endpoint.

Version the policy, model IDs, thresholds, verifier, cost assumptions and evaluation manifest together. Monitor the distribution of routing features, score calibration, cheap acceptance rate, escalation outcome quality, capacity and actual cost. Audit a random sample of cheap accepted outputs rather than checking only escalated failures. A changed model, verifier, workload or pricing regime can invalidate the policy.

If a slice drops below its approved quality floor or loses reliable calibration, restrict automatic cheap acceptance for that slice and use the independently validated strong or human-reviewed path. The strongest FDE answer is not "we saved 50% with routing"; it is "we reduced total cost while demonstrating that the delivered quality and safety commitments remained within their agreed bounds."

Related questions

Explore other topics:AI AgentsAI System DesignLarge Language Models