Skip to main content
Evaluate custom Python code and redirect to ‘true’ or ‘false’ branch. Useful for conditional logic.

Overview

The If-Else block evaluates a Python expression and routes workflow execution to either a True or False branch based on the result. Use it to create conditional logic in your blueprints, enabling different actions based on data conditions. The expression must be a single Python expression that evaluates to a Boolean value. You can use variables, comparison operators, logical operators, and built-in Python functions in your expression.

Common use cases

  • Validating user input before processing
  • Checking if data meets specific criteria
  • Routing workflows based on configuration settings
  • Implementing business rules and decision logic
  • Verifying API responses or data availability

How it works

  1. Expression: Enter a Python expression that evaluates to True or False. The expression must be a single expression, not multiple statements.
  2. Evaluation: The block evaluates the expression using the Python interpreter.
  3. Routing: Based on the result:
    • If the expression evaluates to True, the workflow continues to the True branch
    • If the expression evaluates to False, the workflow continues to the False branch
    • If an error occurs during evaluation, the workflow continues to the Error branch
The block has access to state variables, execution environment variables, and standard Python operations.

Expression examples

state["age"] >= 18

Examples

Data quality validation

This example shows how to validate API response data before processing it further in the workflow. Blueprint Flow:
  1. HTTP Request → Fetches data from external API
  2. If-Else → Validates response contains required fields 3a. True branch → Text generation → Processes valid data 3b. False branch → Log message → Records validation failure
Block Configuration:
  • Expression: isinstance(result, dict) and "data" in result and len(result["data"]) > 0
This workflow ensures data quality before processing, preventing errors downstream.

Score-based routing

This example demonstrates routing users to different workflows based on their performance score. Blueprint Flow:
  1. UI Trigger → User completes assessment
  2. Python code → Calculates total score
  3. If-Else → Checks if score meets passing threshold 4a. True branch → Text generation → Generates certificate 4b. False branch → Text generation → Generates improvement recommendations
Block Configuration:
  • Expression: state["total_score"] >= state["passing_threshold"]
This workflow provides personalized responses based on user performance metrics.
Choosing the right block:
  • Use If-Else for rule-based logic with exact conditions: numeric comparisons (age >= 18), data validation ("email" in state), checking Boolean flags, or evaluating structured data. Best when you know the exact criteria to evaluate.
  • Use Classification for content-based routing: categorizing text by topic, sentiment, or intent. Best when you need AI to understand natural language meaning and route to multiple categories (for example, classifying support tickets as “Technical”, “Billing”, or “General”).
  • Use Python code before If-Else for complex logic: when you need multiple statements, loops, or calculations before the conditional check. Store the result in state, then reference it in the If-Else expression.
Expression requirement: The If-Else block accepts only a single Python expression that evaluates to a Boolean value, not multiple statements.

Fields

NameTypeControlDefaultDescriptionOptionsValidation
ExpressionEval--The expression to be evaluated. Must be a single expression (no statements).--

End states

Below are the possible end states of the block call.
NameFieldTypeDescription
True-successThe event handler execution for True.
False-successThe event handler execution for False.
Error-errorThe expression evaluation failed.