Skip to content

Branch on an AI decision

AI is great at judgement calls: is this email urgent? which category is this? But a judgement is only useful in a flow if you can act on it — and you can’t reliably branch on a paragraph of prose. The fix is to make the AI step return a typed value: not “Well, this looks fairly urgent…”, but exactly urgent.

A typed value turns a fuzzy AI judgement into a real, predictable value you can route on. Ask AI → Switch (or Branch) gives you deterministic routing off an AI decision — classify an email and send each kind down a different path, every time.

The Ask AI step has a Response format setting. Leave it on Free text and you get prose. Change it, and Routario coerces the model’s reply into a real value and puts it in the step’s ai_parsed output:

Response formatYou get back
Free textThe text as written
IntegerA whole number
DecimalA number with decimals
Yes / noA true/false value
JSONA parsed object
JSON listA parsed list
ChoiceExactly one value from a list you define

Read the typed result downstream as {{ <label>.ai_parsed }} — for example {{ classify.ai_parsed }}. (The raw, uncoerced text is still available at {{ classify.ai_response }} if you want it.)

Choice is the one that unlocks routing, so the rest of this guide focuses on it.

Pick Choice as the response format and you supply a list of allowed values. Routario steers the model to answer with exactly one of them, then checks the reply against your list and hands back your value. If the model goes off-script, the step fails loudly rather than passing junk downstream.

You type the allowed values into the Enum values field. Routario is forgiving about how you write them — all of these produce the same list, [rock, paper, scissors]:

You enterParsed list
["rock","paper","scissors"] (chips / JSON)[rock, paper, scissors]
rock, paper, scissors (commas)[rock, paper, scissors]
rock paper scissors (spaces)[rock, paper, scissors]
rock; paper; scissors (semicolons)[rock, paper, scissors]
rock ,, paper , (stray spaces / empties)[rock, paper] (blanks dropped)
(empty)the step errors — Choice needs values

Once the model answers, Routario matches it against your list. Matching is lenient about formatting but strict about content — the result is always one of your exact values, in your casing. With the list [rock, paper, scissors]:

The model returnsResult
rockrock
Rock or ROCKrock — matching ignores case, returns your casing
"rock".rock — surrounding quotes and . , ! ? ' " are stripped
rock (with stray spaces or a newline)rock — surrounding whitespace is stripped
I'd pick rockerror — not an exact value
lizarderror: Response 'lizard' is not one of: rock, paper, scissors

A reply that doesn’t match raises an error and the run fails on that step — which is what you want: a misclassification should stop and surface, not quietly flow into the wrong branch. (In practice this is rare: the step instructs the model to answer with just one of the values.)

Worked example: triage incoming support email

Section titled “Worked example: triage incoming support email”

Every inbound support email is auto-sorted into urgent, normal, or spam and routed down a different path.

  1. Incoming email trigger. The flow starts when a message arrives at the flow’s own inbox address. The trigger hands the email to the steps that follow as plain values — {{ from }}, {{ subject }}, {{ body }}, and any {{ attachments }}.

  2. Classify it with Ask AI (label: classify). Add an Ask AI step and set the prompt to:

    Classify this support email.
    Subject: {{ subject }}
    Body: {{ body }}

    Set Response format to Choice and Enum values to urgent, normal, spam. The decision is now available as {{ classify.ai_parsed }} — guaranteed to be exactly one of those three.

  3. Route on the decision with a Switch. Switch on {{ classify.ai_parsed }}, with one case per value:

    • urgent → a Send notification step that pings the on-call channel.
    • normal → add it to the queue — a Create record in your tickets table, or a Create task.
    • spam → leave the case with no onward step; the run just ends and the message is dropped.

Why the Choice format is what makes this work

Section titled “Why the Choice format is what makes this work”

Step 3 can switch on a clean value — urgent — because step 2 is guaranteed to return one of the three options. If step 2 were Free text and replied “This looks pretty urgent to me”, the Switch would have nothing reliable to match. Typed Choice is the contract that lets a deterministic Switch sit downstream of a fuzzy AI judgement.

It ties straight back to the two tables above: the three values can be entered as chips or as urgent, normal, spam; a reply of Urgent or urgent. still resolves to urgent; and a reply of maybe urgent? errors rather than guessing.