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

# Logic Nodes

> Control flow and branching in Tedro workflows.

# Logic Nodes

Logic nodes control the flow of your workflow. Use them to create branches based on conditions, enforce rate limits, and explicitly terminate execution paths.

***

## logic.switch

**Deterministic branching based on conditions.**

The Switch node evaluates a set of conditions and routes execution to the matching branch. It works like a series of if/else-if checks with a default fallback.

### Configuration

| Option                  | Type   | Required | Description                                                                                           |
| ----------------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------- |
| `conditions`            | array  | Yes      | List of condition objects, each with a field, operator, and value                                     |
| `conditions[].field`    | string | Yes      | The context field to evaluate (e.g., `message.text`, `contact.tags`, `contact.language`)              |
| `conditions[].operator` | string | Yes      | Comparison operator: `equals`, `contains`, `starts_with`, `ends_with`, `gt`, `lt`, `in`, `not_equals` |
| `conditions[].value`    | string | Yes      | The value to compare against                                                                          |
| `conditions[].label`    | string | Yes      | Human-readable label for this branch (displayed on the output handle)                                 |

### Outputs

Each condition creates a labeled output handle on the node, plus a **default** handle for messages that match no condition.

| Output              | Description                                                     |
| ------------------- | --------------------------------------------------------------- |
| `[condition label]` | One handle per condition, triggered when that condition matches |
| `default`           | Triggered when no conditions match                              |

### Connections

* **Inputs**: Single input handle from the previous node
* **Outputs**: One handle per condition + one default handle

### Example Use Case

After an AI Router classifies a message as "billing," "support," or "sales," use a Switch node to route each category to a different AI Respond node with a specialized system prompt. The default branch can route to a generic help response.

***

## logic.rate\_limit

**Spam and cost prevention with built-in counters.**

The Rate Limit node tracks message frequency and throttles processing when limits are exceeded. This protects your AI token budget and prevents abuse.

### Configuration

| Option          | Type   | Required | Description                                                                       |
| --------------- | ------ | -------- | --------------------------------------------------------------------------------- |
| `maxCount`      | number | Yes      | Maximum number of allowed events in the time window                               |
| `windowSeconds` | number | Yes      | Time window in seconds (e.g., 3600 for 1 hour)                                    |
| `scope`         | string | Yes      | Rate limit scope: `per-contact` (per individual) or `per-tenant` (workspace-wide) |

### Outputs

| Output         | Description                                                 |
| -------------- | ----------------------------------------------------------- |
| `allowed`      | The request is within the rate limit -- continue processing |
| `rate_limited` | The request exceeded the rate limit -- handle accordingly   |

### Connections

* **Inputs**: Single input handle from the previous node
* **Outputs**: Two handles: `allowed` and `rate_limited`

### Example Use Case

Place a Rate Limit node after the trigger to cap each contact at 20 messages per hour. Connect the `allowed` output to your AI processing flow, and the `rate_limited` output to a polite "please slow down" message or a `logic.end` node.

<Note>
  Rate limits use atomic counters, so they work correctly even under high concurrency with multiple messages being processed simultaneously.
</Note>

***

## logic.end

**Explicitly terminate a workflow run.**

The End node stops execution of the current branch. Use it to cleanly terminate paths that don't need further processing.

### Configuration

No configuration options. This node simply marks the end of a branch.

### Outputs

None. This is a terminal node.

### Connections

* **Inputs**: Single input handle from the previous node
* **Outputs**: None (terminal node)

### Example Use Case

In a Switch node's default branch where no conditions matched and no response is needed, connect to an End node to explicitly terminate the run. This is also useful after a rate-limited path where you don't want to send any message back.
