deepset-ai/haystack · error · ValueError
Number of replies ({len(replies)}), and metadata ({len(meta)
Error message
Number of replies ({len(replies)}), and metadata ({len(meta)}) must match. What it means
AnswerBuilder.run raises this when the `replies` and `meta` lists passed in have different lengths. Every reply must have a corresponding metadata entry so the builder can attach per-answer metadata consistently.
Source
Thrown at haystack/components/builders/answer_builder.py:181
`[^\\n]+$` finds "this is an answer" in a string "this is an argument.\\nthis is an answer".
`Answer: (.*)` finds "this is an answer" in a string
"this is an argument. Answer: this is an answer".
:param reference_pattern:
The regular expression pattern used for parsing the document references.
If not specified, no parsing is done, and all documents are returned.
References need to be specified as indices of the input documents and start at [1].
Example: `\\[(\\d+)\\]` finds "1" in a string "this is an answer[1]".
:param expand_reference_ranges:
If True, reference ranges like `[6-10]` are expanded to documents 6 through 10.
If not specified, the value from the component initialization is used.
:returns: A dictionary with the following keys:
- `answers`: The answers received from the output of the Generator.
"""
if not meta:
meta = [{}] * len(replies)
elif len(replies) != len(meta):
raise ValueError(f"Number of replies ({len(replies)}), and metadata ({len(meta)}) must match.")
if pattern:
AnswerBuilder._check_num_groups_in_regex(pattern)
pattern = pattern or self.pattern
reference_pattern = reference_pattern or self.reference_pattern
expand_reference_ranges = (
self.expand_reference_ranges if expand_reference_ranges is None else expand_reference_ranges
)
reference_pattern = AnswerBuilder._resolve_reference_pattern(
reference_pattern=reference_pattern, expand_reference_ranges=expand_reference_ranges
)
replies_to_iterate = replies[-1:] if self.last_message_only and replies else replies
meta_to_iterate = meta[-1:] if self.last_message_only and meta else meta
all_answers = []
for reply, given_metadata in zip(replies_to_iterate, meta_to_iterate, strict=True):View on GitHub (pinned to e318778c9b)
Solutions
- Make len(meta) equal len(replies) — provide one meta dict per reply.
- If metadata is uniform, pass meta=[meta_dict] * len(replies) (or simply omit meta, which defaults to empty dicts for all replies).
- Check the upstream generator's number of completions (e.g. n parameter) and build meta accordingly.
Example fix
// before answer_builder.run(replies=replies, meta=[single_meta]) // after answer_builder.run(replies=replies, meta=[single_meta] * len(replies))
Defensive patterns
Strategy: validation
Validate before calling
if meta and len(meta) != len(replies):
raise AssertionError(f"replies={len(replies)} vs meta={len(meta)}") Try / catch
try:
result = answer_builder.run(replies=replies, meta=meta)
except ValueError as e:
if "must match" in str(e):
logging.error("Replies/meta mismatch: %s", e)
raise Prevention
- Build meta in the same loop that collects replies.
- Use meta=[m] * len(replies) for uniform metadata or omit meta.
- Check generator completion count (n) when constructing meta.
When it happens
Trigger: Calling answer_builder.run(replies=[...], meta=[...]) where len(meta) != len(replies); e.g. passing meta from a single reply with a multi-reply generator output (or vice versa).
Common situations: Wiring a generator that returns multiple completions into AnswerBuilder while meta was built for one reply; manually constructing meta with fewer entries; schema drift between generator versions.
Related errors
- Pattern '{pattern}' contains multiple capture groups. Please
- The following tool names are not valid: {invalid_tool_names}
- user_prompt must define exactly one message block, found {le
- system_prompt must define exactly one message block, found {
- LLM evaluator expects all input lists to have the same lengt
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/207b3adddee2b58f.
Report an issue: GitHub.