liveBook · Manning

Temperature

As explained in Building Reliable AI Systems

Temperature is a language-model generation parameter that controls the randomness of token selection.

Temperature controls how much randomness enters token selection during language-model generation. Lower values favor higher-probability tokens, making responses more predictable and reproducible. Higher values increase variation and can make responses more conversational. For a production chatbot, choose it according to the task: a policy answer needs a different level of variation from a creative list. section 2.2.1 section 2.2

The same question, two styles

Asked for iPhone 14 specifications, a chatbot at temperature 0.3 gives a concise list of the display, chip, cameras, and storage options. At 0.8, it gives a longer, more enthusiastic answer about the same features. The change is in the response’s predictability and style—not proof that either answer is correct. section 2.2.1

Set temperature with the task and provider in mind:

  • Start around 0.5, then adjust toward specificity or creativity. Review the resulting answers rather than assuming a setting guarantees accuracy. section 2.9 section 2.2.1
  • Check the model’s supported range. GPT-4.1 supports 0–2 and Claude Sonnet 4.6 supports 0–1; the cited reasoning-focused models do not support temperature. section 2.2.1
  • For answers based on retrieved documents, pair a low temperature with retrieval, a prompt restricting answers to the supplied context, and source information. Low temperature alone does not ground an answer. section 4.5.4 section 2.2.1
import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    temperature=0.3,  # Claude uses 0-1 range
    messages=[
        {"role": "user", "content": "What are 10 unique things to do at the
        grocery store?"}
    ]
)
print(response.content[0].text)

This Claude API call sets temperature to 0.3 within the provider’s 0–1 range for a grocery-store ideas prompt. section 2.2.1

Do not equate temperature zero with factual reliability. A predictable answer can be consistently wrong, and setting temperature to zero does not reliably reduce hallucinations. When facts must be grounded, use techniques such as retrieval-augmented generation or tool use alongside sampling choices. section 2.2.1

How Building Reliable AI Systems covers it

How deep it goes
Explains the next-token effect, compares settings, and gives API examples, but does not derive the probability adjustment mathematically.
Examples
Compares iPhone specification answers at 0.3 and 0.8 and configures temperature in grocery-store idea prompts.
What it assumes
Assumes familiarity with prompts and API calls while defining temperature through its effect on next-token selection.
What you can do after
Operate/configure it through supported model APIs and evaluate the predictability–variety trade-off without treating determinism as correctness.
How it connects
Connects temperature to top-p sampling, prompt engineering, hallucinations, retrieval-augmented generation, and tool use.

Also explained in

Compare how 17 books explain temperature →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.