Implement Branching with Triage Fields
Explore how to implement branching in AI automation workflows by routing messages based on normalized triage fields like category and priority. Learn to handle multiple paths reliably using deterministic rules, normalize data to avoid routing errors, verify routing through run history, and log decisions for auditing. This lesson ensures you can safely route workflow items and maintain transparency in AI-driven processes.
We'll cover the following...
The last lesson got an LLM producing a structured triage_json object for every incoming message. Now it’s time to put that output to work: two emails enter the same workflow and the router takes different paths because the branch conditions read triage.category, triage.priority, and triage.needs_human, not free form text. One email about a surprise charge can route to billing with high priority, while another describing an app crash can route to technical with normal priority, even if both messages contain overlapping words like “urgent” or “broken.” Along the way, we’ll normalize the LLM’s output before routing on it, verify paths using run history evidence, and log the decision for later auditing.
A representative triage JSON output that supports deterministic routing looks like this.
{"category": "billing","priority": "high","needs_human": false,"next_action": "reply"}
Before touching router settings, the branch rules should exist as plain English checks that match the schema.
Review: needs_human==true routes to a review path.
Billing urgent: category=="billing" && priority=="high" routes to a billing urgent path.
Technical normal: category=="bug" && priority=="normal" routes to a technical normal path.
Default: Everything else routes to a default path.
Next, we translate those checks into the router's paths and keep the path set small enough to reason about during testing.
The router diagram only works if every condition reads a small enum or a boolean that was validated. The rule to apply is to branch on small enums and booleans and avoid substring matching on generated prose like searching for urgent inside a model written explanation.
The router in n8n
In n8n, the router is a Switch node. We add it to the Support Inbox Triage workflow after the storage step from the last lesson, with a normalization step in front of it and one logging step on each path.
The mapping step now sends two messages instead of one: the surprise charge and the app crash from the opening paragraph. Both contain the words "urgent" and "broken". The numbers on the lines after the router show where each one went: one item to Billing Urgent and one to Technical Normal.
The Switch ...