---
description: >-
  Logic components provide functionalities for routing, conditional processing,
  and flow management.
---

# Logic

### Use a logic component in a flow[​](https://docs.langflow.org/components-logic#use-a-logic-component-in-a-flow) <a href="#use-a-logic-component-in-a-flow" id="use-a-logic-component-in-a-flow"></a>

This flow creates a summarizing "for each" loop with the [Loop](#loop) component.

The component iterates over a list of [Data](data) objects until it's completed, and then the **Done** loop aggregates the results.

The **File** component loads text files from your local machine, and then the **Parse Data** component parses them into a list of structured `Data` objects. The **Loop** component passes each `Data` object to a **Prompt** to be summarized.

When the **Loop** component runs out of `Data`, the **Done** loop activates, which counts the number of pages and summarizes their tone with another **Prompt**. This is represented in BroxiAI by connecting the Parse Data component's **Data List** output to the Loop component's `Data` loop input.

![Sample Flow looping summarizer](https://docs.langflow.org/assets/images/loop-text-summarizer-bd1d7be6d26bb47765931e3ab9f98dfa.png)

The output will look similar to this:

```
Document Summary
Total Pages Processed
Total Pages: 2
Overall Tone of Document
Tone: Informative and Instructional
The documentation outlines microservices architecture patterns and best practices.
It emphasizes service isolation and inter-service communication protocols.
The use of asynchronous messaging patterns is recommended for system scalability.
It includes code examples of REST and gRPC implementations to demonstrate integration approaches.
```

### Conditional router (If-Else component)[​](https://docs.langflow.org/components-logic#conditional-router-if-else-component) <a href="#conditional-router-if-else-component" id="conditional-router-if-else-component"></a>

This component routes messages by comparing two strings. It evaluates a condition by comparing two text inputs using the specified operator and routes the message to `true_result` or `false_result`.

The operator looks for single strings based on your defined operator behavior, but it can also search for multiple words by regex matching.

To use the **Conditional router** component to check incoming messages with regex matching, do the following:

1. Connect the **If-Else** component's **Text Input** port to a **Chat Input** component.
2. In the If-Else component, enter the following values.

* In the **Match Text** field, enter `.*(urgent|warning|caution).*`. The component looks for these values. The regex match is case sensitive, so to look for all permutations of `warning`, enter `warning|Warning|WARNING`.
* In the **Operator** field, enter `regex`. The component looks for the strings `urgent`, `warning`, and `caution`. For more operators, see Operator behavior.
* In the **Message** field, enter `New Message Detected`. This field is optional. The message is sent to both the **True** and **False** ports. The component is now set up to send a `New Message Detected` message out of its **True** port if it matches any of the strings. If no strings are detected, it sends a message out of the **False** port.

3. Create two identical flows to process the messages. Connect an **Open AI** component, a **Prompt**, and a **Chat Output** component together.
4. Connect one chain to the **If-Else** component's **True** port, and one chain to the **False** port.

The flow looks like this:

![A conditional router connected to two OpenAI components](https://docs.langflow.org/assets/images/component-conditional-router-be8cad83b612bf7c86bc861a1842fda3.png)

5. Add your **OpenAI API key** to both **OpenAI** components.
6. In both **Prompt** components, enter the behavior you want each route to take. When a match is found: `Send a message that a new message has been received and added to the Urgent queue.`

When a match is not found: `Send a message that a new message has been received and added to the backlog.`

7. Open the **Playground**.
8. Send the flow some messages. Your messages route differently based on the if-else component's evaluation.

```
User
A new user was created.

AI
A new message has been received and added to the backlog.

User
Sign-in warning: new user locked out.

AI
A new message has been received and added to the Urgent queue. Please review it at your earliest convenience.
```

#### Inputs[​](https://docs.langflow.org/components-logic#inputs) <a href="#inputs" id="inputs"></a>

| Name            | Type     | Description                                                                                                                         |
| --------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| input\_text     | String   | The primary text input for the operation.                                                                                           |
| match\_text     | String   | The text input to compare against.                                                                                                  |
| operator        | Dropdown | The operator to compare texts. Options: "equals", "not equals", "contains", "starts with", "ends with", "regex". Default: "equals". |
| case\_sensitive | Boolean  | If true, the comparison is case sensitive. This setting is ignored for regex comparison. Default: false.                            |
| message         | Message  | The message to pass through either route.                                                                                           |
| max\_iterations | Integer  | The maximum number of iterations for the conditional router. Default: 10.                                                           |
| default\_route  | Dropdown | The default route to take when max iterations are reached. Options: "true\_result" or "false\_result". Default: "false\_result".    |

#### Outputs[​](https://docs.langflow.org/components-logic#outputs) <a href="#outputs" id="outputs"></a>

| Name          | Type    | Description                             |
| ------------- | ------- | --------------------------------------- |
| true\_result  | Message | The output when the condition is true.  |
| false\_result | Message | The output when the condition is false. |

#### Operator Behavior[​](https://docs.langflow.org/components-logic#operator-behavior) <a href="#operator-behavior" id="operator-behavior"></a>

The **If-else** component includes a comparison operator to compare the values in `input_text` and `match_text`.

All options respect the `case_sensitive` setting except **regex**.

* **equals**: Exact match comparison.
* **not equals**: Inverse of exact match.
* **contains**: Checks if match\_text is found within input\_text.
* **starts with**: Checks if input\_text begins with match\_text.
* **ends with**: Checks if input\_text ends with match\_text.
* **regex**: Performs regular expression matching. It is always case sensitive and ignores the case\_sensitive setting.

### Listen[​](https://docs.langflow.org/components-logic#listen) <a href="#listen" id="listen"></a>

This component listens for a notification and retrieves its associated state.

#### Inputs[​](https://docs.langflow.org/components-logic#inputs-1) <a href="#inputs-1" id="inputs-1"></a>

| Name | Type   | Description                                 |
| ---- | ------ | ------------------------------------------- |
| name | String | The name of the notification to listen for. |

#### Outputs[​](https://docs.langflow.org/components-logic#outputs-1) <a href="#outputs-1" id="outputs-1"></a>

| Name   | Type | Description                                 |
| ------ | ---- | ------------------------------------------- |
| output | Data | The state associated with the notification. |

### Loop[​](https://docs.langflow.org/components-logic#loop) <a href="#loop" id="loop"></a>

This component iterates over a list of [Data](data) objects, outputting one item at a time and aggregating results from loop inputs.

In this example, the **Loop** component iterates over a CSV file through the **Item** port until there are no rows left to process. Then, the **Loop** component performs the actions connected to the **Done** port, which in this case is loading the structured data into **Chroma DB**.

Think of it this way: the **Item** port forms the "main" loop that repeats until a "complete" condition is reached.

1. The **Loop** component accepts **Data** from the **Load CSV** component, and outputs the data from the **Item** port.
2. Each CSV row is converted to a **Message** and processed into structured data with the **Structured Output** component. The dotted line connected from the **Structured Output** component's **Looping** port tells you where the loop begins again.
3. The **Loop** component repeatedly extracts rows by **Text Key** until there are no more rows to extract.

Once all items are processed, the action connected to the **Done** port is performed. In this example, the data is loaded into **Chroma DB**.

![Loop CSV parser](https://docs.langflow.org/assets/images/component-loop-csv-5e6704f4f2b8d511b70336ff3ddc1328.png)

#### Inputs[​](https://docs.langflow.org/components-logic#inputs-2) <a href="#inputs-2" id="inputs-2"></a>

| Name | Type      | Description                                       |
| ---- | --------- | ------------------------------------------------- |
| data | Data/List | The initial list of Data objects to iterate over. |

#### Outputs[​](https://docs.langflow.org/components-logic#outputs-2) <a href="#outputs-2" id="outputs-2"></a>

| Name | Type | Description                                                    |
| ---- | ---- | -------------------------------------------------------------- |
| item | Data | Outputs one item at a time from the data list.                 |
| done | Data | Triggered when iteration complete, returns aggregated results. |

### Notify[​](https://docs.langflow.org/components-logic#notify) <a href="#notify" id="notify"></a>

This component generates a notification for the Listen component to use.

#### Inputs[​](https://docs.langflow.org/components-logic#inputs-3) <a href="#inputs-3" id="inputs-3"></a>

| Name   | Type    | Description                                                        |
| ------ | ------- | ------------------------------------------------------------------ |
| name   | String  | The name of the notification.                                      |
| data   | Data    | The data to store in the notification.                             |
| append | Boolean | If true, the record will be appended to the existing notification. |

#### Outputs[​](https://docs.langflow.org/components-logic#outputs-3) <a href="#outputs-3" id="outputs-3"></a>

| Name   | Type | Description                          |
| ------ | ---- | ------------------------------------ |
| output | Data | The data stored in the notification. |

### Pass message[​](https://docs.langflow.org/components-logic#pass-message) <a href="#pass-message" id="pass-message"></a>

This component forwards the input message, unchanged.

#### Inputs[​](https://docs.langflow.org/components-logic#inputs-4) <a href="#inputs-4" id="inputs-4"></a>

| Name             | Display Name    | Info                                                                 |
| ---------------- | --------------- | -------------------------------------------------------------------- |
| input\_message   | Input Message   | The message to be passed forward.                                    |
| ignored\_message | Ignored Message | A second message to be ignored. Used as a workaround for continuity. |

#### Outputs[​](https://docs.langflow.org/components-logic#outputs-4) <a href="#outputs-4" id="outputs-4"></a>

| Name            | Display Name   | Info                         |
| --------------- | -------------- | ---------------------------- |
| output\_message | Output Message | The forwarded input message. |

### Run flow[​](https://docs.langflow.org/components-logic#run-flow) <a href="#run-flow" id="run-flow"></a>

This component allows you to run any flow stored in your BroxiAI database without opening the flow editor.

The [Run Flow](#run-flow) component can also be used as a tool when connected to an [Agent](agents). The `name` and `description` metadata that the Agent uses to register the tool are created automatically.

When you select a flow, the component fetches the flow's graph structure and uses it to generate the inputs and outputs for the Run Flow component.

To use the Run Flow component as a tool, do the following:

1. Add the **Run Flow** component to flow.
2. In the **Flow Name** menu, select the sub-flow you want to run. The appearance of the **Run Flow** component changes to reflect the inputs and outputs of the selected flow.
3. On the **Run Flow** component, enable **Tool Mode**.
4. Connect the **Run Flow** component to the **Toolset** input of the Agent. ![Run Flow component](https://docs.langflow.org/assets/images/component-run-flow-78e94e2ede1b4b853f0e4de6b9561f6f.png)
5. Run the flow. The Agent uses the Run Flow component as a tool to run the selected sub-flow.

#### Inputs[​](https://docs.langflow.org/components-logic#inputs-5) <a href="#inputs-5" id="inputs-5"></a>

| Name                 | Type     | Description                                                      |
| -------------------- | -------- | ---------------------------------------------------------------- |
| flow\_name\_selected | Dropdown | The name of the flow to run.                                     |
| flow\_tweak\_data    | Dict     | Dictionary of tweaks to customize the flow's behavior.           |
| dynamic inputs       | Various  | Additional inputs that are generated based on the selected flow. |

#### Outputs[​](https://docs.langflow.org/components-logic#outputs-5) <a href="#outputs-5" id="outputs-5"></a>

| Name         | Type                                                | Description                                      |
| ------------ | --------------------------------------------------- | ------------------------------------------------ |
| run\_outputs | A `List` of types `Data`, `Message,` or `DataFrame` | All outputs are generated from running the flow. |

### Legacy components[​](https://docs.langflow.org/components-logic#legacy-components) <a href="#legacy-components" id="legacy-components"></a>

Legacy components are available to use but no longer supported.

#### Data Conditional Router[​](https://docs.langflow.org/components-logic#data-conditional-router) <a href="#data-conditional-router" id="data-conditional-router"></a>

This component routes `Data` objects based on a condition applied to a specified key, including boolean validation. It can process either a single Data object or a list of Data objects.

This component is particularly useful in workflows that require conditional routing of complex data structures, enabling dynamic decision-making based on data content.

**Inputs**[**​**](https://docs.langflow.org/components-logic#inputs-6)

| Name           | Type     | Description                                                                                                                             |
| -------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| data\_input    | Data     | The Data object or list of Data objects to process. This input can handle both single items and lists.                                  |
| key\_name      | String   | The name of the key in the Data object to check.                                                                                        |
| operator       | Dropdown | The operator to apply. Options: "equals", "not equals", "contains", "starts with", "ends with", "boolean validator". Default: "equals". |
| compare\_value | String   | The value to compare against. Not shown/used when operator is "boolean validator".                                                      |

**Outputs**[**​**](https://docs.langflow.org/components-logic#outputs-6)

| Name          | Type      | Description                           |
| ------------- | --------- | ------------------------------------- |
| true\_output  | Data/List | Output when the condition is met.     |
| false\_output | Data/List | Output when the condition is not met. |

**Operator behavior**[**​**](https://docs.langflow.org/components-logic#operator-behavior-1)

* **equals**: Exact match comparison between the key's value and compare\_value.
* **not equals**: Inverse of exact match.
* **contains**: Checks if compare\_value is found within the key's value.
* **starts with**: Checks if the key's value begins with compare\_value.
* **ends with**: Checks if the key's value ends with compare\_value.
* **boolean validator**: Treats the key's value as a boolean. The following values are considered true:
  * Boolean `true`.
  * Strings: "true", "1", "yes", "y", "on" (case-insensitive).
  * Any other value is converted using Python's `bool()` function.

**List processing**[**​**](https://docs.langflow.org/components-logic#list-processing)

The following actions occur when processing a list of Data objects:

* Each object in the list is evaluated individually
* Objects meeting the condition go to true\_output
* Objects not meeting the condition go to false\_output
* If all objects go to one output, the other output is empty

### Deprecated components[​](https://docs.langflow.org/components-logic#deprecated-components) <a href="#deprecated-components" id="deprecated-components"></a>

Deprecated components have been replaced by newer alternatives and should not be used in new projects.

#### Flow as tool[​](https://docs.langflow.org/components-logic#flow-as-tool) <a href="#flow-as-tool" id="flow-as-tool"></a>

This component constructs a tool from a function that runs a loaded flow.

**Inputs**[**​**](https://docs.langflow.org/components-logic#inputs-7)

| Name              | Type     | Description                                         |
| ----------------- | -------- | --------------------------------------------------- |
| flow\_name        | Dropdown | The name of the flow to run.                        |
| tool\_name        | String   | The name of the tool.                               |
| tool\_description | String   | The description of the tool.                        |
| return\_direct    | Boolean  | If true, returns the result directly from the tool. |

**Outputs**[**​**](https://docs.langflow.org/components-logic#outputs-7)

| Name             | Type | Description                         |
| ---------------- | ---- | ----------------------------------- |
| api\_build\_tool | Tool | The constructed tool from the flow. |

#### Sub flow[​](https://docs.langflow.org/components-logic#sub-flow) <a href="#sub-flow" id="sub-flow"></a>

This `SubFlowComponent` generates a component from a flow with all of its inputs and outputs.

This component can integrate entire flows as components within a larger workflow. It dynamically generates inputs based on the selected flow and executes the flow with provided parameters.

**Inputs**[**​**](https://docs.langflow.org/components-logic#inputs-8)

| Name       | Type     | Description                  |
| ---------- | -------- | ---------------------------- |
| flow\_name | Dropdown | The name of the flow to run. |

**Outputs**[**​**](https://docs.langflow.org/components-logic#outputs-8)

| Name          | Type        | Description                          |
| ------------- | ----------- | ------------------------------------ |
| flow\_outputs | List\[Data] | The outputs generated from the flow. |
