Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

BranchJoiner

Use BranchJoiner to merge multiple input branches of a pipeline into a single output. It receives inputs of a declared data type and forwards the first received value downstream.

Key Features

  • Merges multiple pipeline branches into a single output
  • Handles one data type at a time, declared at initialization (for example, list[ChatMessage], str, List[Document])
  • Forwards the first value it receives — additional inputs in the same run raise an error
  • Closes loops in pipelines by re-routing data back to an earlier component
  • Reconciles branches from router components such as ConditionalRouter or TextLanguageRouter

Configuration

  1. Drag the BranchJoiner component onto the canvas from the Component Library.
  2. Click the component to open the configuration panel.
  3. On the General tab:
    1. Set type_ to the Python type this component will receive and pass (for example, list[str], List[Document], list[ChatMessage]).

Connections

BranchJoiner accepts multiple inputs of the type declared by type_ — typically the outputs of router components such as ConditionalRouter or TextLanguageRouter, or the output of a loop component alongside the original input. It sends the first received value to the next component in the pipeline.

Usage Example

This example shows a pipeline where ConditionalRouter routes queries based on whether they contain a question mark, and BranchJoiner consolidates the outputs from different processing approaches.

components:
ConditionalRouter:
type: haystack.components.routers.conditional_router.ConditionalRouter
init_parameters:
routes:
- condition: "{{ '?' in query }}"
output: "{{ query }}"
output_name: question
output_type: str
- condition: "{{ '?' not in query }}"
output: "{{ query }}"
output_name: statement
output_type: str
QuestionPromptBuilder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: "Provide a detailed answer to this question: {{ query }}"
StatementPromptBuilder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: "Acknowledge and expand on this statement: {{ query }}"
QuestionGenerator:
type: haystack.components.generators.openai.OpenAIGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false
model: gpt-4o-mini
generation_kwargs:
temperature: 0.3
max_tokens: 500
StatementGenerator:
type: haystack.components.generators.openai.OpenAIGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false
model: gpt-4o-mini
generation_kwargs:
temperature: 0.7
max_tokens: 200
BranchJoiner:
type: haystack.components.joiners.branch.BranchJoiner
init_parameters:
type_: list[str]

connections:
- sender: ConditionalRouter.question
receiver: QuestionPromptBuilder.query
- sender: ConditionalRouter.statement
receiver: StatementPromptBuilder.query
- sender: QuestionPromptBuilder.prompt
receiver: QuestionGenerator.prompt
- sender: StatementPromptBuilder.prompt
receiver: StatementGenerator.prompt
- sender: QuestionGenerator.replies
receiver: BranchJoiner.value
- sender: StatementGenerator.replies
receiver: BranchJoiner.value

max_runs_per_component: 100

metadata: {}

inputs:
query:
- ConditionalRouter.query

outputs:
replies: BranchJoiner.value


Parameters

Inputs

ParameterTypeDefaultDescription
**kwargsAnyThe input data. Must be of the type declared by type_ during initialization.

Outputs

ParameterTypeDefaultDescription
valueThe type declared by type_The first value BranchJoiner receives from the connected components.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
type_TypeThe expected data type of inputs and outputs.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
**kwargsAnyThe input data. Must be of the type declared by type_ during initialization.