{"record":{"id":"9b1465869ba02b2d","repo":"deepset-ai/haystack","slug":"name-must-be-a-string","errorCode":null,"errorMessage":"name must be a string","messagePattern":"name must be a string","errorType":"exception","errorClass":"TemplateSyntaxError","httpStatus":null,"severity":"error","filePath":"haystack/utils/jinja2_chat_extension.py","lineNumber":198,"sourceCode":"\n        # Parse role attribute (mandatory)\n        parser.stream.expect(\"name:role\")\n        parser.stream.expect(\"assign\")\n        role_expr = parser.parse_expression()\n\n        if isinstance(role_expr, nodes.Const):\n            role = role_expr.value\n            if role not in self.SUPPORTED_ROLES:\n                raise TemplateSyntaxError(f\"Role must be one of: {', '.join(self.SUPPORTED_ROLES)}\", lineno)\n\n        # Parse optional name attribute\n        name_expr = None\n        if parser.stream.current.test(\"name:name\"):\n            parser.stream.skip()\n            parser.stream.expect(\"assign\")\n            name_expr = parser.parse_expression()\n            if not isinstance(name_expr.value, str):\n                raise TemplateSyntaxError(\"name must be a string\", lineno)\n\n        # Parse optional meta attribute\n        meta_expr = None\n        if parser.stream.current.test(\"name:meta\"):\n            parser.stream.skip()\n            parser.stream.expect(\"assign\")\n            meta_expr = parser.parse_expression()\n            if not isinstance(meta_expr, nodes.Dict):\n                raise TemplateSyntaxError(\"meta must be a dictionary\", lineno)\n\n        # Parse message body\n        body = parser.parse_statements((\"name:endmessage\",), drop_needle=True)\n\n        # Build message node with all parameters\n        return nodes.CallBlock(\n            self.call_method(\n                name=\"_build_chat_message_json\",\n                args=[role_expr, name_expr or nodes.Const(None), meta_expr or nodes.Dict([])],","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/utils/jinja2_chat_extension.py#L180-L216","documentation":"TemplateSyntaxError raised by `_parse_message_tag` when the optional name= attribute of a {% message %} tag parses to a non-string constant. The name is passed through to ChatMessage.name and must be a string literal in the template.","triggerScenarios":"Writing `{% message role='assistant' name=42 %}` or `name=some_list`, i.e. any expression whose constant value is not a str (numbers, booleans, lists).","commonSituations":"Forgetting quotes around the name: name=claude instead of name='claude'; passing a numeric identifier; YAML/JSON-influenced habits where names are unquoted keys.","solutions":["Quote the name: name='my-name' so it parses as a string constant","Remove the name attribute if it is not needed","Verify the expression is a literal string, not a variable or number"],"exampleFix":"// before\n{% message role='assistant' name=claude %}...{% endmessage %}\n// after\n{% message role='assistant' name='claude' %}...{% endmessage %}","handlingStrategy":"validation","validationCode":"import re\nfor m in re.finditer(r\"name\\s*=\\s*([^\\s%}]+)\", template):\n    assert m.group(1).startswith(\"'\" ) or m.group(1).startswith('\"'), f\"name must be a quoted string, got {m.group(1)}\"","typeGuard":"null","tryCatchPattern":"from jinja2.exceptions import TemplateSyntaxError\ntry:\n    env.parse(template)\nexcept TemplateSyntaxError as e:\n    if \"name must be a string\" in str(e):\n        raise ValueError(\"Quote the name attribute: name='my-name'\") from e\n    raise","preventionTips":["Always quote the name value: name='literal'","Don't pass numbers, booleans, or variables as name","Lint templates for unquoted attribute values"],"tags":["haystack","jinja2","template-syntax-error","message-tag","name-attribute"],"backgroundTag":"invalid-argument-type","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}