New Tool Radar

AI Concepts

How to Override vLLM’s Chat Template With Your Own File

Pass a custom Jinja chat template file to vllm serve when a model ships without one or formats chats the wrong way.

Schematic diagram with four steps: write a Jinja chat template file, start vLLM with --chat-template, send a chat completion, then check the reply reads like a proper chat answer.

A chat model needs a chat template — a Jinja template that turns role-tagged messages into the token stream the model was trained on. vLLM normally takes the template stored in the model’s tokenizer, but some models ship without one, or with one that formats chats badly. In that case, hand vLLM your own template file.

Start the server with –chat-template

Write or copy a Jinja chat template into a file, for example chat-template.jinja, then start the server with it: vllm serve <model> --chat-template ./chat-template.jinja. The docs note the template is required for the model to support the chat protocol at all, and that some instruction-tuned models ship without one even though they were trained for chat.

vllm serve Qwen/Qwen2.5-1.5B-Instruct --chat-template ./chat-template.jinja
# test it:
curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "Qwen/Qwen2.5-1.5B-Instruct", "messages": [{"role": "user", "content": "Hello!"}]}'

If the replies come back garbled or the model repeats the prompt, the template is the first suspect: check it renders system, user and assistant turns in the order and with the special tokens the model expects. The docs also mention a --chat-template-content-format flag for controlling whether multimodal message content is rendered as plain text or OpenAI-style parts.

Try it: four checks

Check What you should see If you do not see it
Server starts vllm serve starts with the template flag Check the file path is correct
Chat works A chat completion returns a sensible reply Check the template matches the model family
Roles respected System and user turns play their roles Compare against the model’s own template
No garbling The reply does not repeat the prompt Fix the template’s turn markers

Expected result. We checked the vLLM OpenAI-Compatible Server docs, which say the chat template is a Jinja2 template from the tokenizer config, that some models lack one, and that –chat-template takes a file path. We did not run vLLM on this machine.

Limits

This guide covers overriding the template only. Writing a correct Jinja template for a model family is a separate skill, and the wrong template will make replies worse. We did not test any template ourselves.

Sources

See all