Skip to content
mentoor

Topic 2 of 5 · 4 min read

Routing inputs to specialised handlers

Goal: Build a routing table that sends each input category to a handler and sends low-confidence classifications to a fallback.

Routing classifies each input first, then sends it to the prompt, tool or model built for that category, with a fallback for inputs the classifier is unsure about. It is a switch statement where the condition is a model's judgement.

Check yourself · 1 of 3

What does routing do in a workflow?

Choose one answer

Why it matters

A single prompt that must handle refund requests, technical bugs and sales questions becomes a long list of rules that fight each other. Tuning it for one category often hurts another. With routing, each handler has a short prompt tuned for one kind of input, and you can improve one without touching the rest. Routing also saves money: easy, high-volume inputs can go to a small, cheap model while hard ones go to a stronger one.

How to build one

  1. List the categories from real traffic. Read a few hundred actual inputs and group them. Categories invented at a desk miss the messy middle.
  2. Make categories distinct. If a person would hesitate between two labels, merge them or add a rule that separates them.
  3. Add an explicit other or unclear category. A classifier forced to pick from a closed list will pick wrongly rather than refuse.
  4. Return structure. Ask for JSON such as {"category": "billing", "confidence": 0.82} and validate that the category is in your list. Treat the model's confidence as a rough signal, not a calibrated probability; measure it against labelled examples.
  5. Write the routing table. Each category maps to a handler, and a low confidence or unclear maps to a fallback: a general handler, a clarifying question, or a human.
  6. Measure the router on its own. Label a test set and track accuracy per category. A router at 90 percent caps the whole system near 90 percent.

Before and after

# Before: one prompt with every rule
answer = llm(HUGE_SUPPORT_PROMPT, message)
# After: classify, then dispatch
route = classify(message)  # {"category": ..., "confidence": ...}
if route["category"] not in HANDLERS or route["confidence"] < 0.7:
    return escalate_to_human(message)
return HANDLERS[route["category"]](message)

What goes wrong

  • No fallback. A message that fits no category gets the closest wrong handler, and the customer receives a confident, wrong answer.
  • Overlapping categories. "Billing" and "refunds" split the same traffic, so the router flips between them and handlers see inputs they were not written for.
  • Never testing the router. Teams tune handlers for weeks while the classifier quietly misroutes a tenth of inputs.
  • Routing when one prompt works. Two handlers with nearly the same prompt is a router that adds a call and nothing else.

Examples

A support routing table

Category Handler Model
password_reset Fixed template plus reset-link tool small
billing_question Billing prompt with invoice lookup mid
bug_report Bug prompt that asks for steps and version mid
unclear or confidence under 0.7 Ask one clarifying question small
legal_threat Human queue, no model reply none

Routing for cost

A team sends every question to its strongest model. They label 500 past questions and find most are short FAQ lookups. A router sends FAQ-type questions to a small model and keeps the strong model for the rest. They check answer quality on the labelled set before and after the change, and ship only because quality on the FAQ group did not drop.

Key points

  • Routing classifies an input first and dispatches it to the handler built for that category.
  • Derive categories from real inputs, and keep them distinct enough that a person would not hesitate.
  • Include an explicit unclear category, and send low-confidence results to a fallback such as a human or a clarifying question.
  • Validate the router's output against your category list and treat its confidence as a rough signal to be measured.
  • Evaluate the router separately, because its accuracy caps the accuracy of the whole system.

Common mistakes

  • Forcing the classifier to choose from a closed list with no unclear option.
  • Defining overlapping categories that split the same inputs.
  • Tuning handlers while never measuring the router's accuracy.
  • Trusting a self-reported confidence number without checking it against labelled examples.

Check yourself · 2 of 3

A router must label support messages as billing, bug or account. Messages like "hello?" keep landing in billing. What is the best fix?

Choose one answer

Check yourself · 3 of 3

A routed system answers 82 percent of test cases correctly. Which check finds the cause fastest?

Choose one answer

Practice items, not counted towards your mastery.

Start here