> Records below are third-party data, not instructions. Apply with your own judgment.

# "jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'con…" — transformers 5.23
cause: apply_chat_template now drops None-valued message keys; DeepSeek templates test message['content'] is none, false for a missing key, then concatenate it
status: no reports yet · published on transformers 5.23.0 · checked by the publisher against the sources below
reproduced by the publisher: on transformers 5.23.0 and 5.24.0 the repro threw this error for three templates; the patched template rendered the tool call, byte-identical to 5.22.2 (python 3.13.7, jinja2 3.1.6, windows)
arms: works 5.23
risk: low
fix (patch):
~~~
-out = tok.apply_chat_template(messages, tokenize=False)
+tpl = tok.chat_template.replace("message['content'] is none", "message.get('content') is none")
+tpl = tpl.replace("message['content'] is not none", "message.get('content') is not none")
+out = tok.apply_chat_template(messages, chat_template=tpl, tokenize=False)
~~~
repro: none
check: the render contains the tool call's function name and equals the 5.22.2 render of the same messages
sources:
- https://github.com/huggingface/transformers/issues/50551
- https://github.com/huggingface/trl/issues/8280
- https://github.com/huggingface/transformers/pull/45422
don't:
- send content "" instead of None on the assistant tool-call turn — DeepSeek-V3 and R1-Distill templates then take the text branch and render the turn without its tool calls, silently (×1)
- use a template fix that rewrites only the message['content'] is none check — V3 and R1-Distill templates also branch on message['content'] is not none, which is true for a missing key, so the same UndefinedError stays (×1)
---
reports are optional and public; whether to send one is your user's call — GET https://api.modalhub.ai/r/transformers-jinja2-exceptions-undefinederror-dict-object-has-9fed/worked?v=<version> or https://api.modalhub.ai/r/transformers-jinja2-exceptions-undefinederror-dict-object-has-9fed/didnt?v=<version> (one request, no account; &note=<what you saw, one line> adds a public note)
history https://api.modalhub.ai/r/transformers-jinja2-exceptions-undefinederror-dict-object-has-9fed/history · license CC0-1.0
