{"record":{"id":"3981015802b28ebf","repo":"deepset-ai/haystack","slug":"the-templatize-part-filter-cannot-be-used-with-a-t","errorCode":null,"errorMessage":"The templatize_part filter cannot be used with a template containing a list ofChatMessage objects. Use a string template or remove the templatize_part filter from the template.","messagePattern":"The templatize_part filter cannot be used with a template containing a list ofChatMessage objects\\. Use a string template or remove the templatize_part filter from the template\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/builders/chat_prompt_builder.py","lineNumber":180,"sourceCode":"        \"\"\"\n        self._variables = variables\n        self._required_variables = required_variables\n        self.template = template\n\n        self._env = HaystackSandboxedEnvironment(extensions=[ChatMessageExtension])\n        if arrow_import.is_successful():\n            self._env.add_extension(Jinja2TimeExtension)\n\n        extracted_variables = []\n        if template and not variables:\n            if isinstance(template, list):\n                for message in template:\n                    if message.is_from(ChatRole.USER) or message.is_from(ChatRole.SYSTEM):\n                        # infer variables from template\n                        if message.text is None:\n                            raise ValueError(NO_TEXT_ERROR_MESSAGE.format(role=message.role.value, message=message))\n                        if message.text and \"templatize_part\" in message.text:\n                            raise ValueError(FILTER_NOT_ALLOWED_ERROR_MESSAGE)\n                        assigned_variables, template_variables = _extract_template_variables_and_assignments(\n                            env=self._env, template=message.text\n                        )\n                        extracted_variables += list(template_variables - assigned_variables)\n            elif isinstance(template, str):\n                assigned_variables, template_variables = _extract_template_variables_and_assignments(\n                    env=self._env, template=template\n                )\n                extracted_variables = list(template_variables - assigned_variables)\n\n        extracted_variables = extracted_variables or []\n        self.variables = variables or extracted_variables\n        self.required_variables = required_variables or []\n\n        if len(self.variables) > 0 and required_variables is None:\n            logger.warning(\n                \"ChatPromptBuilder has {length} prompt variables and `required_variables` is explicitly set to \"\n                \"`None`. This treats all prompt variables as optional, which may lead to unintended behavior in \"","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/builders/chat_prompt_builder.py#L162-L198","documentation":"ChatPromptBuilder rejects the custom 'templatize_part' filter when the template is a list of ChatMessage objects. The filter only works with plain string templates, so __init__ raises to prevent misuse that cannot be resolved per-message.","triggerScenarios":"Calling ChatPromptBuilder(template=[ChatMessage.from_user('... {{ x | templatize_part }} ...')]) with a message text containing 'templatize_part' in __init__.","commonSituations":"Migrating a PromptBuilder string template that used templatize_part into ChatPromptBuilder message-list form; copy-pasting template code across the two builders.","solutions":["Remove the templatize_part filter from the message texts.","Switch to ChatPromptBuilder(template='...string...', variables=[...]) so templatize_part is supported.","Pre-render or restructure the template so the partial-templatizing logic is done in Python before building messages."],"exampleFix":"// before\nChatPromptBuilder(template=[ChatMessage.from_user('{{ doc | templatize_part }}')])\n// after\nChatPromptBuilder(template='{{ doc | templatize_part }}', variables=['doc'])","handlingStrategy":"validation","validationCode":"bad = [m for m in template if m.text and 'templatize_part' in m.text]\nassert not bad, 'templatize_part not allowed in ChatMessage list templates'","typeGuard":"def uses_allowed_filters(m) -> bool:\n    return not (m.text and 'templatize_part' in m.text)","tryCatchPattern":"try:\n    builder = ChatPromptBuilder(template=msgs)\nexcept ValueError as e:\n    if 'templatize_part' in str(e):\n        builder = ChatPromptBuilder(template=''.join(m.text or '' for m in msgs), variables=[...])\n    else:\n        raise","preventionTips":["Reserve templatize_part for string templates only.","Grep stored prompt messages for 'templatize_part' when migrating from PromptBuilder.","Document which Jinja filters your team allows in message-list templates."],"tags":["validation","chat-prompt-builder","jinja-template"],"backgroundTag":"unsupported-template-filter","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}