skip to content

What must a hand-built Gemma 4 prompt contain for the system role, turn markers and switching thinking on or off?

level: middleimportance: nice to knowfreq 26%

answer

  1. new control tokens, not Gemma 3's
  2. pipe placement differs open versus close
  3. three roles, system now native
  4. a switch token in the system turn
  5. old thoughts leave the history

basics

~20 s

A Gemma 4 prompt wraps every turn in <|turn> plus the role and <turn|>, uses the system, user and model roles, ends on an open model turn, and enables thinking with <|think|> at the start of the system prompt.

solid answer

~50 s

Gemma 4 replaced Gemma 3's `<start_of_turn>`/`<end_of_turn>` with new control tokens: each turn opens with `<|turn>`, the role name and a newline, and closes with `<turn|>`. The roles are `system`, `user` and `model`, and `system` is now native, so instructions no longer get folded into the first user turn. A generation prompt ends with an open `<|turn>model` line. Thinking is set per conversation: put `<|think|>` at the start of the system prompt to enable it, remove it to disable it. With thinking on, the reply starts with `<|channel>thought`, the reasoning and `<channel|>`, then the answer; with it off, every size except E2B and E4B still emits an empty thought block, so the parser must handle both. In history, drop earlier turns' thoughts, except inside a model turn that makes tool calls, where they must be kept.

code

plaintext · 5 lines
plaintext
<|turn>system
<|think|>You are a helpful assistant.<turn|>
<|turn>user
Hello.<turn|>
<|turn>model

go deeper

for a junior

Recall that Gemma 4 marks turns with its own control tokens, has three roles named system, user and model, and switches thinking with a token in the system prompt.

for a middle

Explain the exact shape: open with <|turn> and the role, close with <turn|>, end on an open model turn, and place <|think|> at the start of the system prompt to enable reasoning.

for a senior

Show you have handled output parsing: strip the thought channel, expect an empty one from the larger sizes with thinking off, and keep thoughts only within a tool-calling model turn.

for a principal

Weigh owning a hand-built template against a runtime's: every format change, as from Gemma 3 to Gemma 4, becomes a regression your team must catch, so pin tests to the exact token strings.

## Why the format matters A chat model sees one string of tokens. Roles, turn boundaries and switches such as thinking are encoded as **control tokens** the model was trained on, and a prompt built with the wrong ones reads to the model as unfamiliar text. Many runtimes apply a chat template for you, but a team whose runtime has none, or that builds prompts by hand for tests, must write **Gemma 4's** format exactly. Gemma 4 introduced new turn tokens, so a Gemma 3 template cannot be reused as it stands. ## Turns and roles - Each turn opens with `<|turn>`, then the role name and a newline, and closes with `<turn|>`. Mind the pipe: it sits **inside the bracket on the opening side** of `<|turn>` and **on the closing side** of `<turn|>`. - There are three roles: `system`, `user` and `model`. - **`system` is a native role in Gemma 4.** Instructions go in their own system turn instead of being folded into the first user turn. - To ask for a reply, end the prompt with an open model turn, `<|turn>model` and a newline, and let the model write that turn. The prompt-formatting page's own example of a system turn followed by a user turn: ``` <|turn>system You are a helpful assistant.<turn|> <|turn>user Hello.<turn|> ``` ## Switching thinking on and off Gemma 4's thinking is **configurable**, and the switch is designed to be set at the **conversation level**. 1. To enable it, put `<|think|>` at the start of the system prompt. 2. To disable it, remove `<|think|>`. 3. With thinking on, the model first writes a thought block: `<|channel>thought`, a newline, its reasoning, then `<channel|>`. The answer follows. 4. With thinking off, **every size except E2B and E4B still emits an empty thought block**: `<|channel>thought`, a newline and `<channel|>` with nothing between them. E2B and E4B emit none. The two shapes a reply can start with, thinking on and then the empty block a larger size emits with thinking off: ``` <|channel>thought [reasoning]<channel|> ``` ``` <|channel>thought <channel|> ``` The answer text follows `<channel|>` in both cases. Because the switch lives in the system prompt, it applies to the whole conversation rather than to a single message; a team that wants reasoning for some requests and not others decides that when it opens the conversation. A complete generation prompt with thinking enabled: ``` <|turn>system <|think|>You are a helpful assistant.<turn|> <|turn>user Hello.<turn|> <|turn>model ``` The code that shows the answer to a user must therefore strip a thought block when one is present, whether it holds reasoning or is empty, and must not assume one is always there. ## Thoughts in multi-turn history - **Do not send previous turns' thoughts back** before the next user turn: store each finished model turn as its answer, without the thought block. - **The exception is tool calls.** Within a model turn that makes tool calls, its thoughts must be kept while that turn continues through the tool responses. - Breaking either rule sends a history shaped differently from the one the format documents. ## The other control tokens Gemma 4's other control tokens use the same bracket-and-pipe style: - tools: `<|tool>` and `<tool|>`, `<|tool_call>` and `<tool_call|>`, `<|tool_response>` and `<tool_response|>`, with `<|"|>` as a string delimiter; - media: `<|image>` and `<image|>`, `<|audio>` and `<audio|>`, with `<|image|>` and `<|audio|>` as placeholders. The recommended sampling settings are temperature 1.0, top_p 0.95 and top_k 64. ## Contrast with Gemma 3 - Gemma 3 marked turns with `<start_of_turn>` and `<end_of_turn>`; Gemma 4 uses `<|turn>` and `<turn|>`. - Gemma 3 had only the `user` and `model` roles, so system instructions were folded into the first user turn; Gemma 4 has a native `system` role. - The `<|think|>` switch and the `<|channel>` thought block belong to Gemma 4's format, so a parser written for Gemma 3 output does not know to strip them. ## A checklist for a hand-built Gemma 4 template 1. Wrap every turn in `<|turn>` plus role and newline, and `<turn|>`. 2. Put instructions in a `system` turn, with `<|think|>` at its start only if thinking should be on for the conversation. 3. End the prompt with an open `<|turn>model` line. 4. Strip the thought block from the reply, expecting an empty one from the larger sizes when thinking is off. 5. Leave earlier thoughts out of history, except within a tool-calling model turn.

  • Why must a Gemma 4 output parser cope with an empty thought block even when thinking is disabled?
    With `<|think|>` removed, the 12B Unified, 26B A4B and 31B Dense sizes still emit `<|channel>thought`, a newline and `<channel|>` before the answer; only E2B and E4B omit it. A parser that assumes no block when thinking is off would show control tokens to the user or misplace where the answer starts.
  • When must earlier thoughts stay in a Gemma 4 conversation history?
    Only within a model turn that makes tool calls: its thoughts must be kept while that turn continues through the tool responses. Once the next user turn begins, previous turns' thoughts must not be sent back, so store each finished model turn as its answer alone.
  • Can you flip Gemma 4's thinking switch on one message in the middle of a conversation?
    The switch is designed to be set at conversation level: `<|think|>` sits at the start of the system prompt, which frames the whole conversation. Flipping it turn by turn is outside what the format documents, so decide per conversation and keep the system prompt stable.

  • Gemma 4 still marks turns with start_of_turn and end_of_turn like Gemma 3.
  • Gemma 4 has no system role, so instructions go in the first user turn.
  • Gemma 4 thinking is enabled by a sampling parameter, not a prompt token.
  • With thinking off, no Gemma 4 size emits any thought block.
  • Every earlier turn's thoughts should be resent so the model keeps its reasoning.
  • Gemma 4 opens a turn with <turn|> and closes it with <|turn>.

Assumes Gemma 4's format as documented on its model card and prompt-formatting page; Gemma 3 used <start_of_turn> and <end_of_turn> with no system role, so its templates do not carry over.