Gemma 4 Prompt Guide
How to write prompts Gemma 4 handles well: the settings Google recommends, the turn format, when to switch thinking on, where images and audio go, and how tools are declared. It also covers the short task prompts EmbeddingGemma 2 needs for search.
Checked against Google's documentation on October 7, 2026
Start with Google's three settings
Google's model card recommends one sampling configuration "across all use cases". Set it before you change anything else.
How much variety the model allows itself. Many people lower this out of habit; Google's advice is to leave it at 1.0.
Keeps the model choosing from the most likely 95% of options at each step.
Limits each step to the 64 most likely next tokens.
From Google's Gemma 4 model card: temperature=1.0, top_p=0.95, top_k=64. Apps such as Ollama and LM Studio let you set these; check them if answers seem flat or repetitive.
What a Gemma 4 prompt looks like
Most apps build this for you. It helps to know the shape when something goes wrong, or when you are working with the raw model.
<|turn>system You are a helpful assistant.<turn|> <|turn>user Hello.<turn|> <|turn>model
The prompt ends with an open model turn; the model writes its answer there. Gemma 4 has a real system role, and its reply role is called model.
apply_chat_template() will produce the right tokens. Hand-typed tokens are an easy source of quiet errors.| Token | What it does |
|---|---|
<|turn> <turn|> | Open and close each turn. The role name follows the opening token: system, user or model. |
<|think|> | Placed at the start of the system turn, it switches thinking on. |
<|channel>thought <channel|> | Wrap the model's reasoning, before its answer. |
<|image|> <|audio|> | Mark where an image or audio clip belongs in the text. |
<|tool> <tool|> | Declare a tool the model may use. |
<|tool_call> <tool_call|> | The model asking for a tool to be run. |
<|tool_response> <tool_response|> | The result you send back. |
<|"|> | Wraps every text value inside tool blocks, in place of quotation marks. |
From Google's Gemma 4 prompt formatting guide. These tokens are new in Gemma 4; Gemma 3 used a different set, so old templates do not carry over.
Prompt builder
Change the options and see the exact text the model receives. Nothing is sent anywhere; it all happens on this page.
The image goes before your text and audio after it, following Google's guidance. The tool shown is modelled on the weather example in Google's documentation; in real use, let the chat template write it. To try prompts against a real model, use the playground or chat page.
Switching thinking on and off
With thinking on, the model reasons step by step before it answers. That helps on hard problems and costs time on easy ones.
<|turn>system <|think|><turn|> <|turn>user What is the water formula?<turn|> <|turn>model <|channel>thought ... <channel|>The most common interpretation of "the water formula" refers...<turn|>
text = processor.apply_chat_template(
message,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True, # False for fast replies
)from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemma-4-26b-a4b-it",
contents="What is the water formula?",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_level="high") # or "minimal"
),
)
print(response.text)# inside an Ollama chat /set think # reason before answering /set nothink # answer straight away # in the Ollama API, add this field to the request "think": false
The raw form is from Google's prompt formatting guide: <|think|> at the start of the system turn, with the reasoning returned between <|channel>thought and <channel|>.
Turn it on for
Maths, code, planning, multi-step questions and deciding which tool to call.
Turn it off for
Sorting, tagging, pulling out fields, quick chat and high-volume jobs.
- Remove old reasoning. Google: strip the model's thoughts from a turn before sending the conversation back for the next one. Keep only the final answer.
- Except during tool calls. Within a single model turn that calls tools, the thoughts must stay in place between the calls.
- Expect an empty block sometimes. With thinking off, the model may still produce an empty thought block. Strip it like any other.
- You can ask for less. Google notes a system instruction asking for low thinking cut thinking tokens by roughly 20% in its test, and calls this a proof of concept.
Which uses are "on" or "off" is this site's guidance. On hosted APIs, thinking is billed as output; see pricing. More on what thinking does is under capabilities.
Writing the prompt itself
General prompt-writing practice that works well with Gemma 4. This section is this site's guidance, not Google's.
Say what you want back
Name the format, the length and the audience. "Five bullets for a manager" beats "summarise this".
Show two or three examples
A few worked pairs of input and output steer style better than a paragraph of description.
Separate your material
Put pasted text inside clear markers such as triple quotes, so instructions and content cannot be confused.
Supply recent facts
The training data stops at January 2025. Paste in anything newer that the answer depends on.
Templates to copy
Extract every invoice from the text below.
Return only JSON: a list of objects with the keys
"number", "date" (YYYY-MM-DD) and "total" (a number).
If a value is missing, use null. Do not add commentary.
Text:
"""
{paste the text here}
"""Summarise the report below for a busy manager.
- At most five bullet points
- Plain language, no jargon
- End with one line starting "Decision needed:"
Report:
"""
{paste the report here}
"""Classify the customer message as one of:
billing, technical, delivery, other.
Reply with the label only.
Message: "My parcel still has not arrived."
Label: delivery
Message: "I was charged twice this month."
Label: billing
Message: "{new message}"
Label:You are reviewing a Python function.
1. Say what it does in one sentence.
2. List any bugs, most serious first.
3. Show the corrected function in one code block.
Change nothing that is not a bug.
```python
{paste the function here}
```Replace the parts in curly brackets. Gemma 4 31B scores 98.9 on IFEval, a test of instruction following, so clear instructions are usually obeyed; smaller sizes are less reliable - see benchmarks and limitations. Coding prompts are covered in more depth on the coding page.
Where each kind of input goes
The two placement rules run in opposite directions, which is easy to get wrong.
| Input | Where to put it | Limits | Sizes |
|---|---|---|---|
| Image | Before the text | Detail level of 70, 140, 280, 560 or 1120 tokens; 280 is the default | All |
| Audio | After the text | Up to 30 seconds a clip | E2B, E4B, 12B |
| Video | As a series of frames | Up to 60 seconds at one frame a second | All |
Google's audio prompts
# speech to text Transcribe the following speech segment in {LANGUAGE} into {LANGUAGE} text. # speech translation Transcribe the following speech segment in {SOURCE_LANGUAGE}, then translate it into {TARGET_LANGUAGE}.
Wording from the model card. Fill in the language names.
Low detail: 70 or 140
Enough for sorting images, short captions and video frames. Faster and cheaper.
High detail: 560 or 1120
For small print: scanned documents, screenshots, charts and tables.
Placement and detail levels are from Google's model card. Which sizes accept which inputs is on the model variants page; phone use is under Android.
Tools use their own format, not JSON
You describe a tool, the model asks for it to be run, your code runs it and sends the result back. The model never runs anything itself.
<|turn>system
<|think|>You are a helpful assistant.<|tool>declaration:get_current_temperature{...}<tool|><turn|>
<|turn>user
What's the temperature in London?<turn|>
<|turn>model
<|channel>thought
...
<channel|><|tool_call>call:get_current_temperature{location:<|"|>London<|"|>}<tool_call|># let the template write the tool block for you text = processor.apply_chat_template( message, tools=tools, tokenize=False, add_generation_prompt=True, enable_thinking=True, ) # after running the function yourself, hand the result back "tool_responses": [{"name": function_name, "response": function_response}]
In the raw form, text values sit between <|"|> markers instead of quotation marks. Passing tools= to the chat template writes all of this for you.
- Describe tools plainly. You can pass a JSON schema or a Python function; Google recommends Google-style docstrings so the description is picked up.
- Check before you run. Google's guide says to validate the function name and arguments, and to map names to functions explicitly.
- Send results in the expected shape. Return them as
tool_responsesso the template formats them correctly. - Write schemas by hand for complex inputs. Automatic conversion can oversimplify nested or custom types.
From Google's function calling guide and prompt formatting guide. Hosted and OpenAI-style endpoints accept ordinary JSON tool definitions and translate them; see the API page and features.
EmbeddingGemma 2 prompts
EmbeddingGemma 2 does not chat, so there is no conversation to write. Instead, each piece of text gets a short task prompt in front of it that tells the model what the text is for. Using the right one is the main thing to get right.
| Use | Prompt name | Query becomes | Document becomes |
|---|---|---|---|
| Web search | SearchQuery | task: search result | query: {query} | title: {title} | text: {content} |
| Question answering | QuestionAnswering | task: question answering | query: {question} | title: {title} | text: {passage} |
| Fact checking | FactChecking | task: fact checking | query: {claim} | title: {title} | text: {evidence} |
| Code search | CodeRetrieval | task: code retrieval | query: {query} | title: {title or filename} | text: {code} |
| Classification | Classification | task: classification | query: {content} | Same prompt for every item |
| Clustering | Clustering | task: clustering | query: {content} | Same prompt for every item |
| Similarity | SentenceSimilarity | task: sentence similarity | query: {content} | Same prompt for every item |
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("google/embeddinggemma-2")
# queries and documents get different prompts
query_emb = model.encode(query, prompt_name="SearchQuery")
doc_emb = model.encode(document, prompt_name="Document")# what the prompts expand to
task: search result | query: how do I reset my router?
title: Router manual | text: Hold the reset button for ten seconds...
title: none | text: A passage that has no title.# images, audio and video take no task prompt
image_emb = model.encode({"image": "sunset_beach.jpg"})
audio_emb = model.encode({"audio": "ocean_waves.wav"})# mixed input: placeholders mark where each file belongs
listing_emb = model.encode({
"text": "Waterproof trail shoe. <|image|> Grip test: <|video|>",
"image": "trail_shoe.jpg",
"video": "grip_test.mp4",
})Code from Google's developer guide; prompt strings from the EmbeddingGemma 2 model card.
- Queries and documents differ. For search, question answering, fact checking and code search, encode the question with the task prompt and the stored text with
Document. - Use
title: nonewhen a document has no title. - Media takes no prompt. Images, audio and video are passed on their own, with no task prefix.
- Be consistent. Index and search with the same choices, or results will be poor. If you change prompts, index again.
- Other tools may not add them. Libraries outside sentence-transformers may expect you to add the prefix text yourself; check before trusting the results.
The last two points are this site's guidance. Setup is in how to use and the install guide; storage cost by vector length is on the pricing page.
When a good prompt underperforms
Common causes worth checking first. This table is this site's guidance.
| What you see | Likely cause | Try this |
|---|---|---|
| Flat, repetitive answers | Sampling settings changed | Go back to temperature 1.0, top-p 0.95, top-k 64 |
| Careless maths or logic | Thinking is off | Switch thinking on |
| Slow replies to simple requests | Thinking is on | Switch it off for simple tasks |
| Loses track in a long chat | The app's context setting is smaller than the conversation | Raise the context length, or start a new chat with a summary |
| Reasoning goes in circles over many turns | Old thoughts left in the history | Strip earlier thoughts; keep only final answers |
| Misreads small print in images | Image detail at the 280 default | Raise it to 560 or 1120 |
| Describes a tool call instead of making one | Tools not passed through the chat template | Pass tools to the template or API instead of pasting them as text |
| Audio ignored | 26B A4B or 31B in use | Use E2B, E4B or 12B for audio |
| Search results feel random (EmbeddingGemma 2) | Missing or mismatched task prompts | Use the query prompt for questions and Document for stored text |
Picking the right size and runtime matters as much as the prompt: see the runtime selector, the VRAM guide and model comparison.
What settings should I use with Gemma 4?
Google recommends temperature 1.0, top-p 0.95 and top-k 64 for all uses.
Does Gemma 4 support a system prompt?
Yes. It has a real system turn, which is also where the thinking switch and tool declarations go.
How do I turn thinking on?
Put <|think|> at the start of the system turn, or use your tool's switch: enable_thinking=True in Transformers, thinking_level in Google's API, /set think in Ollama.
Do I need to type the control tokens myself?
Usually not. Chat apps, APIs and apply_chat_template() add them. You only need them when sending raw text to the model.
Should the image go before or after my question?
Before. Audio is the opposite: put it after the text.
Will my Gemma 3 prompts work?
The wording will, but the control tokens changed. Let the Gemma 4 chat template rebuild the format rather than reusing an old one.
Does EmbeddingGemma 2 need prompts?
Yes, short task prompts for text and code, such as SearchQuery and Document. Images, audio and video take none.
Can prompts make the model safe or always correct?
No. Prompts steer behaviour but do not guarantee it. See safety and limitations.
Try your prompt against a real model
Run Gemma 4 on your own machine and test prompts in the browser.