Skip to main content
A choice picks exactly one case from a boolean or a closed string enum that an earlier step produced. It doesn’t evaluate conditions or make judgments: produce the decision first, with a task, an agent or a function through call, then route on it.

Syntax

choice id=route-filing
With region outputs, every case that continues must bind them:
choice id=route-portfolio

Fields

The fence takes no attributes after id, and its body takes no other fields.

What you can route on

on must point to a required member whose schema is boolean or a string enum, read from an input or an earlier step’s output. Open strings, numbers, null, arrays, objects, optional members and unions can’t be routed. Expressions such as $approval.score > 80 aren’t allowed; compute a boolean or enum in an earlier step.

Cases

Case keys are strings. Quote them so YAML keeps them as strings.
  • For a boolean, the keys are exactly 'true' and 'false'.
  • For an enum, the keys are exactly the enum’s values.
  • Every value appears exactly once. There is no default case.
Each case is one of four forms: Inline cases hold only data: literals, built objects and references. Anything that does work, such as a task, call, wait or agent, goes in a heading body. Several case keys can share one heading body. For example, 'approved' and 'approved-with-modifications' can both point to '#promote-package'.

Heading bodies

A heading body is a child heading of the section that holds the choice. The rules:
  • The choice is the last fence in its section.
  • Each '#block' target is a direct child heading of that section. Use a custom ID, such as ### Use the snapshot {#use-snapshot}, so renaming the heading doesn’t change the target.
  • The headings the choice uses come first among the section’s child headings, one after another.
  • After a body finishes, the run continues at the first child heading the choice doesn’t use. If there is none, it continues at the next heading after the section.
  • A body can contain any steps, including a nested choice, repeat or for-each, and can end the run with complete.
A choice whose every case ends the run needs nothing after it.

Region outputs

outputs declares the values the choice hands to later steps. Every case that continues must bind each declared output exactly once:
  • an inline outputs case binds all of them by itself;
  • a heading body binds each one with an ordinary step whose output has that name, on every path that reaches the end of the body.
Cases that end the run don’t bind outputs. After the choice, read an output by its own name, such as $portfolio_source, not through the choice’s ID. Values a body binds that aren’t declared outputs stay inside the body and can’t be read after the choice. If cases produce different shapes, declare an output schema with nullable members, and collapse them with ?? in a later value node.

Example

A minimal approval route, with a body for one value and an inline end for the other:
This procedure reads a policy’s balance from billing. If billing is down, it falls back to last night’s export; if billing has no such policy, it ends at once. Both the live and the fallback path bind balance, which later steps read. A second choice uses continue for the past-due case. The policy values and hosts are illustrative.
balance-check.procedure.md
The two effects return fixed balances to keep the example short. A real effect would parse the response from your billing system.

On retry and resume

  • Routing follows the data. The choice reads the recorded value of on and selects the matching case. It never calls anything, so a resumed run selects the same case again.
  • No override. A run can’t take the 'true' case while on is false. To route differently, the value itself has to change.
  • Outputs appear together. A body’s declared outputs become visible to later steps in one step when the body ends, never one at a time. When a nested choice or loop ends at the same time as its enclosing body, every level closes together.
  • Ending inside a body. When a body reaches complete, the run ends, and the choice and every enclosing construct are recorded as finished. If a step in a body fails, the run fails, and enclosing steps aren’t marked finished.

Common errors

See also