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

# Switch Block

> Route control flow based on a boolean condition

<Frame>
  <img src="https://mintcdn.com/odella/PGZ7enNCqh0mvwj_/block-reference/assets/switch_light.png?fit=max&auto=format&n=PGZ7enNCqh0mvwj_&q=85&s=f90de2011e7c64f247d5ea4454ac4e93" alt="Switch Block Screenshot" className="block dark:hidden" width="600" height="296" data-path="block-reference/assets/switch_light.png" />

  <img src="https://mintcdn.com/odella/PGZ7enNCqh0mvwj_/block-reference/assets/switch_dark.png?fit=max&auto=format&n=PGZ7enNCqh0mvwj_&q=85&s=c6a46ceb70cc39fc26d3b9493c4f0361" alt="Switch Block Screenshot" className="hidden dark:block" width="588" height="308" data-path="block-reference/assets/switch_dark.png" />
</Frame>

## Overview

The Switch Block is a control flow block that routes the input value to different outputs based on a boolean condition. It evaluates the condition and directs the value to either the True or False output port accordingly.

## Key Features

* Routes values based on a condition
* Control flow excluded values for unmatched paths

## Inputs

<ParamField path="Condition" type="any">
  If this is truthy, the value will be passed through the True port. Otherwise, it will be passed through the False port. An unconnected port is considered false.
</ParamField>

<ParamField path="Value" type="any">
  The value to pass through the True or False port. If unconnected, it will be undefined.
</ParamField>

## Outputs

<ResponseField name="True" type="any">
  The `value` passed through if the condition is truthy. Control-flow-excluded if condition is falsy.
</ResponseField>

<ResponseField name="False" type="any">
  The `value` passed through if the condition is falsy. Control-flow-excluded if condition is truthy.
</ResponseField>

## Editor Settings

<ParamField path="Don't run unconnected value" type="boolean" default={true}>
  If enabled, unconnected value input is control-flow-excluded. If disabled (legacy behavior), unconnected value will pass through undefined.
</ParamField>

<ParamField path="Width" type="number" default={150}>
  The width of the block in pixels.
</ParamField>

## Example: Route a message based on a condition

1. Create a Bool Block and set its value to `true`.
2. Create a Text Block with the value "Hello, World!".
3. Create a Switch Block. Connect the Bool Block to `Condition` and the Text Block to `Value`.
4. Add two Text Blocks to display the output, one connected to True and one to False.
5. Run the flow. The "Hello, World!" message should appear in the Text Block connected to True.
6. Change the Bool Block to `false` and run again. The message should now appear in the Text Block connected to False.

## Error Handling

The Switch block will not throw an error under normal circumstances. The following values are considered falsy:

* Boolean `false`
* Empty string
* Empty array
* Control-flow-excluded values
* Undefined/unconnected inputs
* Empty chat messages

## FAQ

<AccordionGroup>
  <Accordion title="What happens if the Value input is not provided?">
    If "Don't run unconnected value" is enabled (default), the value will be control-flow-excluded. If disabled, undefined will be passed through.
  </Accordion>

  <Accordion title="Can I use complex conditions with the Switch block?">
    The Switch block accepts any input type for the condition and coerces it to a boolean. For complex conditions, you may want to evaluate them before the Switch block.
  </Accordion>
</AccordionGroup>

## See Also

* [If/Else Block](/block-reference/logic/if-else)
* [Match Block](/block-reference/logic/match)
* [Bool Block](/block-reference/data/boolean)
