Format a Gemma 4 chat prompt by hand

prompting & control tokens

// what it does

Gemma 4 wraps each message as <start_of_turn>{role}\n{content}<end_of_turn>, where role is user or model, and ends the prompt with <start_of_turn>model to cue a reply. There is no dedicated system role — put system instructions at the top of the first user turn. A single <bos> leads the sequence, and libraries like Transformers, llama.cpp, and vLLM apply all of this for you via apply_chat_template.

// gotcha

Adding a second <bos> (for example by prepending it and also letting the tokenizer add one) or using an assistant role instead of model breaks the format and degrades output. Prefer apply_chat_template over hand-rolling the tokens.

// resources