C.W.K.
Stream
Lesson 06 of 06 · published

Generation Parameters & Safety

~14 min · temperature, thinking, safety, controls

Level 0Spark
0 XP0/35 lessons0/10 achievements
0/140 XP to next level140 XP to go0% complete

The knobs that change every reply

Six parameters control most of what changes between two otherwise-identical Gemini calls:

  • temperature (0.0–2.0) — randomness. 0 is near-deterministic; 1.0 is the balanced default; > 1 is creative-but-weird.
  • topP (0.0–1.0) — nucleus sampling. Restrict to tokens making up p of the probability mass.
  • topK (1–100+) — only consider the top-K candidate tokens.
  • maxOutputTokens — hard cap. Hitting it triggers finishReason: MAX_TOKENS.
  • responseMimeTypetext/plain by default; switch to application/json for JSON mode.
  • seed — pin the random seed for reproducible runs (best-effort, not a guarantee on Pro).

Thinking config — the new lever

Gemini 2.5 introduced explicit thinkingConfig. The model can spend extra compute thinking before answering, and you pay for those thinking tokens at output rates. Choose the level deliberately:

  • MINIMAL — no extended thinking. Cheapest, fastest, fine for chat and simple Q&A.
  • LOW — small budget. Useful for moderately tricky reasoning.
  • MEDIUM — default for hard problems.
  • HIGH — long-form reasoning, complex code, multi-step math. Spend this only when you mean to.

Safety settings

Four harm categories with five threshold levels each. Defaults in Gemini 2.5+ are OFF — the model does not block by default; you opt in to filtering.

CategoryWhat it covers
HARM_CATEGORY_HARASSMENTTargeted identity attacks
HARM_CATEGORY_HATE_SPEECHSlurs, profanity directed at groups
HARM_CATEGORY_SEXUALLY_EXPLICITSexual content
HARM_CATEGORY_DANGEROUS_CONTENTInstructions for harmful acts

Thresholds: OFF, BLOCK_NONE, BLOCK_ONLY_HIGH, BLOCK_MEDIUM_AND_ABOVE, BLOCK_LOW_AND_ABOVE. The difference between OFF and BLOCK_NONE: OFF disables the classifier entirely; BLOCK_NONE still classifies but never blocks.

Code

Generation params in Python·python
from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents='Write a 3-sentence product description for a $40 espresso scale.',
    config=types.GenerateContentConfig(
        system_instruction='You are a professional copywriter.',
        temperature=0.4,
        top_p=0.95,
        top_k=40,
        max_output_tokens=300,
        seed=42,
        # Thinking budget — opt in for hard problems
        thinking_config=types.ThinkingConfig(thinking_level='LOW'),
    ),
)
print(response.text)
Tighten safety on a kid-facing app·python
config = types.GenerateContentConfig(
    safety_settings=[
        types.SafetySetting(
            category=types.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
            threshold=types.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
        ),
        types.SafetySetting(
            category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
            threshold=types.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
        ),
        types.SafetySetting(
            category=types.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
            threshold=types.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
        ),
    ],
)

External links

Exercise

Run the same prompt three times: once with temperature 0.0 (and a fixed seed), once with 0.7, and once with 1.5. Compare outputs. Then enable thinking_config: MEDIUM on a moderately hard logic puzzle (something like "Three people split a $30 dinner; each pays $10. The waiter realizes it should be $25 and returns $5..."). Compare the thinking-on vs thinking-off answers. Write 2–3 sentences on what you noticed.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.