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 | | | 13 | :------------------------------------- | :---------------------------------------------------------------------------------------------- | 14 | **Most common position in a pipeline** | After at least two other components to join their strings | 15 | **Mandatory run variables** | “strings”: Multiple strings from connected components. | 16 | **Output variables** | “strings”: A list of merged strings | 17 | **API reference** | [Joiners](/reference/joiners-api) | 18 | **GitHub link** | https://github.com/deepset-ai/haystack/blob/main/haystack/components/joiners/string_joiner.py | 19 20 ## Overview 21 22 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. 23 24 ## Usage 25 26 ```python 27 from haystack.components.joiners import StringJoiner 28 from haystack.components.builders import PromptBuilder 29 from haystack.core.pipeline import Pipeline 30 31 string_1 = "What's Natural Language Processing?" 32 string_2 = "What is life?" 33 34 pipeline = Pipeline() 35 pipeline.add_component("prompt_builder_1", PromptBuilder("Builder 1: {{query}}")) 36 pipeline.add_component("prompt_builder_2", PromptBuilder("Builder 2: {{query}}")) 37 pipeline.add_component("string_joiner", StringJoiner()) 38 39 pipeline.connect("prompt_builder_1.prompt", "string_joiner.strings") 40 pipeline.connect("prompt_builder_2.prompt", "string_joiner.strings") 41 42 result = pipeline.run( 43 data={ 44 "prompt_builder_1": {"query": string_1}, 45 "prompt_builder_2": {"query": string_2}, 46 }, 47 ) 48 49 print(result) 50 ```