> ## 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.

# Subflow Block

> Execute another flow within the current flow for reusable logic and modular design

## Overview

The Subflow Block allows you to execute another flow within the current flow. This powerful feature enables you to reuse logic across multiple flows, break down complex flows into smaller pieces, and create modular workflow designs.

<Note>
  Subflows must be within the same project and cannot reference flows from different projects.
</Note>

<Frame>
  <img src="https://mintcdn.com/odella/PGZ7enNCqh0mvwj_/block-reference/assets/subflow_light.png?fit=max&auto=format&n=PGZ7enNCqh0mvwj_&q=85&s=0ddba2650817dda58d039255064f9ff6" alt="Subflow Block Screenshot" className="block dark:hidden" width="696" height="240" data-path="block-reference/assets/subflow_light.png" />

  <img src="https://mintcdn.com/odella/PGZ7enNCqh0mvwj_/block-reference/assets/subflow_dark.png?fit=max&auto=format&n=PGZ7enNCqh0mvwj_&q=85&s=411aa326fdf6497c7474f024610e3e97" alt="Subflow Block Screenshot" className="hidden dark:block" width="694" height="252" data-path="block-reference/assets/subflow_dark.png" />
</Frame>

## Inputs

<ParamField path="(Dynamic Inputs)" type="any">
  The inputs are dynamically generated based on the Input Blocks configured in the selected subflow. Each Input Block in the subflow creates a corresponding input port on the Subflow Block.
</ParamField>

<ParamField path="Wait For" type="any">
  Only shown when "Wait For Input" is enabled. Used to delay execution until this input is ready.
</ParamField>

## Outputs

<ResponseField name="(Dynamic Outputs)" type="any">
  The outputs are dynamically generated based on the Output Blocks configured in the selected subflow. Each Output Block in the subflow creates a corresponding output port on the Subflow Block.
</ResponseField>

<ResponseField name="Error" type="string">
  Contains any error message if an error occurs during subflow execution. Only available when "Use Error Output" is enabled.
</ResponseField>

<ResponseField name="Duration" type="number">
  The time in milliseconds that the subflow took to execute.
</ResponseField>

## Editor Settings

<ParamField path="Flow" type="flow" required>
  Select the flow to execute as a subflow. The flow must exist within the same project.
</ParamField>

<ParamField path="Use Error Output" type="boolean" default={false}>
  When enabled, errors during subflow execution will be sent to the Error output port instead of causing the block to fail. This allows for custom error handling logic.
</ParamField>

<ParamField path="Wait For Input" type="boolean" default={false}>
  When enabled, adds a "Wait For" input port that delays execution until that input is ready.
</ParamField>

<ParamField path="(Dynamic Settings)" type="any">
  For each Input Block in the selected subflow, a corresponding setting appears allowing you to set a default value for that input.
</ParamField>

## Notes

* The block's inputs and outputs are determined by the Input and Output Blocks in the selected subflow
* Errors can either fail the block or be handled via the Error output port
* Subflows can be nested within other subflows for complex workflow organization
* The subflow must be in the same project as the parent flow
* Default values can be set for any input, which will be used if no connection is made to that input port

## Examples

### Example 1: Basic Subflow Usage

1. Create a new flow called "Greeting" with:
   * An Input Block named "name"
   * A Text Block with content "Hello, {inputs.name}!"
   * An Output Block named "message"

2. In your main flow:
   * Add a Subflow Block
   * Select "Greeting" as the Flow
   * Connect a Text Block with a name to the "name" input
   * Use the "message" output as needed

### Example 2: Error Handling

1. Create a subflow that might produce errors
2. In your main flow:
   * Add a Subflow Block
   * Enable "Use Error Output"
   * Connect the Error output to handle potential issues
   * Add error handling logic as needed

## FAQ

<AccordionGroup>
  <Accordion title="Can subflows be nested?">
    Yes, you can use Subflow Blocks within other subflows to create hierarchical workflow structures.
  </Accordion>

  <Accordion title="What happens if an error occurs in the subflow?">
    If "Use Error Output" is enabled, the error message will be sent to the Error output port. Otherwise, the block will fail and stop the flow execution.
  </Accordion>

  <Accordion title="Can I modify the subflow's inputs and outputs?">
    Yes, by modifying the Input and Output Blocks in the subflow. Changes will automatically update the ports on any Subflow Blocks using that flow.
  </Accordion>

  <Accordion title="How can I track how long a subflow takes to execute?">
    The Duration output port provides the execution time in milliseconds for each run of the subflow.
  </Accordion>
</AccordionGroup>
