OutputAdapter
Adapt output of components using Jinja templates. This is useful if you want to connect components that have different input or output types.
With smart connections, the pipeline automatically converts between String and ChatMessage in both directions. If you're using OutputAdapter just for this type conversion, you can remove it. For details, see Simplify Your Pipelines with Smart Connections.
Key Features
- Adapts component outputs to match the expected input types of downstream components using Jinja2 templates.
- The template variables define the component's inputs dynamically.
- Supports custom Jinja filters for advanced transformations.
- Safe mode by default, with an optional
unsafesetting for complex types such asChatMessage,Document, orAnswer.
Configuration
- Drag the
OutputAdaptercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Enter the Jinja2
templatethat defines how to transform the input. The variables used in the template become the component's inputs. For example, the template{{ documents[0].content }}creates adocumentsinput. - Set the
output_typeto specify the type of the transformed output.
- Enter the Jinja2
- Go to the Advanced tab to configure additional settings:
- Optionally add
custom_filtersfor custom Jinja filter functions. - Enable
unsafemode if you need to work with complex types likeChatMessage,Document, orAnswer. Use this with caution as it may allow remote code execution.
- Optionally add
Connections
OutputAdapter accepts any inputs defined by the variables in its template. Connect the output of an upstream component to the matching template variable input.
Connect its output to any downstream component that expects the transformed type. For details and examples, see the Incompatible Connection Types section.
Source Code
To check this component's source code, open output_adapter.py in the Haystack repository.
Usage Examples
Basic Configuration
replies_to_query:
type: haystack.components.converters.output_adapter.OutputAdapter
init_parameters:
template: '{{ replies[0] }}'
output_type: str
Using the Component in a Pipeline
This is an example of a RAG chat pipeline where OutputAdapter converts LLM's replies into a single string that other components can accept.
# haystack-pipeline
components:
LLM:
init_parameters:
chat_generator:
init_parameters:
model: gpt-5.5
type: haystack.components.generators.chat.openai_responses.OpenAIResponsesChatGenerator
required_variables: '*'
streaming_callback:
system_prompt: ''
user_prompt: >-
{% message role="user" %}
You are part of a chatbot.
You receive a question (Current Question) and a chat history.
Use the context from the chat history and reformulate the question so
that it is suitable for retrieval augmented generation.
If X is followed by Y, only ask for Y and do not repeat X again.
If the question does not require any context from the chat history,
output it unedited.
Don't make questions too long, but short and precise.
Stay as close as possible to the current question.
Only output the new question, nothing else!
{{ query }}
New question:
{% endmessage %}
type: haystack.components.generators.chat.llm.LLM
answer_builder:
init_parameters:
reference_pattern: acm
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
bm25_retriever:
init_parameters:
document_store:
init_parameters:
create_index: true
embedding_dim: 768
hosts:
- ${OPENSEARCH_HOST}
http_auth:
- ${OPENSEARCH_USER}
- ${OPENSEARCH_PASSWORD}
index: Standard-Index-English
mappings:
max_chunk_bytes: 104857600
method:
return_embedding: false
settings:
index.knn: true
similarity: cosine
timeout:
use_ssl: true
verify_certs: false
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
top_k: 20
type: haystack_integrations.components.retrievers.opensearch.bm25_retriever.OpenSearchBM25Retriever
document_joiner:
init_parameters:
join_mode: concatenate
type: haystack.components.joiners.document_joiner.DocumentJoiner
embedding_retriever:
init_parameters:
document_store:
init_parameters:
create_index: true
embedding_dim: 768
hosts:
- ${OPENSEARCH_HOST}
http_auth:
- ${OPENSEARCH_USER}
- ${OPENSEARCH_PASSWORD}
index: Standard-Index-English
mappings:
max_chunk_bytes: 104857600
method:
return_embedding: false
settings:
index.knn: true
similarity: cosine
timeout:
use_ssl: true
verify_certs: false
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
top_k: 20
type: haystack_integrations.components.retrievers.opensearch.embedding_retriever.OpenSearchEmbeddingRetriever
query_embedder:
init_parameters:
model: intfloat/e5-base-v2
type: haystack.components.embedders.sentence_transformers_text_embedder.SentenceTransformersTextEmbedder
ranker:
init_parameters:
model: intfloat/simlm-msmarco-reranker
model_kwargs:
torch_dtype: torch.float16
top_k: 8
type: haystack.components.rankers.transformers_similarity.TransformersSimilarityRanker
LLM_2:
type: haystack.components.generators.chat.llm.LLM
init_parameters:
chat_generator:
init_parameters:
model: gpt-5.5
type: haystack.components.generators.chat.openai_responses.OpenAIResponsesChatGenerator
system_prompt: ""
user_prompt: >-
{% message role="user" %}
You are a technical expert.
You answer questions truthfully based on provided documents.
Ignore typing errors in the question.
For each document check whether it is related to the question.
Only use documents that are related to the question to answer it.
Ignore documents that are not related to the question.
If the answer exists in several documents, summarize them.
Only answer based on the documents provided. Don't make things up.
Just output the structured, informative and precise answer and nothing
else.
If the documents can't answer the question, say so.
Always use references in the form [NUMBER OF DOCUMENT] when using
information from a document, e.g. [3] for Document[3].
Never name the documents, only enter a number in square brackets as a
reference.
The reference must only refer to the number that comes in square
brackets after the document.
Otherwise, do not use brackets in your answer and reference ONLY the
number of the document without mentioning the word document.
These are the documents:
{% for document in documents %}
Document[{{ loop.index }}]:
{{ document.content }}
{% endfor %}
Question: {{ query }}
Answer:
{% endmessage %}
required_variables: "*"
streaming_callback:
connections:
- receiver: document_joiner.documents
sender: bm25_retriever.documents
- receiver: embedding_retriever.query_embedding
sender: query_embedder.embedding
- receiver: document_joiner.documents
sender: embedding_retriever.documents
- receiver: ranker.documents
sender: document_joiner.documents
- receiver: answer_builder.documents
sender: ranker.documents
- sender: LLM.last_message
receiver: query_embedder.text
- sender: LLM.last_message
receiver: bm25_retriever.query
- sender: LLM.last_message
receiver: ranker.query
- sender: LLM.last_message
receiver: answer_builder.replies
- sender: LLM.messages
receiver: LLM_2.messages
- sender: ranker.documents
receiver: LLM_2.documents
- sender: LLM_2.last_message
receiver: answer_builder.replies
inputs:
filters:
- bm25_retriever.filters
- embedding_retriever.filters
query:
- LLM.query
max_runs_per_component: 100
metadata: {}
outputs:
answers: answer_builder.answers
documents: ranker.documents
Parameters
Inputs
Input names and types depend on how you configure the template parameter.
| Parameter | Type | Description |
|---|---|---|
kwargs | Any | Must contain all variables used in the template string. |
Outputs
The output depends on the value of the output_type parameter.
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
template | str | A Jinja template that defines how to adapt the input data. The variables in the template define the input of this instance. For example, with this template: {{ documents[0].content }}, the component input will be documents. | |
output_type | TypeAlias | The type of output this instance should return. | |
custom_filters | Optional[Dict[str, Callable]] | None | A dictionary of custom Jinja filters used in the template. |
unsafe | bool | False | Enable execution of arbitrary code in the Jinja template. This should only be used if you trust the source of the template as it can lead to remote code execution. |
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.
| Parameter | Type | Description |
|---|---|---|
kwargs | Any | Must contain all variables used in the template string. |
Was this page helpful?