if_else
Route events through different processing paths based on conditions.
Overview
Route events through different processing paths based on conditions. This step provides if/else-if/else conditional logic with nested step execution. It evaluates conditions in order and executes the steps in the first matching branch. Conditions within a branch use AND logic (all must be true), while branches themselves act as OR logic (first match wins). This enables complex routing scenarios like A/B testing, data validation with different handling paths, user segmentation, or any workflow where processing logic depends on data values. Each branch can contain any number of nested steps that execute only when that branch's conditions are met. The step also injects metadata about which branch matched.
Quick Start
steps:
- type: if_else
else: null
if: nullConfiguration
| Parameter | Type | Required | Description |
|---|---|---|---|
if | string | Yes | Required. Primary conditional branch evaluated first. |
else_if | string | No | Optional. Additional conditional branches evaluated in order if 'if' fails. |
else | string | Yes | Required. Default branch executed if no conditions match. |
output_to | string | No | Optional key to inject metadata about which branch was taken (e.g., 'if_else_result'). |
inject | string | No | DEPRECATED: Use 'output_to' instead. Optional key for branch metadata. |
Examples
Simple condition routing
Route based on a single field value
type: if_else
if:
conditions:
- field: user.status
op: eq
value: premium
steps:
- type: print
template: "Processing premium user ${user.email}"
else:
steps:
- type: print
template: "Processing free user ${user.email}"
Multi-condition AND logic
Require multiple conditions to be true (verified AND adult)
type: if_else
output_to: eligibility_check
if:
conditions:
- field: user.verified
op: eq
value: true
- field: user.age
op: gte
value: 18
steps:
- type: print
text: "User is eligible"
else:
steps:
- type: print
text: "User not eligible"
Grade calculation with multiple branches
Use else_if for multiple score ranges
type: if_else
output_to: grade_assignment
if:
conditions:
- field: score
op: gte
value: 90
steps:
- type: python_function
code: |
def process(event):
event['grade'] = 'A'
event['message'] = 'Excellent!'
return event
handler: process
else_if:
- conditions:
- field: score
op: gte
value: 80
steps:
- type: python_function
code: |
def process(event):
event['grade'] = 'B'
event['message'] = 'Good job!'
return event
handler: process
- conditions:
- field: score
op: gte
value: 70
steps:
- type: python_function
code: |
def process(event):
event['grade'] = 'C'
event['message'] = 'Passed'
return event
handler: process
else:
steps:
- type: python_function
code: |
def process(event):
event['grade'] = 'F'
event['message'] = 'Failed'
return event
handler: process
Complex nested processing
Different API calls based on user tier
type: if_else
if:
conditions:
- field: user.tier
op: eq
value: enterprise
steps:
- type: http_call
url: https://api.example.com/enterprise/process
method: POST
body: ${data}
inject: api_result
- type: print
template: "Enterprise processing complete"
else_if:
- conditions:
- field: user.tier
op: eq
value: professional
steps:
- type: http_call
url: https://api.example.com/pro/process
method: POST
body: ${data}
inject: api_result
else:
steps:
- type: http_call
url: https://api.example.com/basic/process
method: POST
body: ${data}
inject: api_result
Advanced Options
These options are available on all steps for error handling and retry logic:
| Parameter | Type | Default | Description |
|---|---|---|---|
retries | integer | 0 | Number of retry attempts (0-10) |
backoff_seconds | number | 0 | Backoff (seconds) applied between retry attempts |
retry_propagate | boolean | false | If True, raise last exception after exhausting retries; otherwise swallow. |