{"record":{"id":"207b3adddee2b58f","repo":"deepset-ai/haystack","slug":"number-of-replies-len-replies-and-metadata","errorCode":null,"errorMessage":"Number of replies ({len(replies)}), and metadata ({len(meta)}) must match.","messagePattern":"Number of replies \\((.+?)\\), and metadata \\((.+?)\\) must match\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/builders/answer_builder.py","lineNumber":181,"sourceCode":"                    `[^\\\\n]+$` finds \"this is an answer\" in a string \"this is an argument.\\\\nthis is an answer\".\n                    `Answer: (.*)` finds \"this is an answer\" in a string\n                    \"this is an argument. Answer: this is an answer\".\n        :param reference_pattern:\n            The regular expression pattern used for parsing the document references.\n            If not specified, no parsing is done, and all documents are returned.\n            References need to be specified as indices of the input documents and start at [1].\n            Example: `\\\\[(\\\\d+)\\\\]` finds \"1\" in a string \"this is an answer[1]\".\n        :param expand_reference_ranges:\n            If True, reference ranges like `[6-10]` are expanded to documents 6 through 10.\n            If not specified, the value from the component initialization is used.\n\n        :returns: A dictionary with the following keys:\n            - `answers`: The answers received from the output of the Generator.\n        \"\"\"\n        if not meta:\n            meta = [{}] * len(replies)\n        elif len(replies) != len(meta):\n            raise ValueError(f\"Number of replies ({len(replies)}), and metadata ({len(meta)}) must match.\")\n\n        if pattern:\n            AnswerBuilder._check_num_groups_in_regex(pattern)\n\n        pattern = pattern or self.pattern\n        reference_pattern = reference_pattern or self.reference_pattern\n        expand_reference_ranges = (\n            self.expand_reference_ranges if expand_reference_ranges is None else expand_reference_ranges\n        )\n        reference_pattern = AnswerBuilder._resolve_reference_pattern(\n            reference_pattern=reference_pattern, expand_reference_ranges=expand_reference_ranges\n        )\n\n        replies_to_iterate = replies[-1:] if self.last_message_only and replies else replies\n        meta_to_iterate = meta[-1:] if self.last_message_only and meta else meta\n\n        all_answers = []\n        for reply, given_metadata in zip(replies_to_iterate, meta_to_iterate, strict=True):","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/builders/answer_builder.py#L163-L199","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nanswer_builder.run(replies=replies, meta=[single_meta])\n// after\nanswer_builder.run(replies=replies, meta=[single_meta] * len(replies))","handlingStrategy":"validation","validationCode":"if meta and len(meta) != len(replies):\n    raise AssertionError(f\"replies={len(replies)} vs meta={len(meta)}\")","typeGuard":null,"tryCatchPattern":"try:\n    result = answer_builder.run(replies=replies, meta=meta)\nexcept ValueError as e:\n    if \"must match\" in str(e):\n        logging.error(\"Replies/meta mismatch: %s\", e)\n    raise","preventionTips":["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."],"tags":["haystack","answer-builder","length-mismatch","validation"],"backgroundTag":"list-length-mismatch","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}