> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langdock.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Condition

> Route workflow execution down different paths based on conditions and logic.

<img src="https://mintcdn.com/langdock-34/cWyoB3RsITQmAUnM/images/workflows/nodes/condition.jpg?fit=max&auto=format&n=cWyoB3RsITQmAUnM&q=85&s=aab693db6c3e938d6eebe4ef6a4e1730" alt="Condition" width="1920" height="903" data-path="images/workflows/nodes/condition.jpg" />

## Overview

The Condition node adds branching logic to your workflow. Based on data from previous nodes, route execution down different paths - like if-then-else statements in code, but visual and no-code.

<Info>
  **Best for**: Approval workflows, priority routing, data validation,
  multi-path automations, and decision logic.
</Info>

## How It Works

1. Add multiple conditions (If, Else if, etc.)
2. Each condition evaluates to true/false using Manual or Prompt AI mode
3. By default, the **first** matching condition is executed
4. Enable "Allow multiple conditions" to execute **all** matching paths
5. Each condition gets its own output handle on the node

## Configuration

### Model Selection

Choose the AI model used for Prompt AI mode conditions. This only applies when using Prompt AI mode—Manual mode doesn't use AI.

### Condition Modes

Each individual condition can use one of two modes:

**Manual Mode**
Write expressions inside `{{ }}` brackets:

```handlebars theme={null}
{{ trigger.output.amount > 1000 }}
{{ agent.output.sentiment === "negative" }}
{{ trigger.output.email.includes("@company.com") }}
```

<Note>
  **Important**: All manual expressions must be wrapped in `{{}}` brackets.
</Note>

**Prompt AI Mode**
Give natural language instructions for the AI to evaluate:

```text theme={null}
Determine if this customer message requires urgent attention based on:
- Keywords like "urgent", "emergency", "asap"
- Angry or frustrated tone
- Mention of high-priority issues

Context: {{trigger.output.message}}
```

### Allow Multiple Conditions

**Disabled (default)**: First match wins

* Conditions evaluated in order (top to bottom)
* Only the first matching condition executes
* Other conditions are skipped
* Most common use case

**Enabled**: All matching conditions execute

* All conditions are evaluated
* Every condition that returns true executes
* Useful for triggering multiple parallel actions

### Force Select Branch

When using Prompt AI mode, enabling "Force Select Branch" ensures the AI always selects at least one branch, even if none of the conditions seem to match perfectly.

**Disabled (default)**: AI may not select any branch if no condition matches
**Enabled**: AI is forced to select the most appropriate branch

This is useful when you need guaranteed workflow continuation and want the AI to make a best-effort decision.

## Example Use Cases

### Priority Routing (Manual Mode)

```text theme={null}
Condition 1: "If High Priority"
Mode: Manual
Expression: {{ agent.output.structured.priority === "high" }}

Condition 2: "Else if Medium Priority"
Mode: Manual
Expression: {{ agent.output.structured.priority === "medium" }}

Condition 3: "Else Low Priority"
Mode: Manual
Expression: {{ true }}
```

### Customer Segmentation (Prompt AI Mode)

```text theme={null}
Condition 1: "If is already a customer"
Mode: Prompt AI
Instructions: Check if {{trigger.output.email}} exists in our customer database based on {{http_request.output.customers}}

Condition 2: "Else if is not a customer yet"
Mode: Prompt AI
Instructions: Determine if this is a new prospect
```

### Amount Threshold (Manual Mode)

```text theme={null}
Condition 1: "If Needs Approval"
Mode: Manual
Expression: {{ trigger.output.amount >= 5000 }}

Condition 2: "Else Auto-Approve"
Mode: Manual
Expression: {{ trigger.output.amount < 5000 }}
```

## Choosing Between Modes

### Use Manual Mode When:

* Logic is straightforward (checking values, comparing numbers)
* You need predictable, consistent results
* You want to minimize AI credit usage
* Conditions are based on exact data matching

### Use Prompt AI Mode When:

* Logic requires understanding context or nuance
* Evaluating natural language content
* Making subjective judgments
* Combining multiple factors that need interpretation

**Example - When Manual is Better:**

```handlebars theme={null}
{{ trigger.output.amount > 1000 }}  ✅ Simple, clear, no AI needed
```

## Manual Mode Operators

When writing manual expressions, you can use:

**Comparison**: `===`, `!==`, `>`, `<`, `>=`, `<=`\
**Logical**: `&&` (and), `||` (or), `!` (not)\
**String Methods**: `.includes()`, `.startsWith()`, `.endsWith()`\
**Existence**: Check if value exists with `{{ trigger.output.field }}`

**Examples:**

```handlebars theme={null}
{{ trigger.output.status === "approved" }}
{{ agent.output.structured.score > 80 && agent.output.structured.verified === true }}
{{ trigger.output.email.includes("@company.com") }}
{{ trigger.output.tags.includes("urgent") }}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Add a Default Condition">
    Always add a final condition with `{{ true }}` to catch cases that don't match other conditions.
  </Accordion>

  <Accordion title="Order Matters (When Multiple Disabled)">
    Conditions are evaluated top to bottom. Put most specific conditions first,
    general ones last.
  </Accordion>

  <Accordion title="Use Clear Names">
    Name conditions clearly: "If High Priority" not "Condition 1". This makes
    workflows easier to understand.
  </Accordion>

  <Accordion title="Choose the Right Mode">
    Use Manual for simple logic checks. Use Prompt AI for complex evaluations that need context analysis.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Agent Node" icon="brain" href="/en/using-langdock/workflows/nodes/agent-node">
    Use AI for complex decisions
  </Card>

  <Card title="Code Node" icon="code" href="/en/using-langdock/workflows/nodes/code-node">
    Write custom code logic
  </Card>

  <Card title="HTTP Request" icon="globe" href="/en/using-langdock/workflows/nodes/http-request-node">
    Make API calls based on conditions
  </Card>

  <Card title="Variable Usage" icon="brackets-curly" href="/en/using-langdock/workflows/fundamentals/variable-usage">
    Learn how to use variables in conditions
  </Card>
</CardGroup>
