# If/Else Routing on Structured Fields — OpenAI Agent Builder Workflows

Source: https://www.skillbyai.com/en/openai-agent-builder/l-ifelse

> 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.](assets/figures/openai-agent-builder/section-3-map.svg) — Figure 3.1 — Branch, loop and approve.

## Routing table for a support flow

Write conditions as a table before building them.

```text
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.

**Quiz:** What should an if/else node ideally branch on?

- [ ] Random numbers
- [ ] The model's mood
- [x] 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.
