Using conditional steps
Conditional steps route Flow execution through different paths based on a condition. Use a when condition when you need to gate one step instead of creating branches. For more information, see Skip a single step with when.
Before you begin
Open a Flow in the Flow editor.
Add a conditional step
To add a conditional step, follow these steps:
- In the Flow editor, click Add Step.
- Select Conditional Logic.
- Enter a JavaScript expression in Condition.
- Add steps to If true. These steps run when JavaScript treats the expression result as true.
- Add steps to Otherwise when JavaScript treats the expression result as false or when no added path matches.
- To add another path, click Add path, then enter its condition and add its steps.
- In the Flow editor toolbar, click Save.
Paths run in order. The first path whose condition JavaScript treats as true runs. If no path matches, Otherwise runs. To rename the step, edit its name in the step header.
Write a condition
Enter a JavaScript expression in Condition. Reference variables from earlier steps by their outputVariable names. You can write a variable path such as sentiment.score, or use a template reference such as {{sentiment.score}}. Runtype resolves template references before it evaluates the expression.
For example, this condition routes scores above 0.5 to the true path:
Use these operators in conditions:
===and!==for strict equality and inequality.<,>,<=, and>=for numeric comparisons.&&and||for logical AND and OR.!for negation.
Examples
Use these conditions to route common Flow decisions.
Check AI confidence
Route a high-confidence response to one path with this condition:
Use the AI response in the true path. Route the request to human review in Otherwise.
Route by user tier
Quote the template reference when you compare a string value:
Use the priority support path for premium customers. Use Otherwise for standard support.
Detect an API error
Route the response to error handling when its status differs from 200:
Handle the error in the true path. Process the response in Otherwise.
Combine conditions
Combine numeric and string comparisons with &&:
Require approval in the true path. Auto-approve in Otherwise.
Compare strings
Put quotes around a template reference when the resolved value is a string. This keeps the substituted value valid JavaScript:
Check whether a value exists
Use undefined and null checks to test for a nested value. Compare an array’s length to zero when you need to check whether it contains items:
Nest conditional steps
Add a conditional step inside a branch when you need another decision. This structure runs VIP processing only when both conditions are true:
The validator allows up to 10 nested conditional levels. A Flow with more than 10 levels fails validation. If you need deeper branching, use a transform-data step to calculate a boolean and reference it from one conditional.
Stop on invalid input
Use a conditional branch to route invalid requests to an error path. Put the main processing logic in Otherwise so it runs when validation passes:
Use a transform-data step to calculate one boolean when the validation logic needs several checks.
Access branch outputs
Steps inside conditional branches write variables in the same Flow-level scope as other steps. Set an outputVariable on a branch step, then reference that name in a later step:
Only the selected path runs, so a later step can read a branch variable only when that path writes it. To expose one result from the conditional, set the conditional’s outputVariable. Runtype binds it to the last enabled branch step with a named output.
Test conditional branches
To test every path, run the Flow with inputs that select each path:
- Run the Flow with input that makes the first condition true.
- Confirm that the selected path runs.
- Repeat the test for each additional path.
- Run the Flow with input that matches no path.
- Confirm that Otherwise runs.
Review the execution results to confirm that the selected steps ran and that skipped steps have a skipped status.
Common patterns
Use these patterns to organize validation, feature flags, and fallback behavior.
Validate input
Continue processing when the input is valid and log an error otherwise:
Route by feature flag
Choose an implementation based on a feature flag:
Add fallback logic
Call a backup API when the primary API fails:
Skip a single step with when
Add an optional when condition to any step when you need to run that step only for certain inputs. When JavaScript treats the expression result as false, the step is skipped and the Flow continues. You do not need to wrap the step in a conditional branch.
Use when for a single conditional action, such as a retry after a failure or an enrichment step that runs when data is present.
Set a when condition in the editor
To add a when condition in the Flow editor, follow these steps:
- Find the step that you want to gate.
- Click Always run on the step.
- Enter a JavaScript expression with a maximum length of 500 characters.
- In the Run Condition sheet, click Save.
The control changes to Runs conditionally after you save a condition. The editor adds an amber border to the step and groups consecutive steps that use the same condition.
How skipping works
When JavaScript treats a when condition result as false, the following behavior applies:
- The step does not write its
outputVariable. If an earlier step wrote the same variable, that value remains. - The Flow continues to the next step.
- The execution results show the step as skipped.
Use the same JavaScript expression syntax as a Conditional Logic step. For example, this step runs only when needs_retry is true:
Handle condition errors
If a when expression throws an error, the step is skipped by default. For example, an invalid expression or a missing variable can cause an evaluation error. The Flow continues after the step is skipped.
To stop the Flow when a when expression throws an error, set the step’s error handling to Stop on error.
Choose between when and a conditional step
Use this table to choose between a when condition and a conditional step:
Next steps
- Flow step types overview: choose other steps for your Flow.
- Flow variables and templates: reference inputs and step outputs.
- Using transform-data steps: calculate values before a condition.
- Debugging flows: verify branch execution and skipped steps.