LLM classification assigns an input to one of several specified categories, then uses the decision to select a tool, data source, or workflow. In query routing, it can distinguish vector-store, SQL, and graph questions; in a guardrail, it can reject requests outside an assistant’s domain. section 10.8 section 14.2.1
Build a practical classifier by defining clear categories and connecting its decision to deterministic application logic:
- Describe each category in the prompt and provide few-shot examples, such as routing a revenue question to a vector store and a units-sold question to SQL. section 10.8
- Return a structured decision when consistency matters; a Pydantic model can expose a boolean classification and a brief reason. section 14.2.1
- Use the result before downstream work: route an in-scope request to the appropriate agent or retriever, and send an out-of-scope request to a refusal path. section 10.8 section 14.2.1
- Add fallback behavior when the selected source returns nothing, such as trying an alternative source for structured results. section 10.8
Travel-domain guardrail
A lightweight classifier receives the user’s last message and returns whether it concerns destinations, attractions, lodging, prices, availability, or weather in Cornwall or England. A non-travel request receives a fixed refusal and exits through a guardrail_refusal node before downstream agents run. For example, “Can you give me the latest results of Inter Milan?” is refused. section 14.2.1
