Building AI Routing Workflows
Introduction & Context
Welcome back! In the previous lesson, you learned how to use prompt chaining to connect multiple Claude API calls in a linear sequence, breaking down complex tasks into manageable steps. This approach works well when you know exactly what sequence of operations is needed.
However, real-world applications often face unpredictable requests that require different types of expertise. Instead of building separate chains for every possible request, routing workflows use Claude to analyze incoming requests and intelligently direct them to the right specialist — such as a math expert, a writing expert, or a code expert.
This lesson will show you how to build a flexible routing system that maintains high-quality responses by leveraging specialized system prompts for each domain.
Workflow Design at a Glance
The routing workflow follows a clean two-step pattern that's more dynamic than the linear chains you've used before. When a user submits a request, your system first sends it to a router — a Claude instance with a specialized system prompt designed to classify the request type. The router analyzes the content and returns a decision about which specialist should handle it.
Once you have the routing decision, you send the original user request to a second Claude instance configured with the appropriate specialist system prompt. This specialist focuses entirely on providing the best possible response within their domain of expertise, whether that's solving equations, crafting stories, or debugging code.
The key insight here is that you're using the same Anthropic API and the same Claude model for both calls, but with completely different system prompts that give each instance a distinct role and expertise. The router acts as a classifier, while the specialist acts as a domain expert. This separation of concerns makes your system both more reliable and easier to extend with new specialist types.
Crafting the Router Prompt
The router prompt is the critical component that determines how accurately your system classifies incoming requests. Unlike the open-ended prompts you might use for creative tasks, router prompts need to be strict and constrained to ensure reliable, parseable output.
Your router system prompt should establish Claude's role as a decision-maker and provide clear, unambiguous options. Here's an effective approach that limits the router to exactly three choices:
The phrase Respond with ONLY is crucial because it prevents Claude from adding explanatory text or reasoning that would complicate parsing the response. You want exactly one of three possible strings, nothing more. The explicit list of specialist names with their descriptions helps Claude understand the boundaries between categories and reduces ambiguous classifications.
Notice how each specialist description focuses on clear, distinct domains. Mathematical problems are clearly different from creative writing, which is clearly different from programming tasks. This separation reduces edge cases where the router might struggle to choose between specialists.
