Route Data with the Switch Node
Most of the time, an IF node is enough. You check a condition, things go left or right, done.
But sometimes you hit a point in your workflow where you need more than two directions. I run into this constantly with AI classifiers. Say you have incoming emails and an AI that categorizes each one as support, sales, complaint, or info. That's four categories. An IF node gives you two outputs. You'd need to chain three IF nodes together, and that gets ugly fast.
The Switch node handles this. One node, as many outputs as you need, each with its own rule. And the part I like most: you can name each output, so the arrows in your workflow actually say "Support" or "Sales" instead of "Output 0" and "Output 1". When you have five or six branches coming out of one node, those labels are the only thing keeping the workflow readable.
In this exercise, you'll build exactly that: a Gmail workflow where an AI classifies incoming emails and a Switch node routes each one to a named output. The full pattern, from trigger to classification to routing, in one workflow.
What you'll practice:
- Using the Switch node in Rules mode
- Creating multiple routing rules
- Naming outputs for readability
- Handling unmatched items with a fallback output
- Connecting an AI classifier to a Switch node
Your Task
- 1Copy the exercise below
- 2Paste into your n8n editor (Ctrl+V)
- 3Solve it — use hints if you get stuck
- 4Check the solution when done
Build a workflow that classifies incoming emails with AI and routes them to named outputs:
- Gmail Trigger watches for new unread emails in your inbox
- OpenAI classifies each email as: support, sales, complaint, or info
- Switch routes by the AI's classification to named outputs
- Edit Fields on each branch labels the email with its category
Your Switch node should have these outputs:
- "Support" for support emails
- "Sales" for sales emails
- "Complaint" for complaint emails
- "Info" for info emails
- "Other" as a fallback for anything the AI can't classify
Expected result: When an email arrives, the AI classifies it, the Switch routes it to the matching output, and the Edit Fields node labels it. The arrows on the Switch node should display the output names.
Get the exercise workflow
Create a free account to copy exercises into your n8n editor.