System prompts, temperature and other settings
LLM Fundamentals & Prompting · 10 questions
Short notes
Key idea
The system instruction sets the model's role and rules for the whole conversation. Settings like temperature control how it picks tokens: low for consistent answers, higher for variety.
Syntax
from google.genai import types
config = types.GenerateContentConfig(
system_instruction="You are a support assistant for an online shop. Be brief.",
temperature=0.2,
max_output_tokens=300,
)
r = client.models.generate_content(model=MODEL, contents=question, config=config)
- Temperature: 0 ≈ most likely token each time; higher spreads the choice.
- top_p / top_k: limit the choice to the most likely tokens.
- max_output_tokens: caps reply length (and cost); a cut-off reply is incomplete.
- stop sequences: end the reply at a marker.
Example
Extracting an order number: temperature 0, so the same input gives the same output. Writing five ad headlines: temperature 1, for variety.
Traps
- Temperature 0 isn't fully deterministic on every provider; don't rely on identical output.
- A system prompt isn't a security boundary; users can try to talk the model out of it.
- Too small
max_output_tokenscuts answers mid-sentence; check the finish reason. - Change one setting at a time when testing.
Want the full lesson with step-by-step examples, a project and a certificate? LLM Fundamentals & Prompting course, ₹180 →
- Question 1easy
"Never ask customers for OTPs or PINs." Where should this rule go?
- Question 2easy
What happens when you lower the temperature towards 0?
- Question 3medium
What does this print?
def apply_temperature(probs, t): w = {k: p ** (1 / t) for k, p in probs.items()} total = sum(w.values()) return {k: round(v / total, 2) for k, v in w.items()} print(apply_temperature({"yes": 0.6, "no": 0.4}, 1.0)) - Question 4medium
You're extracting order ids and categories from tickets into a database. Which temperature?
- Question 5hard
Your system instruction says "Never offer discounts", but a user talks the model into offering one. What's the real fix?
System prompts, temperature and other settings
System prompts, temperature and other settings
System prompts, temperature and other settings
System prompts, temperature and other settings
System prompts, temperature and other settings
5 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.