Sub topic 3
What a Router Can Look At
This chapter assumes you can write basic Python and have called a hosted language model through an API. It also assumes you know that models differ in cost, speed, and capability, and that pricing is per token. The previous chapters covered the trade-off between small and large models. This chapter covers the information a router has available when it chooses between them.
A signal is anything known at decision time
A router is a function that picks a model for a request. Its inputs are called signals. A signal is any fact the router can read before it commits to a model, or soon enough that acting on it is still cheap.
The timing matters. Some signals are free and arrive with the request. Others cost a model call to produce. A signal that costs as much as the large model defeats the purpose of routing.
Signals fall into three groups:
- Request signals come from the prompt text itself.
- Context signals come from around the request: who sent it, from which feature, under what load.
- Output signals come from a model's answer, usually the small model's.
Request signals
These are the cheapest signals because computing them is plain string work.
- Length. Long prompts often carry more material to reason over. Count tokens if you can. Characters are a rough stand-in.
- Keywords. Words such as "prove", "refactor", or "step by step" often mark harder tasks.
- Structure. Code blocks, several numbered questions, or large tables suggest more work than a one-line question.
- Language. Small models are often weaker in less common languages.
- Attachments. A request with a file or retrieved documents usually needs a longer context window.
Context signals
These describe the situation, not the text.
- Feature or endpoint. A "suggest a title" button and a "review this contract" button can be routed differently with no text analysis at all. This is often the strongest signal and the cheapest.
- User tier. A free plan may default to the small model, and a paid plan to the large one.
- Conversation state. A fifth follow-up in a long thread may need more context than a first question.
- Latency budget. An autocomplete call may have 300 ms, while a background report has minutes.
- System load. If the large model is slow or rate-limited, the router can prefer the small one.
Output signals
After the small model answers, the router can inspect the answer. Useful checks include whether the output parses as the required JSON, whether the model refused, and whether a confidence score is high. Confidence estimation and cascades get their own chapters. For now, remember that output signals cost one small-model call, which is why they belong to cascades and not to routers that decide up front.
| Signal group | Available | Cost to obtain | Typical weakness |
|---|---|---|---|
| Request | Before any call | Near zero | Weak proxy for difficulty |
| Context | Before any call | Near zero | Says little about this specific prompt |
| Output | After the small call | One small-model call | Cannot help if the small call is skipped |
Collecting signals in code
It helps to gather signals into one object so rules and later classifiers read the same inputs.
from dataclasses import dataclass
FENCE = "`" * 3
@dataclass
class Signals:
char_count: int
line_count: int
has_code_block: bool
question_count: int
user_tier: str
feature: str
def extract_signals(prompt: str, user_tier: str, feature: str) -> Signals:
return Signals(
char_count=len(prompt),
line_count=prompt.count("\n") + 1,
has_code_block=FENCE in prompt,
question_count=prompt.count("?"),
user_tier=user_tier,
feature=feature,
)
print(extract_signals("Refactor this?\nWhy?", "free", "chat"))Running it prints:
Signals(char_count=19, line_count=2, has_code_block=False, question_count=2, user_tier='free', feature='chat')Nothing here calls a model. Extraction takes microseconds, so it adds no meaningful latency or cost.
Common errors
- Treating length as difficulty. A 5,000-character prompt that asks for a summary may suit the small model. A 40-character prompt that asks for a proof may not. Check any signal against labeled outcomes before you trust it.
- Using information that is not available yet. Do not route on the answer's quality or length when the router must decide before the call. This mistake often appears when you test on logged data that contains the final answers.
- Paying too much for a signal. If you run a model to judge difficulty, its cost and latency are added to every request.
- Ignoring drift. Users change how they write, and features change what they send. A keyword list that worked in March can misroute in September.
Exercise
A router must pick a model before any model is called. You can choose among these signals: (a) the feature that sent the request, (b) the number of code blocks in the prompt, (c) whether the small model's JSON output parsed correctly. Which can the router use, and why can't it use the other?
Show answer
It can use (a) and (b). Both are known when the request arrives. Signal (c) exists only after the small model has answered, so it can drive a cascade's escalation decision but not an up-front routing decision.