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

At least two downstream nodes connected
Clear understanding of true/false paths
Proper workflow logic design

Data Requirements

Understanding of data types and comparisons

Input Values: Two comparable values for the condition evaluation
Type Compatibility: Understanding of how types will be cast and compared
Operation Logic: Clear understanding of the comparison operation being used

Technical Requirements

System capabilities needed

Branching Support: Workflow engine must support conditional branching
Type Casting: Ability to cast values to string, boolean, or number types
Path Routing: System routes execution to branch 0 (true) or branch 1 (false)

Node Configuration

Required Fields

inputType

Type:dropdown
Required:Yes
Value Type:string, boolean, number

The type to cast both inputs to before comparison. All comparisons happen after casting to this type. Choose the type that best matches your data.

operation

Type:dropdown
Required:Yes
Value Type:equals, does not equal, contains, does not contain

The comparison operation to perform. Equals checks for exact match, does not equal checks for difference, contains checks if first value includes second (string/array), does not contain checks if first value excludes second.

input1

Type:text
Required:Yes
Value Type:any

The first value to compare. Will be cast to the specified inputType before comparison.

input2

Type:text
Required:Yes
Value Type:any

The second value to compare. Will be cast to the specified inputType before comparison.

Examples & Use Cases

String Comparison

Check if email domain matches company domain

{
  "inputType": "string",
  "operation": "contains",
  "input1": "{{userEmail}}",
  "input2": "@company.com"
}

Routes to true path if the email contains "@company.com", false path otherwise. Useful for filtering internal vs external users.

Number Threshold

Route based on numeric value comparison

{
  "inputType": "number",
  "operation": "equals",
  "input1": "{{orderTotal}}",
  "input2": "0"
}

Checks if order total equals zero. Can be used to skip payment processing for free orders.

Boolean Status Check

Route based on boolean flag

{
  "inputType": "boolean",
  "operation": "equals",
  "input1": "{{user.isVerified}}",
  "input2": "true"
}

Routes verified users to one path and unverified users to another path for different handling.

Exclusion Check

Check if value does NOT contain unwanted content

{
  "inputType": "string",
  "operation": "does not contain",
  "input1": "{{emailSubject}}",
  "input2": "spam"
}

Filters out emails that contain "spam" in the subject line.

Best Practices

Do's

  • Choose the correct input type for your data
  • Use clear, meaningful comparison values
  • Connect different nodes to each branch for proper routing
  • Test both true and false paths in your workflow
  • Use the condition output for debugging and logging
  • Consider type casting behavior when designing conditions

Don'ts

  • Don't forget that types are cast before comparison
  • Avoid using contains operation with number types
  • Don't create conditions that always evaluate to the same result
  • Avoid deeply nested if-else chains (consider AI Router instead)
  • Don't ignore the condition output for audit trails
  • Avoid comparing incompatible data types without proper casting
💡
Pro Tip: When working with complex conditions, use the condition output field to log the result. This makes debugging much easier. For multiple conditions, consider using the AI Router node instead of chaining many If-Else nodes.

Troubleshooting

Common Issues

Unexpected Routing

Symptoms: Workflow routes to wrong branch

Solution: Check the inputType and ensure both values are being cast correctly. Remember that casting happens before comparison. Test with explicit values first before using template variables.

Contains Not Working

Symptoms: Contains operation doesn't find substring

Solution: Ensure inputType is set to 'string'. The contains operation works on strings and arrays. Check for case sensitivity and whitespace issues.

Boolean Comparison Issues

Symptoms: Boolean comparisons give unexpected results

Solution: When using boolean type, ensure values are exactly 'true' or 'false'. Truthy values (like '1', 'yes') may not cast as expected. Use explicit boolean values.

Related Resources