Lesson 4 of 30
Temperature controls how predictable versus varied a model's output feels, by reshaping the probability distribution it samples the next token from — and it's the first knob to reach for when output feels too rigid or too erratic.
10 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
You're building an endpoint that extracts a fixed JSON shape from user input and needs consistent, parseable output every time. What temperature setting fits best, and why?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
At every step of generating a response, a model computes a probability distribution over what the next token could be — some tokens are far more likely than others given everything so far. Temperature controls how that distribution gets used to actually pick a token.
Two related parameters constrain which tokens are even eligible to be sampled, independent of temperature:
p (e.g. the top 90% of probability mass), cutting off the long tail of unlikely tokens entirely.k most likely tokens, a simpler fixed-count cutoff.These aren't mutually exclusive with temperature — an API call can set temperature and top-p and top-k together, each narrowing the pool or reshaping it in a different way.
// A structured-extraction endpoint: pulling a fixed JSON shape out of user input.
// Reliability matters far more than variety — low temperature.
const extractionParams = { temperature: 0.1 };
// A brainstorming endpoint: generating varied marketing headline ideas.
// Variety is the actual goal here — higher temperature is appropriate.
const brainstormParams = { temperature: 0.9, top_p: 0.95 };
The extraction endpoint benefits from the model reliably picking its most-confident token at every step, because the output needs to parse as valid, predictable JSON every time. The brainstorming endpoint benefits from the opposite: sampling more broadly is the entire point, since a handful of near-identical "safe" headlines would defeat the purpose of asking for options.
"You're building a feature that extracts structured data versus one that brainstorms ideas — how would you configure sampling differently for each?" tests whether a candidate understands temperature as a real engineering lever tied to the task's actual requirements, not a vague "creativity slider."