Routing

LLM router · Intent classification · Model routing

Written by Darjus Kazakevic · reviewed

Classify first, so each request reaches the prompt built for it.

A prompt that handles every kind of request collects instructions for each, and they conflict. Refund rules confuse the technical answers. Code examples mislead the billing questions. Every fix for one kind of request can quietly break another.

Routing adds a small step in front. Rules, an embedding match or a small model gives the request a label. Plain code then sends it to the branch for that label, with its own prompt, tools and model. The router now limits quality: the best branch cannot fix a request sent to the wrong one.

In essence — One cheap classification step in front of several focused branches beats one big prompt that tries to handle everything.

When to reach for it

Reach for it when

  • Different kinds of request pull one prompt in different directions
  • Kinds of request need different tools or permissions
  • Most traffic is easy, and a cheap model could serve it

Reconsider when

  • Requests do not fall into kinds you can name
  • One request often needs several branches combined
  • Traffic is too low to know what the kinds are yet

The parts

The classifier
The small, fast step that labels the request before any real work. It runs on every request, so its cost and latency are the tax the pattern charges.
The route table
The mapping from label to branch, in plain code. It is boring on purpose: the intelligence lives in the classifier and the branches, so the mapping can be complete, typed and easy to review.
The branch
Where a routed request lands: a prompt with examples for exactly this kind of work, the few tools it needs, and the cheapest model that handles it. Each branch is owned and tested on its own.
The fallback
The branch for low-confidence and out-of-scope requests: a general prompt, a clarifying question, or a person. It is a real branch, not an error path.

Design rules

Try the simplest classifier first
Keyword rules and an embedding similarity check handle more routing than people expect, at almost no cost and fully predictable. Use a small model only when labels need real reading, and rarely a large one.
Classify into a fixed set, through a schema
Free-text labels drift: “billing”, “Billing”, “billing_question”, and the switch silently stops matching. An enum output makes unknown labels impossible, and the compiler can check the route table covers every label.
Give unclear requests a fallback
Send low-confidence requests to a fallback: a general prompt, a clarifying question or a person. Set the floor from labelled requests, because a model's own score is rough. Without it, the wrong branch answers.
Test the router on its own
Keep a labelled set of real requests and rerun it after every change. Router accuracy limits the whole system, and the test needs only assertions. Tested only end to end, a misroute looks like a branch failure.

Common pitfalls

  • No fallback, so unclear requests are forced into the nearest branch.
  • Free-text labels, so the switch silently stops matching as the wording drifts.
  • Branch prompts that drift apart on shared rules, like tone or refund policy.
  • Too many branches. Prompts copied between branches are the sign you split too finely.