Chat models expect their prompts wrapped in a template: system, user and assistant turns marked with the model’s own special tokens. llama-server can take a Jinja template file with –jinja, which is useful when the model’s built-in template is missing or wrong. This guide supplies a template file and checks the reply format.
Before you start
- llama.cpp installed, with llama-server on your PATH.
- A GGUF chat model, for example a Qwen3 8B Q4_K_M file.
- A Jinja template file for the model, usually copied from the model’s Hugging Face repository.
Get the template file
Find the template in the model’s repository on Hugging Face, usually a file called chat_template.jinja, and save it locally as chat_template.jinja. Check that the file mentions the model’s special tokens for system, user and assistant turns.
Start the server with the template
Point the server at the template file:
llama-server -m qwen3-8b-q4_k_m.gguf --jinja chat_template.jinja --port 8080
The server loads the model and the template together.
Send a chat request
Send a chat completion with a system message and a user message to http://localhost:8080/v1/chat/completions. The reply should follow the model’s normal chat style; a wrong template usually shows up as a reply that starts with stray role markers or repeats the prompt.
Worked example
Worked example: with the Qwen3 template, send a system message “You answer in short sentences.” and the user message “What is a router?” The reply should be a short definition without any visible template markers such as <|im_start|> in the text.
Expected result
UNTESTED in this guide: no server was run while writing it. The expected result is that the server starts with the template and the chat reply is cleanly formatted, with no template markers leaking into the answer.
Limitations
A template written for a different model family can make replies worse, not better. Use the template from the same model family, and if the model already has a correct built-in template, you do not need this flag at all.
