If-Else
Conditionally route workflow execution based on typed comparison
Node Type
Conditional
Category
Control Flow
Icon
GitBranch
Overview
The If-Else node is a conditional node that compares two inputs after casting them to specified types and routes workflow execution to one of two paths based on the result. This powerful branching logic enables complex decision-making in your workflows, allowing you to create dynamic paths based on data comparisons and conditions.
Key Features
- • Type Casting: Automatically casts inputs to specified types before comparison
- • Flexible Operations: Supports equals, does not equal, contains, and does not contain
- • Dual Branching: Routes to true path (0) or false path (1) based on condition result
- • Type Safety: Handles string, boolean, and number types with proper casting
- • Condition Tracking: Returns the evaluated boolean result for downstream use
- • Dynamic Routing: Enables complex workflow logic and decision trees
Prerequisites
Workflow Structure
Must have downstream nodes for branching paths
Data Requirements
Technical Requirements
Node Configuration
Required Fields
Input A
The first value to compare. This input will be cast to the specified Type A before comparison. Can be any string value that can be converted to the target type.
Input B
The second value to compare. This input will be cast to the specified Type B before comparison. Can be any string value that can be converted to the target type.
Type A
The data type to cast Input A to before comparison. Available options include string, boolean, and number. Choose the type that matches your comparison needs.
Type B
The data type to cast Input B to before comparison. Available options include string, boolean, and number. Choose the type that matches your comparison needs.
Operation
The comparison operation to perform between Input A and Input B. Available options include equals, does not equal, contains, and does not contain.
Technical Details
Type Casting Process
How the node converts inputs to specified types before comparison
Input Parsing
The node parses and casts inputs using the specified types:
- • String Type: Keeps the original string value
- • Boolean Type: Converts to true/false based on string content
- • Number Type: Converts to numeric value using parseFloat
- • Type Safety: Ensures consistent comparison types
Type Validation
Both inputs are cast to their respective types before comparison, ensuring that the comparison operation works correctly regardless of the original input format.
Comparison Operations
How the node performs different types of comparisons
Equality Operations
Equals: Uses strict equality (===
) to compare the cast values. Does not equal: Uses strict inequality (!==
) for the opposite result.
String Operations
Contains: Converts both values to strings and checks if Input A contains Input B using includes()
.Does not contain: Returns the opposite of the contains check.
Operation Validation
The node validates that the operation is one of the four supported options. If an invalid operation is provided, it throws an error with a descriptive message.
Branch Routing Logic
How the node determines which workflow path to follow
Condition Evaluation
After performing the comparison operation, the node evaluates the result as a boolean. The condition result determines which branch index is returned.
Branch Index Calculation
True Path (0): When the condition evaluates to true, returns [0] to route to the first downstream node. False Path (1): When the condition evaluates to false, returns [1] to route to the second downstream node.
Output Format
Returns an array with a single index for the branch routing, along with the boolean condition result for downstream use and debugging purposes.
Examples & Use Cases
String Equality Check
Compare two string values for exact equality
{
"inputA": "hello",
"inputB": "hello",
"typeA": "string",
"typeB": "string",
"operation": "equals"
}
This will compare the strings "hello" and "hello" using the equals operation. Since they are identical, the condition result will be true and the workflow will follow branch 0.
Numeric Comparison
Compare numeric values after type casting
{
"inputA": "42",
"inputB": "42",
"typeA": "number",
"typeB": "number",
"operation": "equals"
}
This will cast both inputs to numbers (42 and 42) and compare them. Since they are equal, the condition result will be true and the workflow will follow branch 0.
Boolean Logic
Use boolean type casting for logical operations
{
"inputA": "true",
"inputB": "false",
"typeA": "boolean",
"typeB": "boolean",
"operation": "does not equal"
}
This will cast both inputs to booleans (true and false) and check if they are not equal. Since true ≠ false, the condition result will be true and the workflow will follow branch 0.
String Contains Check
Check if one string contains another
{
"inputA": "hello world",
"inputB": "world",
"typeA": "string",
"typeB": "string",
"operation": "contains"
}
This will check if "hello world" contains "world". Since it does, the condition result will be true and the workflow will follow branch 0.
Workflow Examples
User Authentication Flow
Route users based on authentication status
Workflow Structure
If-Else Configuration
{
"inputA": "{{authStatus}}",
"inputB": "authenticated",
"typeA": "string",
"typeB": "string",
"operation": "equals"
}
Implementation Steps
- Auth Check: Determines user authentication status
- If-Else: Compares status with "authenticated" string
- Authenticated Path: Executes when condition is true (branch 0)
- Unauthenticated Path: Executes when condition is false (branch 1)
Data Validation Pipeline
Route data processing based on validation results
Use Case
Automatically route data through different processing paths based on validation results, ensuring data quality and appropriate handling for different data types.
If-Else Configuration
{
"inputA": "{{dataValidationResult}}",
"inputB": "valid",
"typeA": "string",
"typeB": "string",
"operation": "equals"
}
Processing Steps
- Data validation node checks input data quality
- If-Else compares validation result with "valid" string
- Valid data follows branch 0 (normal processing)
- Invalid data follows branch 1 (error handling)
- Each path has appropriate downstream processing
Best Practices
Do's
- • Use appropriate types for your comparison needs (string, boolean, number)
- • Choose the right operation for your use case (equals, contains, etc.)
- • Ensure both inputs can be properly cast to the specified types
- • Use descriptive input values for better workflow readability
- • Test your conditions with various input combinations
- • Use the condition result output for downstream logic when needed
- • Design clear true/false paths for your branching logic
Don'ts
- • Don't use incompatible types for your comparison operation
- • Avoid using contains operations with non-string types
- • Don't forget to connect downstream nodes for both branches
- • Avoid overly complex conditions that are hard to debug
- • Don't assume type casting will always succeed
- • Avoid using the same input values for both Input A and Input B
- • Don't ignore the condition result output for debugging
Troubleshooting
Common Issues
Type Casting Failures
Symptoms: Node fails with type conversion errors or unexpected results
Solution: Ensure your input values can be properly converted to the specified types. For numbers, use valid numeric strings. For booleans, use "true"/"false" or truthy/falsy values.
Unexpected Branch Routing
Symptoms: Workflow follows the wrong branch path
Solution: Check the condition result output to verify the evaluation. Review your input values, types, and operation to ensure they match your intended logic.
Invalid Operation Errors
Symptoms: Node throws "Invalid operation" error
Solution: Ensure the operation field contains one of the four valid options: "equals", "does not equal", "contains", or "does not contain".
Missing Downstream Nodes
Symptoms: Workflow fails when trying to follow a branch
Solution: Ensure you have connected downstream nodes for both branch 0 (true path) and branch 1 (false path). The If-Else node requires both paths to be defined.