Skip to content
mentoor

Topic 4 of 5 · 5 min read

Matching sampling settings to tasks

Goal: Choose sampling settings for extraction, brainstorming and code generation and justify each choice.

Pick sampling settings by asking one question: does this task have a right answer, or does it want many good options?

Check yourself · 1 of 3

Which task is best served by a temperature close to zero?

Choose one answer

Why it matters

The best setting for pulling dates out of invoices is the worst for naming a product. One default for everything wastes quality. A small match between task and setting is one of the cheapest improvements you can make.

A simple guide

  1. Tasks with one right answer (extraction, classification, data cleanup, math, short factual answers): use low temperature, near 0. You want the most likely reading, every time. Use a fixed output format as well.
  2. Code generation: low to moderate temperature. A little variety can help when you ask for several options, but a function that must compile and pass tests benefits from steady output. Verify with tests, not with the setting.
  3. Summaries and rewrites: low to moderate. You want faithful text that still reads naturally.
  4. Brainstorming, names, slogans, story ideas: moderate to high temperature, and ask for many items. Variety is the point here, so pick the best from a long list.
  5. Chat and general help: the provider's default is usually tuned for it. Leave it unless you have a reason.

Reasoning models

Many reasoning models, which think in a hidden step before answering, restrict or ignore these settings. Some fix temperature at one value, and some reject the parameter or ask you to leave it at its default. Rules differ by provider and by model, so read the API reference for your exact model before you tune. For these models, put your effort in the prompt, the reasoning-effort setting where one exists, and checks on the result.

Before and after

# Before: one setting for every job
CONFIG = {"temperature": 1.0}
# After: settings per task
SETTINGS = {
    "extract_invoice": {"temperature": 0},
    "write_unit_tests": {"temperature": 0.2},
    "summarize_ticket": {"temperature": 0.3},
    "name_ideas": {"temperature": 0.9},
}

The numbers are starting points, not rules. Try them and check the output.

What goes wrong

  • Using high temperature for extraction, so the same invoice gives different totals.
  • Using temperature 0 for brainstorming and receiving ten near-identical ideas.
  • Sending a temperature value to a reasoning model that rejects it, and getting an error.
  • Tuning sampling when the real problem is a weak prompt or missing context. Fix the prompt first.

Examples

Two jobs, two configs

# Extract: steady and exact
extract = dict(temperature=0, messages=[{"role": "user", "content": "Return the invoice date as YYYY-MM-DD only.\n\n" + text}])

# Brainstorm: varied, many options
ideas = dict(temperature=0.9, messages=[{"role": "user", "content": "Give 20 names for a plant-care app, one per line."}])

The first wants the same answer every time. The second wants twenty different ones.

A reasoning model rejects temperature

A team copies temperature=0.2 into a call to a reasoning model and gets an error saying the value is not supported. The fix is not a workaround. They remove the parameter, as the docs say, and move the effort to the prompt and the reasoning-effort setting.

Key points

  • Tasks with a single right answer, such as extraction and classification, work best at low temperature.
  • Brainstorming benefits from higher temperature and a request for many options.
  • Code generation usually wants low to moderate temperature, with tests as the real check.
  • Many reasoning models fix, limit or reject sampling settings, so read the docs for your exact model.
  • Sampling is a small adjustment; fix the prompt and context before tuning knobs.

Common mistakes

  • Using one temperature for every task.
  • Using temperature zero when you want many different ideas.
  • Passing sampling parameters to a model whose docs forbid them.
  • Tuning knobs to fix what is really a vague prompt.

Check yourself · 2 of 3

You send temperature 0.7 to a reasoning model and the API returns an error saying the value is not supported. What is the best response?

Choose one answer

Check yourself · 3 of 3

An extraction tool returns a different total for the same invoice on different runs. Which change comes first?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic