liveBook · Manning

Semantic routing

As explained in Natural Language Processing in Action, Second Edition

Semantic routing is the classification-driven selection of an appropriate language model or processing path for a natural-language input.

A prompt asking for code may need a different response path from one asking for poetry or a simple explanation. Semantic routing, also called intent routing, predicts which language model is likely to work best for an input, sends the request there, and processes the response. It moves that choice out of a single model’s prompt instructions and into routing logic. section 10.1.2 section 10.1.3

A practical router follows three steps:

  • Collect prompts that have worked well for users as training data. section 10.1.3
  • Train a classifier to predict which LLM is likely to produce the best result for a new prompt. Semantic search, or vector search, is a core technology behind this approach. section 10.1.3
  • Use the prediction in routing logic—such as Python if–elif branches—to request a response from the selected model and process its output. section 10.1.2 section 10.1.3

Different requests, different paths

Consider requests to generate code, write poetry, and explain AI to a five-year-old. Rather than send all three to one LLM with increasingly elaborate instructions, a router classifies each request and selects the LLM predicted to handle it best. The prediction depends on the router’s training data; the prompt alone does not establish which model will win. section 10.1.3

Routing can improve the cost–benefit balance of an LLM service, but selection is not a guarantee of a good or safe answer. Models have different guardrails and quirks, so the chosen path still needs appropriate handling. section 10.1.3

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines intent routing and outlines training, classification, and if–elif dispatch, but does not supply a worked router implementation.
Examples
Contrasts code generation, poetry, and simple AI explanations as requests that may call for different models.
What it assumes
Introduces intent routing from ordinary prompt examples while assuming familiarity with LLM prompts and basic Python branching.
What you can do after
Build it from scratch at the design level: collect successful prompts, train a model-choice classifier, and dispatch requests accordingly.
How it connects
Connects prompt classification to semantic search, vector search, prompt engineering, and LLM guardrails.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.