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

BranchJoiner

Merge multiple branches of a pipeline into a single output. It receives inputs of the same data type and forwards the first received value to its output.

Key Features

  • Merges multiple pipeline branches into a single output.
  • Type-safe: handles one data type at a time, declared at initialization.
  • Useful for closing loops and reconciling branches from router components.
  • Raises an error if more than one value is received in a single run.

Configuration

  1. Drag the BranchJoiner component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    • Set the Type to specify the data type the component will receive and pass (for example, List[ChatMessage], str, or List[Document]).

Connections

BranchJoiner typically receives outputs from router components such as ConditionalRouter or TextLanguageRouter, or from components at the end of parallel branches. Connect each branch's output to BranchJoiner's input, then connect its output to the next component in the pipeline.

Common use cases:

  • Loop handling: Close loops in pipelines by merging an error-handling branch back into the main flow.
  • Decision-based merging: Reconcile branches created by router components into a single continuation point.

Source Code

To check this component's source code, open branch.py in the Haystack repository.

Usage Examples

Basic Configuration

  BranchJoiner:
type: haystack.components.joiners.branch.BranchJoiner
init_parameters:
type_: list[str]

Connections

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

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

Outputs

ParameterTypeDescription
(value)Declared typeThe 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.