~/tools / Model files and chat templates / Hugging Face Chat Template Tester

Hugging Face Chat Template Tester — Render a Hugging Face chat template and see the exact prompt

Paste a Hugging Face chat template (Jinja) or a model's whole tokenizer_config.json, add messages and tools, and see the exact prompt text that transformers' apply_chat_template(..., tokenize=False) produces. The tool runs Jinja2 with the same sandboxed settings as transformers, so the text, the errors and their line numbers are the same as in Python. Nothing leaves your browser.

Examples (written for this tool)

Paste the Jinja template (chat_template.jinja), or the whole tokenizer_config.json or chat_template.json from the model's files on Hugging Face.

A JSON list of messages, the same list you pass to apply_chat_template.

A JSON list of tool definitions (JSON Schema). Leave it empty for no tools.

Adds the start of an assistant turn at the end, so the model writes a reply (if the template supports it).

Leaves the last message open so the model continues it (prefill). It cannot be used together with add_generation_prompt.

Other values passed to apply_chat_template as keyword arguments, as a JSON object, such as {"enable_thinking": false}. The variables the template reads are listed below the output.

More options
Special tokens

transformers passes the tokenizer's special tokens to the template. They are filled in when you paste tokenizer_config.json.

For templates that support documents (RAG): a JSON list of objects such as {"title": "…", "text": "…"}.

The time that strftime_now() returns. Leave it empty to use the current time.

Prompt text

<|im_start|>system
You are a helpful assistant.

# Tools

You can call these functions:
<tools>
{"type": "function", "function": {"name": "get_weather", "description": "Get the current weather in a city.", "parameters": {"type": "object", "properties": {"city": {"type": "string", "description": "City name"}}, "required": ["city"]}}}
</tools>

To call one, reply with JSON inside <tool_call></tool_call>.<|im_end|>
<|im_start|>user
What's the weather in Paris?<|im_end|>
<|im_start|>assistant

<tool_call>
{"name": "get_weather", "arguments": {"city": "Paris"}}
</tool_call><|im_end|>
<|im_start|>user
<tool_response>
{"temperature": 22}
</tool_response><|im_end|>
<|im_start|>assistant
688 characters

About this template

Variables it reads
Set by apply_chat_template: add_generation_prompt, messages, tools
Special tokens: none
Other: none
Uses {% generation %}
No

Check it in Python

Run this to compare with transformers. Replace MODEL_ID with the model, or pass your template as chat_template=.

from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("MODEL_ID")
messages = [
    {'role': 'system', 'content': 'You are a helpful assistant.'},
    {'role': 'user', 'content': "What's the weather in Paris?"},
    {'role': 'assistant', 'content': '', 'tool_calls': [{'type': 'function', 'function': {'name': 'get_weather', 'arguments': {'city': 'Paris'}}}]},
    {'role': 'tool', 'name': 'get_weather', 'content': '{"temperature": 22}'},
]
tools = [
    {'type': 'function', 'function': {'name': 'get_weather', 'description': 'Get the current weather in a city.', 'parameters': {'type': 'object', 'properties': {'city': {'type': 'string', 'description': 'City name'}}, 'required': ['city']}}},
]
text = tokenizer.apply_chat_template(
    messages,
    tools=tools,
    add_generation_prompt=True,
    tokenize=False,
)
print(text)

The output is the text before tokenization. transformers then tokenizes it with add_special_tokens=False, so special tokens appear only where the template writes them.

When tools are given and the model has a template named tool_use, transformers uses that one. You can also choose a template by name.

Messages, tools and documents are read like Python's json module: whole numbers become int and numbers with a decimal point become float, which can change how the template prints them.

Checked on 2026-11-09 against transformers 5.22.2 with Jinja2 3.1.6 (Python 3.14). transformers: chat templates · transformers source

Everything runs in your browser. Nothing you paste is sent or saved.

Most open models on Hugging Face ship a chat template: a small Jinja program that turns a list of messages into the text the model actually reads. A missing space, a doubled BOS token or a wrong generation prompt changes what the model sees, and the template is hard to read without running it. This tool runs it the way transformers does. We ported Jinja2 3.1.6 to JavaScript: its lexer, parser, the rules for which variables are visible where, constant folding, the sandbox that transformers uses, and all built-in filters and tests, together with Python's own behaviour for strings, numbers, sorting and error messages. On top of that it follows apply_chat_template in transformers 5.22.2: special tokens such as bos_token, the tool_use template when tools are given, add_generation_prompt, continue_final_message, documents, reasoning_content, and the {% generation %} spans. We rendered the chat templates of 39 open models (Qwen, Llama, Mistral, Gemma, Phi, DeepSeek, gpt-oss and others) with 15 kinds of conversations, and all 585 results matched transformers. More than 20,000 other test templates also matched, including errors and line numbers, except a few that use the random filter, whose result is random in Python too.

Use Cases

  • See the exact prompt a model receives before you fine-tune or serve it: BOS and EOS tokens, spaces, line breaks and the generation prompt
  • Find the switches a template reads, such as enable_thinking, and see what they change
  • Debug a chat template you are writing, with errors and line numbers, tools, documents and continue_final_message

Usage

  1. Paste a chat template, or the whole tokenizer_config.json or chat_template.json of a model, or pick an example.
  2. Edit the messages and tools (the same JSON lists you pass in Python), and set add_generation_prompt and the other options.
  3. Read the prompt text and the variables the template uses, and copy the Python code to check the same input in transformers.

FAQ

Is the result the same as apply_chat_template?

It is the same as apply_chat_template(..., tokenize=False), the text before tokenization. Special tokens, add_generation_prompt, continue_final_message, tools and documents are handled as in transformers 5.22.2. The tool does not turn the text into token IDs.

Where do bos_token and eos_token come from?

In Python they come from the tokenizer. When you paste tokenizer_config.json, the tool reads them from it. Otherwise, enter them under More options.

What does {% generation %} do?

Some templates wrap the assistant's replies in {% generation %} … {% endgeneration %}. transformers uses these spans for return_assistant_tokens_mask, for example to train only on the assistant's tokens. The tool highlights them in the output.

Will vLLM, llama.cpp or other servers give the same text?

Other software can render the same template with a different engine or different settings, so its output can differ. This tool follows transformers.

Why is a variable such as enable_thinking listed under Other?

The template reads it, but apply_chat_template does not set it. Pass it as an extra variable (for example {"enable_thinking": false}) to change the output, as you would pass enable_thinking=False in Python.

Is my template sent anywhere?

No. Everything runs in your browser.

Related