Sub topic 6
Cascades: try small first, escalate when needed
A router decides which model to use before any model runs. A cascade makes the decision after the small model has answered. This chapter covers how a cascade works, what it costs, where it fails, and how to build one that behaves well in production.
This chapter assumes you can read basic Python and have called a hosted language model through an API. It also assumes you know that models differ in price, speed, and capability, and that pricing is per token. It builds on the earlier chapters on model tiers, routing signals, rule-based routing, and confidence estimation.
The idea
A cascade sends every request to the small model first. The small model returns an answer and a confidence score. If the score is at or above a threshold, the system returns the small model's answer. If not, the system sends the same prompt to the large model and returns that answer.
The design bets that many requests are easy and the small model handles them well. The large model is then used only for the requests that need it. The system needs no up-front prediction of difficulty, because the small model's own output shows whether it struggled.
A minimal cascade
Here is the core logic. call_small returns a (text, confidence) pair, and call_large returns text.
def answer(prompt, call_small, call_large, threshold=0.8):
text, confidence = call_small(prompt)
if confidence >= threshold:
return text, "small"
return call_large(prompt), "large"The function returns the tier that answered along with the text. Keep that second value. You need it for cost accounting, evaluation, and monitoring, and it is hard to reconstruct later.
To try the function without an API, stub both models:
def answer(prompt, call_small, call_large, threshold=0.8):
text, confidence = call_small(prompt)
if confidence >= threshold:
return text, "small"
return call_large(prompt), "large"
def fake_small(prompt):
# Pretend short prompts are easy and long ones are hard.
confidence = 0.95 if len(prompt) < 40 else 0.4
return "small:" + prompt[:10], confidence
def fake_large(prompt):
return "large:" + prompt[:10]
print(answer("What is 2 + 2?", fake_small, fake_large))
print(answer("Summarize the trade-offs of eventual consistency in detail.", fake_small, fake_large))The first call prints a small-tier answer and the second prints a large-tier answer.
Where the confidence score comes from
The cascade is only as good as its confidence signal. Common sources, from cheapest to most expensive:
- Token log-probabilities. Many APIs return the log-probability of each generated token. Average them and exponentiate to get a per-token geometric mean probability. This costs nothing extra but is only available from some providers.
- Self-reported confidence. You ask the small model to rate its own certainty. This is easy to implement but is often poorly calibrated.
- Agreement between samples. You sample the small model several times and measure how often the answers match. This is a good signal for short answers but multiplies small-model cost.
- A verifier. A cheap check validates the output. It might parse JSON against a schema, run unit tests on generated code, or check a cited quote against the source. When a verifier exists, it is usually the most reliable signal.
This helper turns log-probabilities into a score:
import math
def confidence_from_logprobs(logprobs):
"""Geometric-mean token probability, in the range 0 to 1."""
if not logprobs:
return 0.0
return math.exp(sum(logprobs) / len(logprobs))
print(round(confidence_from_logprobs([-0.05, -0.1, -0.02]), 3))
print(round(confidence_from_logprobs([-1.2, -2.0, -0.9]), 3))The first call gives about 0.945 and the second about 0.26. A fluent, low-uncertainty answer scores high, and a hesitant one scores low.
What a cascade costs
A cascade always pays for the small model. Requests that escalate also pay for the large model, so those requests cost more than if you had sent them straight to the large model. A router pays for exactly one model per request.
def expected_cost_cascade(frac_answered_by_small, cost_small, cost_large):
# Every request pays for the small model; escalated requests also pay for the large one.
return cost_small + (1 - frac_answered_by_small) * cost_large
def expected_cost_router(frac_sent_to_small, cost_small, cost_large):
# A router pays for exactly one model per request.
return frac_sent_to_small * cost_small + (1 - frac_sent_to_small) * cost_largeSuppose the small model costs 1 unit per request, the large model costs 10 units, and 70% of requests stay with the small model:
| Strategy | Calculation | Expected cost |
|---|---|---|
| Always large | 10 | 10.0 |
| Router, 70% to small | 0.7 × 1 + 0.3 × 10 | 3.7 |
| Cascade, 70% answered by small | 1 + 0.3 × 10 | 4.0 |
The cascade is 0.3 units more expensive than a router with the same split. That difference is (1 - f) * cost_small, the wasted small-model call on every escalated request. The gap grows as the small model gets more expensive relative to the large one, or as the escalation rate rises. A cascade can even cost more than always using the large model. With a small-to-large cost ratio of 0.5 and a 20% small-answer rate, the cascade costs 0.5 + 0.8 × 1 = 1.3 versus 1.0 for large only.
The comparison above is also not fair in one respect. A router with a 70% small split would need a classifier that predicts difficulty correctly. A cascade gets its split from observed behavior, which is often more accurate than a prediction made from the prompt alone.
Latency
Latency adds up the same way. An escalated request waits for the small model, then the large model. Expected latency is the small model's latency plus the escalation rate times the large model's latency. If the small model takes 0.5 seconds, the large model takes 4 seconds, and 30% escalate, the average is 0.5 + 0.3 × 4 = 1.7 seconds. The tail is worse: the slowest 30% of requests take about 4.5 seconds. If you have a strict latency target on the slowest requests, measure the 95th percentile (p95) latency, not the average.
Choosing the threshold
The threshold moves the system along a quality and cost curve. A higher threshold means more escalation, higher cost, and quality closer to the large model's. A lower threshold means more small-model answers, lower cost, and more mistakes slipping through.
You choose it by replaying a labeled sample. For each record you need the small model's confidence, whether the small answer was correct, and whether the large answer was correct.
def sweep(records, thresholds):
# Each record: {"confidence": float, "small_correct": bool, "large_correct": bool}
results = []
for t in thresholds:
correct = 0
escalated = 0
for r in records:
if r["confidence"] >= t:
correct += int(r["small_correct"])
else:
escalated += 1
correct += int(r["large_correct"])
n = len(records)
results.append((t, correct / n, escalated / n))
return resultsA small run shows the pattern:
records = [
{"confidence": 0.95, "small_correct": True, "large_correct": True},
{"confidence": 0.90, "small_correct": True, "large_correct": True},
{"confidence": 0.85, "small_correct": False, "large_correct": True},
{"confidence": 0.60, "small_correct": False, "large_correct": True},
{"confidence": 0.40, "small_correct": False, "large_correct": False},
]
for t, accuracy, escalation in sweep(records, [0.5, 0.8, 0.9]):
print(f"threshold={t:.1f} accuracy={accuracy:.2f} escalated={escalation:.2f}")With this data, a threshold of 0.5 gives 0.60 accuracy with 20% escalation, 0.8 gives 0.80 accuracy with 40% escalation, and 0.9 gives 0.80 accuracy with 60% escalation. The step from 0.8 to 0.9 buys no accuracy and costs more, so 0.8 is the better choice here. Five records is only an illustration. Use hundreds, drawn from real traffic, and pick the lowest threshold that meets your quality target. The later chapter on evaluation covers sample size and metrics in more detail.
Design decisions and edge cases
What to send to the large model
The simplest choice is to resend the original prompt and discard the small model's attempt. This keeps the large model's answer independent of a possibly wrong draft. Some systems pass the draft along as context so the large model can correct it. That can save output tokens, but it can anchor the large model on the small model's mistakes. Start with a clean resend and test the alternative on your own data.
Calling both models at once
To protect tail latency, you can start the large model in parallel and cancel it if the small model is confident. This trades extra cost for lower latency, since you pay for the large call whenever it starts before the cancellation lands. Most teams use it only for the slowest, most latency-sensitive paths.
Streaming
You cannot decide to escalate until you have the confidence score, and a score from log-probabilities needs the whole answer. That conflicts with streaming tokens to the user. Either buffer the small model's output until you decide, or use a signal that is available early, such as a check on the first tokens.
Side effects
If the small model's attempt calls tools that change state, such as sending an email or writing a record, escalating means those actions may run twice or conflict. Keep cascaded calls read-only, or run the cascade on the planning step and perform actions only after a final answer is chosen.
More than two tiers
A cascade can have three or more tiers, such as small, medium, and large. Each extra tier adds latency for requests that reach it and one more threshold to tune. Add a tier only when measurements show a meaningful share of traffic that the medium model handles well and the small model does not.
Caching
If the same prompt arrives repeatedly, cache the final answer along with the tier that produced it. Otherwise you pay for the small attempt every time and, for hard prompts, the large call too.
Cascades compared with routers
| Property | Router | Cascade |
|---|---|---|
| Decision made | Before any model runs | After the small model answers |
| Models called per request | One | One or two |
| Signal used | Prompt features or a classifier | The small model's own output |
| Cost on hard requests | Large model only | Small plus large |
| Latency on hard requests | Large model only | Small plus large |
| Main failure mode | Misjudging difficulty from the prompt | Confident wrong answers from the small model |
The two combine well. A rule-based router can send obviously hard requests, such as very long prompts, straight to the large model. A cascade then handles the uncertain middle. This removes the wasted small attempts on requests you already know will escalate.
Failure modes to watch
- Confidently wrong answers. The small model returns a high score for a mistake, so the cascade never escalates. A verifier or a stricter threshold helps. Audit a random sample of small-tier answers regularly.
- Calibration drift. Changing the prompt, the model version, or the input mix changes what a given score means. Re-run the threshold sweep after any of these changes.
- Escalation spikes. If a new type of traffic scores low across the board, nearly everything escalates and cost rises sharply. Alert on the escalation rate.
- Tuning on the wrong data. A threshold chosen on a convenient sample may fail on production traffic. Sample from production, and keep a held-out set for a final check.
- Hidden double-billing. Teams that report only the large model's spend miss the small-model cost on escalated requests. Count both calls.
Exercise
A cascade uses a small model costing 2 units per request and a large model costing 20 units per request. On a labeled sample, a threshold of 0.85 leaves 60% of requests answered by the small model. What is the expected cost per request using the cascade? What would a router cost if it sent the same 60% of requests to the small model? Which is cheaper, and by how much?
Show answer
Cascade: 2 + (1 - 0.6) × 20 = 2 + 8 = 10 units per request. Router: 0.6 × 2 + 0.4 × 20 = 1.2 + 8 = 9.2 units per request. The router is cheaper by 0.8 units, which equals (1 - 0.6) × 2, the small-model call wasted on each escalated request. The cascade's advantage is not cost but that its split comes from the small model's observed output rather than a prediction from the prompt.
Exercise
Name two reasons a cascade's measured p95 latency can be much worse than its average latency, and give one change that reduces the tail.
Show answer
Escalated requests wait for the small model and then the large model, so the slowest requests take the sum of both latencies. Buffering the output until a confidence score is available adds further delay for those requests. One change that reduces the tail is to route obviously hard requests straight to the large model with a rule-based router, so they skip the wasted small attempt. Starting the large model in parallel on latency-sensitive paths also reduces the tail, at extra cost.