Skip to main content
Glama
README.md
# gguf-template-check

[![Tests](https://github.com/vanshaj1999/gguf-template-check/actions/workflows/tests.yml/badge.svg)](https://github.com/vanshaj1999/gguf-template-check/actions/workflows/tests.yml)

Is the GGUF model you downloaded still using its official chat template? This checks it in one command.

Every GGUF file carries its own copy of the model's chat template, frozen on the day the file was made. Model authors keep fixing their templates after release, and the copies on Hugging Face don't update. I looked at 1,788 GGUF uploads of six popular models, and for four of them most downloads get a template that differs from the official one today. Sometimes that's harmless. Sometimes it crashes your app the first time the model calls a tool, or quietly drops the tools from the prompt.

<!-- mcp-name: io.github.vanshaj1999/gguf-template-check -->

The full write-up is on Medium: [Your AI Model Isn't Broken. The File You Downloaded Is Out of Date.](https://medium.com/@vanshaj.kakkar/your-ai-model-isnt-broken-the-file-you-downloaded-is-out-of-date-bfc36a6a3ea9)

## Check your model

You need [uv](https://docs.astral.sh/uv/). Nothing else to install.

```bash
git clone https://github.com/vanshaj1999/gguf-template-check
cd gguf-template-check

# a repo on Hugging Face (the base model is found automatically)
uv run check_template.py bartowski/Qwen_Qwen3-8B-GGUF

# or a file you already have
uv run check_template.py ~/models/Qwen3-8B-Q4_K_M.gguf --base Qwen/Qwen3-8B
```

You can also skip the clone and run it from PyPI:

```bash
uvx gguf-template-check bartowski/Qwen_Qwen3-8B-GGUF
```

This is what it says about Qwen's own Qwen3-8B GGUF, the most downloaded one:

```
Checking  Qwen/Qwen3-8B-GGUF
Base      Qwen/Qwen3-8B
Official  2 template version(s), the current one from 2025-05-19

Result    OUT OF DATE. It matches the official template from 2025-04-28.
          Qwen/Qwen3-8B has changed it since then (latest change 2025-05-19).

Test conversation                    This file vs current official
  plain question                     same
  system prompt                      same
  ...
  tool call with null content        FAILS: TypeError: argument of type 'NoneType' is not iterable
  ...
```

It pulls every version of the template from the base model's history and renders each one, plus the one in your file, over 12 test conversations: plain chat, system prompts, tools, tool results, a tool call with `null` content (what OpenAI-style clients send back), parallel calls and a few reasoning cases. Then it tells you if your file is up to date, out of date (and since when), or edited by the uploader.

If it's out of date, `--save chat_template.jinja` writes the current official template, and you can hand that to llama.cpp:

```bash
llama-server -m model.gguf --jinja --chat-template-file chat_template.jinja
```

`--json` prints the whole result as JSON, for scripts and agents. `--list-local` lists the GGUF files in your LM Studio, llama.cpp and Hugging Face cache folders, or in a folder you name (`--list-local ~/models`).

### Use it from your AI agent

The whole checker is also an MCP server. In Claude Code:

```bash
claude mcp add gguf-template-check -- uvx --from gguf-template-check gguf-template-check-mcp
```

For any other MCP client, add this to its config:

```json
{
  "mcpServers": {
    "gguf-template-check": {
      "command": "uvx",
      "args": ["--from", "gguf-template-check", "gguf-template-check-mcp"]
    }
  }
}
```

It exposes five tools: `check_gguf_template`, `check_llama_server`, `find_local_gguf_models`, `get_official_template` and `show_prompt_diff`.

Or grab just the skill (it tells the agent when to run the check and how to fix what it finds):

```bash
npx skills add vanshaj1999/gguf-template-check
```

Or install the Claude Code plugin, which bundles the MCP server and the skill:

```bash
claude plugin marketplace add vanshaj1999/gguf-template-check
claude plugin install gguf-template-check@vanshaj1999
```

### Check a running llama-server

If you already run llama-server, point the checker at it:

```bash
uv run check_template.py --server http://127.0.0.1:8080
# needs the base model only when it can't be detected:
uv run check_template.py --server http://127.0.0.1:8080 --base Qwen/Qwen3-0.6B
```

It reads the server's template from `/props`, checks that text the same way as above, then POSTs all 12 test conversations to `/apply-template` and compares the prompts the server really builds.

Two rows usually come back different on purpose: llama.cpp rewrites tool calls whose arguments arrive as a string (what OpenAI-style clients send) and handles the `reasoning_content` field itself. Those print as `different (llama.cpp rewrites this input, expected)` and are not a problem. When every row matches, the server needs no fix, even if the template inside the file is old (the checker still tells you, because Python apps reading that file would break). If the tools rows say `TOOLS DROPPED`, or the tool chats fail, start the server with `--jinja`.

A few things to know:

- It renders templates with Python Jinja, the same way `transformers` and `llama-cpp-python` do. llama.cpp has its own template engine and papers over some gaps, so a template that fails here can still work there. Its `/apply-template` endpoint shows you the exact prompt it builds, and `--server` does that comparison for you.
- I still haven't tested how LM Studio applies templates at runtime. `--list-local` finds its files and the check works on them, and if one is out of date you can paste the official template into that model's Prompt Template setting. Ollama isn't covered at all: it stores its own template and ignores the one inside the GGUF.
- Gated base models (Llama, Gemma) need a Hugging Face token in `HF_TOKEN`.
- It exits with 1 when the template isn't up to date, so you can drop it into a script. Exit 2 means the check itself failed (bad repo id, missing file, unreachable server).

## Privacy

The checker has no telemetry and no account. It only talks to:

- the Hugging Face Hub, to read the model and template history you ask about (with your `HF_TOKEN` if you set one)
- a llama-server, only at the URL you give `--server`

It reads the header of local `.gguf` files, keeps downloaded templates in `~/.cache/gguf-template-check` (delete it any time), and writes a file only where you ask it to save a template.

## What I found

Share of the last 30 days' downloads (23 Nov 2026, clean repacks only) whose template doesn't build the official prompt, either because the prompt is different or because the template fails:

| Model | Python (transformers) | llama.cpp | What goes wrong |
|---|---|---|---|
| Mistral-7B-Instruct v0.3 | 97% | 97% | Python rejects system prompts. llama.cpp drops tool definitions without a warning and returns HTTP 400 on tool results. |
| Qwen3-8B | 84% | 0% | Python crashes on a tool call with `null` content. llama.cpp patches it. |
| Qwen2.5-7B-Instruct | 70% | 70% | Doubled braces in the tool-call example. No measurable effect. |
| gpt-oss-20b | 62% | 62% | Small formatting differences. No measurable effect. |
| Phi-4-mini-instruct | 0% | 0% | |
| Qwen3.8-27B | 0% | 0% | |

![Share of GGUF downloads that build the official prompt, by engine](https://raw.githubusercontent.com/vanshaj1999/gguf-template-check/main/img/fig1_engines.png)

Then I ran the files on an RTX 5090 to see what the differences actually do:

- **Same file, different template.** With the template inside it, lmstudio-community's Mistral 7B file didn't make a single tool call in 60 function-calling tasks, and over its 100 tasks it scored 12%. With the current official template swapped in, the same file called a tool in all 60, got 55 right, and scored 87%. The Qwen2.5 and gpt-oss template differences changed the wording of the replies but not a single right or wrong answer.
- **Same label, different uploaders.** Eight Qwen3-8B Q4_K_M files from different uploaders scored between 91.0% and 92.3% over 300 tasks, against 92.7% for Qwen's Q8_0. None of those gaps is statistically significant. Who made the file barely matters. Which template it carries can matter a lot.

![Same file, different template](https://raw.githubusercontent.com/vanshaj1999/gguf-template-check/main/img/fig4_testc_templates.png)

The short version: a difference in formatting (whitespace, braces, quoting) didn't change anything I measured. A difference in capability (a template that predates tool calling) switched the feature off completely.

## Reproduce it

Everything I ran is in `harness/`. In the code, the scan is Test A, the uploader comparison is Test B and the template swap is Test C.

```bash
# the scan: every GGUF upload of the six models, about 1,800 Hub requests at roughly one a second
uv run harness/scan.py
python3 harness/analyse_scan.py

# the same templates rendered by llama.cpp (I used build b12359)
# needs llama-server on your PATH and models/Qwen3-0.6B-Q8_0.gguf
uv run harness/engine_render.py
python3 harness/analyse_engine.py --diffs

# check the Hub API against real file headers (20 uploads, range requests only)
uv run harness/gguf_header.py

# the Qwen3-8B crash in the real libraries, and the ten file fingerprints
uv run harness/check_libraries.py
uv run harness/file_hashes.py

# the benchmarks: start llama-server --jinja on a GPU machine first
uv run harness/build_tasks.py
python3 harness/bench.py --run qwen3-8b__unsloth__embedded --base http://127.0.0.1:8090
uv run harness/grade.py --ref qwen3-8b__official-q8__embedded

# charts
uv run harness/figs_scan.py
uv run harness/figs_bench.py
```

Benchmark settings: greedy decoding, fixed seed, thinking off, at most 2,048 tokens per reply, one file at a time. The 300 tasks are 100 GSM8K, 100 IFEval (graded with Google's checker), 60 BFCL simple function calls, 20 multi-turn rule checks and 20 tool-result checks. `results/` has every raw reply, so you can regrade without a GPU.

## What's in here

| Path | What it is |
|---|---|
| `check_template.py` | The one-command checker (a small `uv` script that runs the package) |
| `gguf_template_check/` | The installable package: CLI, core checks, local model discovery, llama-server check, MCP server |
| `pyproject.toml` | `pip install`-able package: `gguf-template-check` and `gguf-template-check-mcp` entry points |
| `skills/gguf-template-check/` | Agent skill: when to run the check and the fixes that work |
| `.claude-plugin/` | Claude Code plugin and marketplace files |
| `server.json` | MCP Registry metadata |
| `gguf_template_check/hub.py` | Small Hub client with a polite gap between requests (0.2 s for a check, 0.8 s in the study scripts); the study scripts point its disk cache at `results/cache/` |
| `gguf_template_check/render.py` | The 12 test conversations and the transformers-style renderer |
| `harness/scan.py` | The scan, plus how "out of date" is decided |
| `harness/engine_render.py` | The llama.cpp side, through `llama-server /apply-template` |
| `harness/build_tasks.py`, `bench.py`, `grade.py` | Benchmark tasks, runner and grader (Wilson intervals, exact McNemar tests) |
| `harness/check_libraries.py` | The null-content crash, reproduced in transformers and llama-cpp-python |
| `harness/file_hashes.py` | SHA-256 of the ten most downloaded Qwen3-8B Q4_K_M files, from Hub metadata |
| `tests/` | Offline tests for the package: `uv run --group dev pytest -q` (add `--network` for the live Hub ones) |
| `results/` | Scan results, every template I found, rendered prompts and all benchmark replies |
| `img/` | Charts |

How I sorted the uploads:

- **Clean repack:** the repo name is the base model's name plus quantisation words and nothing else. Fine-tunes, merges and uncensored variants are left out. It's a name rule, so it isn't perfect.
- **Up to date:** builds the same prompt as the current official template for all 12 conversations.
- **Out of date:** builds the same prompts as an older official version from the base repo's history.
- **Edited:** matches no official version.

## Licence

My code is MIT. `harness/instruction_following_eval/` is Google's IFEval checker (Apache 2.0, licence in that folder), with one change marked in `instructions_util.py`. The task data comes from GSM8K (MIT), IFEval (Apache 2.0) and BFCL (Apache 2.0). The chat templates in `results/` belong to their model authors.