stringjoiner.mdx
 1  ---
 2  title: "StringJoiner"
 3  id: stringjoiner
 4  slug: "/stringjoiner"
 5  description: "Component to join strings from different components into a list of strings."
 6  ---
 7  
 8  # StringJoiner
 9  
10  Component to join strings from different components into a list of strings.
11  
12  <div className="key-value-table">
13  
14  |                                        |                                                                                                 |
15  | :------------------------------------- | :---------------------------------------------------------------------------------------------- |
16  | **Most common position in a pipeline** | After at least two other components to join their strings                                       |
17  | **Mandatory run variables**            | `strings`: Multiple strings from connected components.                                          |
18  | **Output variables**                   | `strings`: A list of merged strings                                                             |
19  | **API reference**                      | [Joiners](/reference/joiners-api)                                                                      |
20  | **GitHub link**                        | https://github.com/deepset-ai/haystack/blob/main/haystack/components/joiners/string_joiner.py |
21  
22  </div>
23  
24  ## Overview
25  
26  The `StringJoiner` component collects multiple string outputs from various pipeline components and combines them into a single list. This is useful when you need to merge several strings from different parts of a pipeline into a unified output.
27  
28  ## Usage
29  
30  ```python
31  from haystack.components.joiners import StringJoiner
32  from haystack.components.builders import PromptBuilder
33  from haystack.core.pipeline import Pipeline
34  
35  string_1 = "What's Natural Language Processing?"
36  string_2 = "What is life?"
37  
38  pipeline = Pipeline()
39  pipeline.add_component("prompt_builder_1", PromptBuilder("Builder 1: {{query}}"))
40  pipeline.add_component("prompt_builder_2", PromptBuilder("Builder 2: {{query}}"))
41  pipeline.add_component("string_joiner", StringJoiner())
42  
43  pipeline.connect("prompt_builder_1.prompt", "string_joiner.strings")
44  pipeline.connect("prompt_builder_2.prompt", "string_joiner.strings")
45  
46  result = pipeline.run(
47      data={
48          "prompt_builder_1": {"query": string_1},
49          "prompt_builder_2": {"query": string_2},
50      },
51  )
52  
53  print(result)
54  ```