A Choice state adds conditional branching to a flow. It evaluates conditions against the input data and routes execution to the first matching branch, similar to a switch-case statement in programming.
How it works
When a flow reaches a Choice state, the system evaluates each branch's condition in order:
If a condition evaluates to
true, the flow transitions to the state specified in that branch'sNextfield.If no condition evaluates to
true, the flow transitions to the state specified in theDefaultfield.
The Default field is required. This ensures the flow always has a valid transition path, even when no branch conditions match.
Choice states do not support the End and Next attributes at the state level. Use the Default attribute to define the fallback transition. Each ChoiceBranch defines its own Next attribute to specify where the flow goes when the condition is met.
Attributes
Attribute | Type | Required | Description | Example |
Name | string | Yes | The state name. | my state |
Description | string | No | A description of the state. | describe it here |
Type | string | Yes | The state type. Set to | Choice |
InputConstructor | map[string]any | No | The input constructor. For more information, see Inputs and outputs. | -- |
Default | string | Yes | The fallback state to transition to when no branch condition evaluates to | my next task |
Branches | ChoiceBranch[] | Yes | An array of choice branches. See the ChoiceBranch table. | -- |
ChoiceBranch
Each entry in the Branches array contains the following attributes:
Attribute | Type | Required | Description | Example |
Condition | string | Yes | A conditional expression that evaluates to |
|
Next | string | Yes | The state to transition to when the condition evaluates to | my next task |
Example
The following flow routes execution based on the value of $Input.data:
If
$Input.dataequals"ready", the flow transitions to thePass1state.Otherwise, the flow transitions to the default
Pass2state.
Type: StateMachine
Name: MyWorkflow
SpecVersion: v1
StartAt: Choice
States:
- Type: Choice
Name: Choice
Branches:
- Condition: $Input.data == "ready"
Next: Pass1
Default: Pass2
- Type: Pass
Name: Pass2
End: true
- Type: Pass
Name: Pass1
End: trueConditional expressions
Conditional expressions combine variables, constants, and operators to produce a Boolean result (true or false). Use the $Input variable to reference state input data and the $Context variable to reference flow context data. For more information, see Data passing.
Supported operators
Category | Operators | Applicable types |
Comparison |
| Strings, numbers |
Logical |
| Boolean expressions |
Prefix |
| Boolean expressions, numbers |
Inclusion |
| Arrays (check if a value exists), objects (check if a key exists) |
Supported constants
Type | Syntax | Examples |
String | Double quotes ( |
|
Numeric | Integer or decimal |
|
Boolean | Lowercase keywords |
|
Expression examples
Given the following $Input data, the tables below show how different expressions evaluate:
{
"a": 1,
"b": {
"b1": true,
"b2": "ready"
},
"c": [1, 2, 3],
"d": 1,
"e": 1,
"f": {
"f1": false,
"f2": "inprogress"
}
}Numeric comparisons
Expression | Result | Description |
| true | Equal to a literal value |
| false | Not equal to the literal value |
| true | Greater than |
| true | Literal on the left side |
| true | Greater than or equal to |
| true | Not equal to |
Boolean comparisons
Expression | Result | Description |
| true | Direct Boolean reference |
| true | Explicit comparison to |
| false | Explicit comparison to |
String comparisons
Expression | Result | Description |
| true | String equality |
| false | String inequality |
Compound expressions
Expression | Result | Description |
| true | Both conditions are true |
| false | First condition is false |
Array and variable-to-variable comparisons
Expression | Result | Description |
| true | Access array element by index |
| true | Compare two variables |
Inclusion checks
Expression | Result | Description |
| true | Key exists in the object |
| false | Key does not exist |
| true | Value exists in the array |