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:

  1. In the Flow editor, click Add Step.
  2. Select Conditional Logic.
  3. Enter a JavaScript expression in Condition.
  4. Add steps to If true. These steps run when JavaScript treats the expression result as true.
  5. Add steps to Otherwise when JavaScript treats the expression result as false or when no added path matches.
  6. To add another path, click Add path, then enter its condition and add its steps.
  7. 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:

sentiment.score > 0.5

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:

analysis_result.confidence > 0.8

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:

'{{customer_data.tier}}' === 'premium'

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:

api_result.status !== 200

Handle the error in the true path. Process the response in Otherwise.

Combine conditions

Combine numeric and string comparisons with &&:

order_total > 1000 && '{{customer_data.tier}}' === 'standard'

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:

'{{sentiment_result.label}}' === 'negative'
'{{process_status}}' !== 'completed'

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:

customer_data.email !== undefined && customer_data.email !== null
order_history.length > 0

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:

Main conditional: Is the tier premium?
If true:
Nested conditional: Is the order greater than $5000?
If true: VIP processing
Otherwise: Premium processing
Otherwise: Standard processing

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:

Conditional: Is the request valid?
If true: Continue processing
Otherwise: Log the validation error

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:

{{branch_result}}

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:

  1. Run the Flow with input that makes the first condition true.
  2. Confirm that the selected path runs.
  3. Repeat the test for each additional path.
  4. Run the Flow with input that matches no path.
  5. 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:

Conditional: Is the input valid?
If true: Continue processing
Otherwise: Log the validation error

Route by feature flag

Choose an implementation based on a feature flag:

Conditional: Is the feature enabled?
If true: Use the alternate implementation
Otherwise: Use the standard implementation

Add fallback logic

Call a backup API when the primary API fails:

Conditional: Did the primary API succeed?
If true: Use the primary response
Otherwise: Call the backup API

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:

  1. Find the step that you want to gate.
  2. Click Always run on the step.
  3. Enter a JavaScript expression with a maximum length of 500 characters.
  4. 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:

needs_retry === 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:

Featurewhen conditionConditional step
ScopeGates one step.Selects one path.
BranchesRuns or skips the step.Runs the first matching path or Otherwise.
OutputDoes not write the step’s outputVariable when skipped.Branch steps write their own outputs.
Use it whenOne step needs a condition.You need separate paths.

Next steps