Llama prompt formatter
Hosted APIs hide the chat template from you, but when you run Llama or Mistral locally you have to format prompts yourself — and each family expects a different token structure. Get it wrong and the model ignores your system prompt or mangles the turns. The Llama prompt formatter wraps a system and user message in the exact template each model family was trained on.
How the three formats differ
Each model family uses a distinct set of special tokens to mark role boundaries. Sending a Llama 3 template to a Llama 2 checkpoint (or vice versa) causes the model to misinterpret turns and produce garbled or instruction-ignoring output.
Llama 2 format:
<s>[INST] <<SYS>>
{system message}
<</SYS>>
{user message} [/INST]
Llama 3 format:
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
{system message}<|eot_id|>
<|start_header_id|>user<|end_header_id|>
{user message}<|eot_id|>
<|start_header_id|>assistant<|end_header_id|>
Mistral Instruct format (no system role — system prepended to user turn):
<s>[INST] {system message}
{user message} [/INST]
How it works
You pick a model family and enter a system message and a user message. The tool wraps them in the correct template, including all special tokens and delimiters. The trailing empty assistant header for Llama 3 is added automatically — it marks where generation should begin and is required for the model to start its reply. Everything runs locally — no API key, no network call — and you copy the result straight into your runtime, llama.cpp command, vLLM request body, or any tool that accepts a raw prompt.
Tips and notes
- Match the template to the checkpoint — pick the family that matches the weights you are running; mixing templates degrades output noticeably.
- Keep the special tokens intact — do not hand-edit
<|eot_id|>or[/INST]; the model tokenizer relies on them to delimit turns. - Mistral’s system text is a convention — it lives inside the user turn, so keep it concise and place the most important instructions near the top.
- For multi-turn conversations, extend the pattern by repeating
[INST] user [/INST] assistantblocks for Llama 2, or additional header-token blocks for Llama 3.
Where to use the formatted output
The formatted prompt is consumed directly by model runtimes that accept raw text input:
- llama.cpp — pass it via the
--promptflag or as the prompt field in the API - vLLM — use it as the
promptfield in a/v1/completionsrequest (not/v1/chat/completions, which applies the template automatically) - Ollama raw mode — send it as the
raw: trueprompt field to bypass Ollama’s own template layer - LM Studio — switch to raw mode in the playground and paste the formatted prompt directly
When using a chat completions API (including local servers that expose one), you normally supply the system and user message separately and let the server format them — the formatter is useful for systems that take raw text only.