Visual Workflow AI

Condition

Create conditional logic and branching in your workflows

The Condition block allows you to branch your workflow execution path based on boolean expressions. It evaluates conditions and routes the workflow accordingly, enabling you to create dynamic, responsive workflows with different execution paths.

Condition blocks enable deterministic decision-making without requiring an LLM, making them ideal for straightforward branching logic.

Overview

The Condition block enables you to:

Create branching logic: Route workflows based on boolean expressions

Make data-driven decisions: Evaluate conditions using previous block outputs

Handle multiple scenarios: Define multiple conditions with different paths

Provide deterministic routing: Make decisions without requiring an LLM

How It Works

The Condition block operates through a sequential evaluation process:

  1. Evaluate Expression - Processes the JavaScript/TypeScript boolean expression using current workflow data
  2. Determine Result - Returns true or false based on the expression evaluation
  3. Route Workflow - Directs execution to the appropriate destination block based on the result
  4. Provide Context - Generates metadata about the decision for debugging and monitoring

Configuration Options

Conditions

Define one or more conditions that will be evaluated. Each condition includes:

  • Expression: A JavaScript/TypeScript expression that evaluates to true or false
  • Path: The destination block to route to if the condition is true
  • Description: Optional explanation of what the condition checks

You can create multiple conditions that are evaluated in order, with the first matching condition determining the execution path.

Condition Expression Format

Conditions use JavaScript syntax and can reference input values from previous blocks.

// Check if a score is above a threshold
<agent.score> > 75
// Check if a text contains specific keywords
<agent.text>.includes('urgent') || <agent.text>.includes('emergency')
// Check multiple conditions
<agent.age> >= 18 && <agent.country> === 'US'

Accessing Results

After a condition evaluates, you can access its outputs:

  • <condition.result>: Boolean result of the condition evaluation
  • <condition.matched_condition>: ID of the condition that was matched
  • <condition.content>: Description of the evaluation result
  • <condition.path>: Details of the chosen routing destination

Advanced Features

Complex Expressions

Use JavaScript operators and functions in conditions:

// String operations
<user.email>.endsWith('@company.com')

// Array operations
<api.tags>.includes('urgent')

// Mathematical operations
<agent.confidence> * 100 > 85

// Date comparisons
new Date(<api.created_at>) > new Date('2024-01-01')

Multiple Condition Evaluation

Conditions are evaluated in order until one matches:

// Condition 1: Check for high priority
<ticket.priority> === 'high'

// Condition 2: Check for urgent keywords
<ticket.subject>.toLowerCase().includes('urgent')

// Condition 3: Default fallback
true

Error Handling

Conditions automatically handle:

  • Undefined or null values with safe evaluation
  • Type mismatches with appropriate fallbacks
  • Invalid expressions with error logging
  • Missing variables with default values

Inputs and Outputs

  • Conditions: Array of boolean expressions to evaluate

  • Expressions: JavaScript/TypeScript conditions using block outputs

  • Routing Paths: Destination blocks for each condition result

  • condition.result: Boolean result of condition evaluation

  • condition.matched_condition: ID of the matched condition

  • condition.content: Description of evaluation result

  • condition.path: Details of chosen routing destination

  • Boolean Result: Primary condition evaluation outcome

  • Routing Information: Path selection and condition details

  • Access: Available in blocks after the condition

Example Use Cases

Customer Support Routing

Scenario: Route support tickets based on priority

  1. API block fetches support ticket data
  2. Condition checks if <api.priority> equals 'high'
  3. High priority tickets → Agent with escalation tools
  4. Normal priority tickets → Standard support agent

Content Moderation

Scenario: Filter content based on analysis results

  1. Agent analyzes user-generated content
  2. Condition checks if <agent.toxicity_score> > 0.7
  3. Toxic content → Moderation workflow
  4. Clean content → Publishing workflow

User Onboarding Flow

Scenario: Personalize onboarding based on user type

  1. Function block processes user registration data
  2. Condition checks if <user.account_type> === 'enterprise'
  3. Enterprise users → Advanced setup workflow
  4. Individual users → Simple onboarding workflow

Best Practices

  • Order conditions correctly: Place more specific conditions before general ones to ensure specific logic takes precedence over fallbacks
  • Include a default condition: Add a catch-all condition (true) as the last condition to handle unmatched cases and prevent workflow execution from getting stuck
  • Keep expressions simple: Use clear, straightforward boolean expressions for better readability and easier debugging
  • Document your conditions: Add descriptions to explain the purpose of each condition for better team collaboration and maintenance
  • Test edge cases: Verify conditions handle boundary values correctly by testing with values at the edges of your condition ranges