If-Else - Writer AI Studio

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

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:

The block has access to state variables, execution environment variables, and standard Python operations.

Expression examples

Comparing values

Checking data presence

Multiple conditions

Type checking

String operations

state["age"] >= 18
"email" in state and state["email"]
state["score"] > 80 and state["completed"] == True
isinstance(payload, dict) and "user_id" in payload
state.get("status", "").lower() == "approved"

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:

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:

This workflow provides personalized responses based on user performance metrics.

Choosing the right block:

Expression requirement: The If-Else block accepts only a single Python expression that evaluates to a Boolean value, not multiple statements.

Fields

Name Type Control Default Description Options Validation
Expression Eval - - The expression to be evaluated. Must be a single expression (no statements). - -

End states

Below are the possible end states of the block call.

Name Field Type Description
True - success The event handler execution for True.
False - success The event handler execution for False.
Error - error The expression evaluation failed.