Lesson 8 / 26

If/Else Routing on Structured Fields

Branch on data, not on vibes.

Conditions over state

An if/else node evaluates a condition over the workflow state and picks a branch. Conditions are most reliable when they test structured fields produced by earlier nodes (category equals billing, amount above 100, urgent is true) rather than asking another model to decide. Keep conditions simple, cover the else case explicitly, and order branches from most specific to most general. Agent Builder evaluates conditions with an expression language (CEL at the time of writing); in code they are ordinary if statements. Product details such as node names and menus change; check the current OpenAI documentation.

Control the path explicitly

Deterministic logic around model calls makes workflows predictable and safe.

Three ideas: branch, loop, approve.
Figure 3.1 — Branch, loop and approve.

Routing table for a support flow

Write conditions as a table before building them.

condition                                         next node
category == "refund" && amount > 100              user approval
category == "refund"                              refund agent
category == "technical"                           tech agent (with docs search)
urgent == true                                    escalate to human
else                                              general answer agent

Never leave else empty

An unhandled case should go somewhere safe, such as a general agent or a human queue.

Quick check: What should an if/else node ideally branch on?

  • Random numbers
  • The model's mood
  • Structured fields produced by earlier nodes
  • The length of the system prompt
Answer

Structured fields produced by earlier nodes — Deterministic conditions on data are testable.