Skip to content

Llama 3.x and GPT-OSS templates: treat tool_calls None as no tool call - #17176

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
vineethsaivs:tcnone-templates
Nov 12, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
vineethsaivs:tcnone-templates

Conversation

@vineethsaivs

Copy link
Copy Markdown
Contributor

datasets fills tool_calls: None into every plain message of a tool-calling dataset. get_chat_template(tok, "llama-3.1") then raises TypeError: object of type 'NoneType' has no len() and "gpt-oss" raises UndefinedError: None has no element 0, on the plain rows too, so the whole formatting map dies.

Both templates tested 'tool_calls' in message, which is true for a None value. They now test message.tool_calls, like the Qwen and Gemma templates. Covers the llama-3.1/3.2/3.3 aliases and gpt-oss/gptoss. An empty tool_calls: [] now renders as a plain turn instead of raising.

Rendering of conversations without the key is byte-identical (96 plain, tool, thinking and tools=... renders compared against main).

Test: pytest tests/python/test_chat_template_tool_calls_none.py fails 33 of 33 on main and passes 33 with the fix. Neighbouring chat template tests: 313 passed.

`datasets` fills `tool_calls: None` into every plain message of a tool-calling
dataset. The two templates tested whether the key exists, so each of those
turns was read as a tool call. Llama 3.1 raised `object of type 'NoneType'
has no len()` and GPT-OSS raised `None has no element 0`, on the plain rows as
well as the tool rows, which stops the whole formatting map.

Test `message.tool_calls` instead, as the Qwen and Gemma templates already do.
A missing key renders exactly as before. An empty `tool_calls: []` now renders
as a plain turn instead of raising.

Test: `tests/python/test_chat_template_tool_calls_none.py` renders plain and
tool conversations with `tool_calls` filled with None or [] and compares them
to the clean ones. It fails 33 of 33 on main and passes with the fix.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T14:19:25.416651Z ba56aab Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: ba56aab476

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants