Conditional
Control workflow execution by defining conditions that determine whether steps should run or be skipped.
The conditional feature in steps allows you to control step execution based on specified conditions. When a condition is defined, the step will only execute if the condition evaluates to true
. If the condition evaluates to false
, the step will be skipped with a status of ‘SKIPPED’.
Enabling Conditional
To enable conditional for a step:
- Click the step’s options menu (⋮)
- Click
Add Conditional
- Enter a condition in the Conditional Expression field that will determine whether the step should run
Conditional Expression
- A conditional is a JavaScript expression that evaluates to a boolean value
- Defined using the
conditional
property in step configuration - Must return
true
orfalse
- Cannot contain async operations
Expression Rules
Conditional expressions must follow specific rules to ensure proper execution.
Syntax Requirements
Valid Conditional Patterns
Invalid Patterns
Common Conditional Patterns
Here are frequently used patterns for writing conditional expressions in workflows. These patterns demonstrate best practices for handling different types of checks and comparisons.
Input-Based Conditions
Previous Step Output Conditions
Array and Object Handling
Error Handling
Here are some best practices for error handling in conditional expressions.
Conditional Evaluation Errors
Step Skip Handling
When a step is skipped due to a conditional evaluating to false
, subsequent steps need to handle this gracefully when accessing the output of the skipped step. The following example shows how to properly check for and handle skipped steps in your workflow:
Common Issues and Solutions
Here are some common issues you might encounter when writing conditionals and their recommended solutions:
- Undefined Property Access
- Invalid Boolean Expressions
- Complex Logic
Examples
Below are practical examples demonstrating how to effectively use conditionals in different workflow scenarios. These examples showcase proper syntax, best practices, and common use cases for conditional step execution.
Document Processing Workflow
This example demonstrates a document processing workflow that uses conditionals to control the execution flow:
- A PDF document is uploaded via a dropzone input
- The
CODE_VALIDATE_INPUT
step validates that it’s a PDF file and checks its size - The
MODEL_ANALYZE
step only runs if validation passes and file is under 10MB - The
CODE_PROCESS_RESULTS
step processes the analysis results if they exist - Finally, a simple code step demonstrates the end of the workflow
Was this page helpful?