Datasets:
|
Download README.md from SamJoshua/chat-template-toolcall-bench: direct link, hf CLI and curl.
- Browser
- Download file 11.4 kB
-
https://huggingface.co/datasets/SamJoshua/chat-template-toolcall-bench/resolve/main/README.md
- Command line
-
hf download hf://datasets/SamJoshua/chat-template-toolcall-bench/README.md
-
curl -L -o README.md https://huggingface.co/datasets/SamJoshua/chat-template-toolcall-bench/resolve/main/README.md
11.4 kB
| license: apache-2.0 | |
| pretty_name: Chat Template Tool-Call Bench | |
| task_categories: | |
| - text-generation | |
| language: | |
| - en | |
| tags: | |
| - tool-calling | |
| - chat-template | |
| - agents | |
| - evaluation | |
| - reliability | |
| - compatibility | |
| size_categories: | |
| - n<1K | |
| configs: | |
| - config_name: cases | |
| data_files: cases.parquet | |
| - config_name: results | |
| data_files: results.parquet | |
| - config_name: models | |
| data_files: models.parquet | |
| # Chat Template Tool-Call Bench (CTT-Bench) | |
| **Version 1.0** · measured 16 Nov 2026, 22:16 IST · `transformers 5.22.2` | |
| A small, versioned set of conversations for checking whether a model's **chat template** can render tool calls through `tokenizer.apply_chat_template`. It is a **harness / spec-compatibility** bench, not a model-quality bench. The questions it answers are: does the template crash, silently corrupt arguments, or paste an unescaped tool name? | |
| Companion static leaderboard (proposed): [SamJoshua/chat-template-toolcall-leaderboard](https://huggingface.co/spaces/SamJoshua/chat-template-toolcall-leaderboard). The same three baseline checks also appear as tab 8 of [SamJoshua/agent-harness-checks](https://huggingface.co/spaces/SamJoshua/agent-harness-checks). | |
| ## The caveat | |
| A crash (or a clear `TemplateError`) when `tool_calls[].function.arguments` is a JSON string is a **chat-template spec-compatibility issue, not a model bug**. The transformers docs treat arguments as a mapping (a dict). This bench still scores OpenAI-style JSON strings because that is the shape you get from OpenAI-compatible APIs, logged traces, and many function-calling datasets. Feeding those messages straight into `apply_chat_template` is a thing people actually do, and 31 of 40 templates in this snapshot die on it with an obscure Jinja error. | |
| Practical rule for a harness: `json.loads` every `arguments` value before you template, and reject a tool name that is not in your declared tool list before you write it into history. | |
| ## Headline numbers (v1.0) | |
| Population: **41** repos (**33** distinct template hashes) whose chat template references `tool_calls`. Taken from the top 500 `text-generation` models by Hub downloads, last updated within 180 days, minus quants, abliterated forks, and tiny test repos. Snapshot date 16 Nov 2026. 21 further repos from that sweep are listed in `exclusions.json` (14 had no tool-call template, 7 failed to load a tokenizer). | |
| Of the **40** templates that can render a normal dict-shaped tool call: | |
| | Case | Result among those 40 | | |
| | --- | --- | | |
| | C1 dict args (baseline) | **40 / 40** pass | | |
| | C3 empty dict, C5 nested dict, C7 unicode dict, C9 two tool calls | **40 / 40** pass | | |
| | C2 OpenAI-style string args | **3** render correctly, **31** crash with an obscure Jinja error, **5** raise a clear "deserialize first" error, **1** silently double-encodes | | |
| | C6 nested string, C8 unicode string | same split as C2 | | |
| | C4 empty string `'{}'` | **6** pass, **31** crash, **2** clear error, **1** double-encodes | | |
| | C10 quote-containing tool name | **0 / 40** escape it; all 40 paste the raw name | | |
| The remaining repo, [`swiss-ai/Apertus-8B-Instruct-2509`](https://huggingface.co/swiss-ai/Apertus-8B-Instruct-2509), crashes on every case because the template reads `tool.description` on a schema that does not have that attribute. A fix is in [PR #36](https://huggingface.co/swiss-ai/Apertus-8B-Instruct-2509/discussions/36). | |
| No template in the set passes all 10 cases. The best score is **9 / 10**, on three repos, all failing only C10: | |
| - `laion/delphi-1e22-9_7Bparams-160Btokens-base-wc386k_lr1e5-sft` | |
| - `trl-internal-testing/small-Qwen3ForCausalLM` | |
| - `Vxtzq/Crowd-v1` | |
| The C4 "empty string" extra passes (6, not 3) are the three repos above plus three LiquidAI templates (`LFM2.5-350M`, `LFM2.5-1.2B-Instruct`, `LFM3-1.7B`). Those three raise a clear error on non-empty JSON strings, but their template explicitly allowlists `"{}", "", "null"` and renders an empty call. That is intentional, not a scorer bug. | |
| The silent double-encoder is `JackKozmo29/depguard-jev-style-1.5b`: string arguments are pasted as a JSON string inside a JSON object (`"arguments": "{\"city\": \"Paris\", ...}"`). | |
| ## Test cases | |
| | ID | Short name | What is under test | Pass if | | |
| | --- | --- | --- | --- | | |
| | C1 | `dict_args` | `arguments` is a Python dict `{"city": "Paris", "metric": True}` — the transformers-documented shape | Renders; `Paris` appears, not double-encoded | | |
| | C2 | `string_args` | Same payload as a JSON string, the OpenAI-compatible shape | Renders; `Paris` appears decoded, not as `\"Paris\"` | | |
| | C3 | `empty_args` | `arguments` is `{}` | Renders; `get_weather` appears in the post-user region | | |
| | C4 | `empty_string_args` | `arguments` is the string `'{}'` | Same, and not pasted as `"arguments": "{}"` | | |
| | C5 | `nested_args` | Dict with a nested object and a boolean | Renders; `Paris`, `units`, and `C` appear | | |
| | C6 | `nested_string_args` | Same nested payload as a JSON string | Same, not double-encoded | | |
| | C7 | `unicode_args` | Dict values `París` and `東京の天気` | Both values appear (UTF-8 or a reversible `\u` escape) | | |
| | C8 | `unicode_string_args` | Same unicode payload as a JSON string (`ensure_ascii=False`) | Same, not double-encoded | | |
| | C9 | `multi_tool_calls` | One assistant turn with `get_weather` and `get_time` | Both names, plus `Paris` and `Tokyo`, appear | | |
| | C10 | `name_escape` | Tool name `x", "arguments": {"cmd": "rm -rf /"}, "y": "` | The raw string does **not** appear unescaped in the prompt | | |
| Full conversations, tool schemas, and marker lists are in `cases.jsonl` (and `cases.parquet`). | |
| ## Scoring | |
| Each `(repo, case)` row in `results.jsonl` has a `status`: | |
| | Status | Meaning | | |
| | --- | --- | | |
| | `pass` | Rendered; expected markers present; not double-encoded; for C10, the raw name is not pasted | | |
| | `fail_crash` | Exception, usually `jinja2.UndefinedError` or `TypeError: Can only get item pairs from a mapping` | | |
| | `fail_clear` | `TemplateError` (or similar) that tells the caller to deserialize / pass a mapping | | |
| | `fail_double_encoded` | Rendered, but arguments appear as an escaped JSON string inside the prompt | | |
| | `fail_dropped` | Rendered, but expected markers were missing | | |
| | `fail_raw_name` | C10 only: the injection string appears verbatim | | |
| `fail_clear` is **not** a pass. It is a better failure mode than an obscure crash — the template is being honest — but it is still not OpenAI-string compatible. The leaderboard sorts by number of `pass` results, so a clear error ranks below a correct render and the empty-string allowlist can still move a repo one point. | |
| Markers and snippets are taken from the **post-user region** of the rendered prompt, so a tool name that already appears in the rendered tool schema is not counted as a successful call. | |
| ## What's in this repo | |
| | File | What it is | | |
| | --- | --- | | |
| | `cases.jsonl` / `cases.parquet` | The 10 test cases: messages, tools, expected markers, pass rule | | |
| | `results.jsonl` / `results.parquet` | One row per `(repo, case)` with status, error, and a short snippet | | |
| | `models.jsonl` / `models.parquet` | One row per repo: downloads, template hash, per-case status, pass counts | | |
| | `repos.json` | The 41 measured repo ids and the download/like snapshot | | |
| | `exclusions.json` | Repos from the same sweep that were not measured, and why | | |
| | `summary.json` | Headline counts, versions, timestamp | | |
| | `scan.py` | The runner. Re-run with the same `repos.json` to reproduce | | |
| | `leaderboard_data.json` | Convenience bundle used by the static leaderboard Space | | |
| Downloads and likes are Hub figures as of the 16 Nov 2026 snapshot (the Hub `downloads` field, commonly a 30-day window). | |
| ## Method | |
| For each repo: | |
| 1. `AutoTokenizer.from_pretrained(repo_id, trust_remote_code=False, local_files_only=True)` (falls back to the network if the cache misses). | |
| 2. SHA-1 of the chat template string (the `tool_use` or `default` entry if the template is a dict), first 10 hex chars, as `template_sha1`. | |
| 3. For each case, `tokenizer.apply_chat_template(messages, tools=TOOLS, tokenize=False, add_generation_prompt=False)`. | |
| 4. Classify the exception or the rendered text as above. | |
| The runner does not load model weights and does not generate tokens. A change in `transformers`, in the repo's `chat_template`, or in the case list is a new bench version. | |
| ## How to reproduce | |
| ```bash | |
| pip install transformers==5.22.2 | |
| python scan.py --repos repos.json --out-dir . | |
| ``` | |
| Or a single case, without the runner: | |
| ```python | |
| import json | |
| from transformers import AutoTokenizer | |
| tok = AutoTokenizer.from_pretrained("openbmb/MiniCPM5-2B") | |
| tools = [{ | |
| "type": "function", | |
| "function": { | |
| "name": "get_weather", | |
| "description": "Get weather", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "city": {"type": "string", "description": "City"}, | |
| "metric": {"type": "boolean", "description": "Metric units"}, | |
| }, | |
| "required": ["city"], | |
| }, | |
| }, | |
| }] | |
| messages = [ | |
| {"role": "user", "content": "Weather in Paris?"}, | |
| { | |
| "role": "assistant", | |
| "content": "", | |
| "tool_calls": [{ | |
| "id": "c1", | |
| "type": "function", | |
| "function": { | |
| "name": "get_weather", | |
| # OpenAI-style string. A dict also works for C1. | |
| "arguments": json.dumps({"city": "Paris", "metric": True}), | |
| }, | |
| }], | |
| }, | |
| {"role": "tool", "tool_call_id": "c1", "name": "get_weather", "content": '{"temp": 21}'}, | |
| ] | |
| print(tok.apply_chat_template(messages, tools=tools, tokenize=False)) | |
| ``` | |
| On many popular templates that call raises `UndefinedError: 'str object' has no attribute 'items'` or `TypeError: Can only get item pairs from a mapping`. Passing `json.loads(...)` (a dict) instead of the string is the documented shape and is what C1 tests. | |
| ## Limitations | |
| - This is not a measure of how well a model *writes* tool calls. It only measures how the published chat template *renders* a conversation you already have. | |
| - The population is "popular and recently updated on the Hub," not a complete catalogue of tool-calling models. Family forks that share a template hash are listed separately; the leaderboard can collapse them. | |
| - C10 ("verbatim name") is a strict string check. Whether an unescaped name actually breaks the structure depends on the format: JSON tool-call blocks are exposed, XML-style tags less so. The raw name is still in the prompt either way. | |
| - Boolean style (`true` vs `True`) is recorded as `value_style` when it is obvious, but it is not a pass/fail. Some templates are intentionally Python-call shaped (for example several LiquidAI LFM templates). | |
| - Gated or broken tokenizers from the original sweep are in `exclusions.json`, not in the scores. | |
| Related reports: [Qwen3.8-27B #240](https://huggingface.co/Qwen/Qwen3.8-27B/discussions/240), [MiniCPM5-2B #30](https://huggingface.co/openbmb/MiniCPM5-2B/discussions/30), [Granite 4.1-3b #7](https://huggingface.co/ibm-granite/granite-4.1-3b/discussions/7), [Apertus-8B PR #36](https://huggingface.co/swiss-ai/Apertus-8B-Instruct-2509/discussions/36). | |
| ## License and author | |
| Apache-2.0. The conversations and scores in this repo are original. The measured templates belong to their model authors. | |
| [Sam Joshua](https://huggingface.co/SamJoshua) · [@SAM_JOSHUA_S](https://x.com/SAM_JOSHUA_S) | |