Sim Studio

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 serves as a decision point in your workflow, enabling:

Branching Logic

Create different execution paths based on specific conditions

Rule-Based Routing

Route workflows deterministically without needing an LLM

Data-Driven Decisions

Create workflow paths based on structured data values

If-Then-Else Logic

Implement conditional programming paradigms in your workflows

How It Works

The Condition block:

Evaluate Expression: Evaluates a boolean expression or condition

Determine Result: Determines whether the condition evaluates to true or false

Route Workflow: Routes the workflow to the appropriate path based on the result

Provide Context: Provides context about the decision made

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
input.score > 75

Inputs and Outputs

  • Variables: Values from previous blocks that can be referenced in conditions
  • Conditions: Boolean expressions to evaluate

Example Usage

Here's an example of how a Condition block might be used in a customer satisfaction workflow:

# Example Condition Configuration
conditions:
  - id: "high_satisfaction"
    expression: "input.satisfactionScore >= 8"
    description: "Customer is highly satisfied"
    path: "positive_feedback_block"
    
  - id: "medium_satisfaction"
    expression: "input.satisfactionScore >= 5"
    description: "Customer is moderately satisfied"
    path: "neutral_feedback_block"
    
  - id: "default"
    expression: "true"
    description: "Customer is not satisfied"
    path: "improvement_feedback_block"

Best Practices

Order conditions correctly

Conditions are evaluated in order, so place more specific conditions before general ones. This ensures that more specific logic takes precedence over general fallbacks.

Include a default condition

Add a catch-all condition (e.g., true) as the last condition to handle cases when no other conditions match. This prevents workflow execution from getting stuck.

Keep expressions simple

Use clear, straightforward boolean expressions for better readability. Complex expressions can be difficult to debug and maintain.

Document your conditions

Add descriptions to explain the purpose of each condition. This helps other team members understand the logic and makes maintenance easier.

Test edge cases

Ensure your conditions handle boundary values correctly. Test with values at the edges of your condition ranges to verify correct behavior.

On this page

On this page