Topic 3
A chat is one token sequence
A chat template turns the list of messages into the one sequence the model reads. Each model has its own, set by its developers and documented with the model (AI Engineering, Ch. 5, "System Prompt and User Prompt").
Llama 3's, from Meta's reference code (ChatFormat in the llama3 repository, fetched 2026-10-21):
<|begin_of_text|>once.- Per message:
<|start_header_id|>, the role,<|end_header_id|>, a blank line, the content,<|eot_id|>. - An empty assistant header at the end, so the model's most likely continuation is a reply.
Meta's prompt-format page adds: "Newlines (0x0A) are part of the prompt format". Each <|…|> marker is one special token.
Predict first
From messages to one token sequence
Llama 3 chat template · deterministic, no model runs
The string the model is trained on (↵ is a newline)
<|begin_of_text|><|start_header_id|>system<|end_header_id|>↵ ↵ Translate the text below into French<|eot_id|><|start_header_id|>user<|end_header_id|>↵ ↵ How are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>↵ ↵
Loading the tokenizer…
Edit the messages and watch the string and the tokens. The counts use cl100k_base for text: Llama 3's tokenizer splits text with the same pattern but has its own merges, so treat counts as close, not exact. The markers are exact: one token each.
The book's advice holds for any model: "print out the final prompt to double-check if it follows the expected template." This lab is that printout.
Quick check