Gemma 4 / Prompting

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

<|turn>system<|think|> You are a careful analyst.<turn|> <|turn>user<|image|> What does this chart show?<turn|> <|turn>model The answer starts here
Every Gemma 4 prompt is a series of turns: system, user, then model.
1.0Temperature
0.95Top-p
64Top-k
<|think|>Switches thinking on
Before the prompt

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.

Temperature
1.0

How much variety the model allows itself. Many people lower this out of habit; Google's advice is to leave it at 1.0.

Top-p
0.95

Keeps the model choosing from the most likely 95% of options at each step.

Top-k
64

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.

The format

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.

Do not write these by hand if you can avoid it. A chat app, an OpenAI-style API or apply_chat_template() will produce the right tokens. Hand-typed tokens are an easy source of quiet errors.
TokenWhat 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.

Interactive

Prompt builder

Change the options and see the exact text the model receives. Nothing is sent anywhere; it all happens on this page.

What the model receives

      

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.

Reasoning

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 it

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.

Images, audio and video

Where each kind of input goes

The two placement rules run in opposite directions, which is easy to get wrong.

InputWhere to put itLimitsSizes
ImageBefore the textDetail level of 70, 140, 280, 560 or 1120 tokens; 280 is the defaultAll
AudioAfter the textUp to 30 seconds a clipE2B, E4B, 12B
VideoAs a series of framesUp to 60 seconds at one frame a secondAll

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.

Function calling

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_responses so 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 · released October 6, 2026
The search model

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.

What the model actually reads task: search result | query: how do I reset my router? 768 numbers title: none| text: Hold the reset button... documents get their own prefix
A query and a document each get a different prefix.
UsePrompt nameQuery becomesDocument becomes
Web searchSearchQuerytask: search result | query: {query}title: {title} | text: {content}
Question answeringQuestionAnsweringtask: question answering | query: {question}title: {title} | text: {passage}
Fact checkingFactCheckingtask: fact checking | query: {claim}title: {title} | text: {evidence}
Code searchCodeRetrievaltask: code retrieval | query: {query}title: {title or filename} | text: {code}
ClassificationClassificationtask: classification | query: {content}Same prompt for every item
ClusteringClusteringtask: clustering | query: {content}Same prompt for every item
SimilaritySentenceSimilaritytask: 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: none when 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.

Diagnosis

When a good prompt underperforms

Common causes worth checking first. This table is this site's guidance.

What you seeLikely causeTry this
Flat, repetitive answersSampling settings changedGo back to temperature 1.0, top-p 0.95, top-k 64
Careless maths or logicThinking is offSwitch thinking on
Slow replies to simple requestsThinking is onSwitch it off for simple tasks
Loses track in a long chatThe app's context setting is smaller than the conversationRaise the context length, or start a new chat with a summary
Reasoning goes in circles over many turnsOld thoughts left in the historyStrip earlier thoughts; keep only final answers
Misreads small print in imagesImage detail at the 280 defaultRaise it to 560 or 1120
Describes a tool call instead of making oneTools not passed through the chat templatePass tools to the template or API instead of pasting them as text
Audio ignored26B A4B or 31B in useUse E2B, E4B or 12B for audio
Search results feel random (EmbeddingGemma 2)Missing or mismatched task promptsUse 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.

FAQ

Prompting questions

More answers on the full FAQ page.

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.

Top '