Choice states make routing explicit
How Choice states, JSONata expressions, and bounded loops route requests, transform query state, and coordinate iterative agent and moderation workflows. · advanced
A Choice state selects a transition; it does not invoke a model or perform moderation itself. Tasks produce structured facts such as a moderation verdict, request category, or completion flag. Choice rules interpret those facts. With QueryLanguage set to JSONata, each rule has a Boolean Condition and a fixed Next state name. For example, {"Condition":"{% $states.input.verdict = 'deny' %}","Next":"Reject"} routes an explicit denial to a rejection path.
Rules are evaluated in their listed order, and the first matching rule wins. Put overriding policy decisions before more permissive routing decisions. A request can be both classified as technical and denied by moderation; checking its category first could route it to generation before enforcing the denial. A Choice state has no top-level Next or End; its rules and optional Default determine its outgoing transitions.
Use Default deliberately. Without it, an execution fails when no rule matches. For moderation, explicitly match recognized allow and deny verdicts and send anything else to a non-generating validation or rejection path. Default handles unmatched conditions, not expression-evaluation errors. Validate field presence and types before relying on them. Content-based model routing follows the same pattern: validated categories select fixed states whose task configuration identifies approved models.