Skip to content
mentoor

Topic 3 of 5 · 5 min read

Getting repeatable model outputs

Goal: Configure a call to be as repeatable as the provider allows and explain why temperature zero can still vary.

You can make output more repeatable, but no major provider promises identical text every time, even at temperature zero.

Check yourself · 1 of 3

Why can a request at temperature zero still return different text on different runs?

Choose one answer

Why it matters

Repeatable output matters when you test a prompt, run a daily report, or compare two models. If results shift on their own, you cannot tell a real change from noise. So aim for "as steady as the provider allows" and design the rest of your work to survive small differences.

Why temperature zero is not enough

At temperature zero the model takes the top token each time. That sounds fixed. But two tokens can be nearly tied, and the server's math can differ slightly between runs. The order of adding numbers changes with batch size and load, and tiny differences can flip a near tie. One flip changes all later text. Researchers have traced much of this to how servers batch requests together (see the Thinking Machines article). Providers also say so: OpenAI describes its seed option as best effort.

What you can do

  1. Lower the randomness. Set temperature to 0 or close to it for tasks that need steady answers.
  2. Pass a seed where the API has one. A seed fixes the random draw, so the same seed plus the same input gives mostly the same output. Log the seed you used. Check whether the response returns a system fingerprint or similar field. If that value changes, the server setup changed and the output may too.
  3. Pin the model version. Use a dated model name, not a moving alias, so an update cannot change results silently.
  4. Constrain the output. Ask for a fixed shape: a JSON schema, a list of allowed labels, a single word. Structured outputs leave fewer places for wording to wander.
  5. Cache what you need to reuse. If you need the same answer later, store it. Do not regenerate it and hope.
  6. Keep the input identical. Same prompt text, same order of tools and examples, same context.

Before and after

# Before: moving alias, default randomness
resp = client.chat.completions.create(
    model="gpt-latest",
    messages=msgs,
)
# After: pinned version, low randomness, seed, fixed shape
resp = client.chat.completions.create(
    model="example-model-2026-01-15",
    temperature=0,
    seed=1234,
    response_format={"type": "json_object"},
    messages=msgs,
)
print(resp.system_fingerprint)  # log it with the result

The model name above is a placeholder. Use a real dated name from your provider.

What goes wrong

  • Trusting temperature 0 as a guarantee and writing tests that need exact text.
  • Using a seed on a provider or model that ignores it.
  • Forgetting to log model, seed and settings, so a past result cannot be explained.
  • Testing exact strings when you should test the parsed fields or a pass/fail check.

Examples

A repeatable classification call

resp = client.chat.completions.create(
    model="example-model-2026-01-15",
    temperature=0,
    seed=7,
    messages=[{"role": "user", "content": "Label this ticket: billing, bug or other. Reply with one word.\n\n" + ticket}],
)
label = resp.choices[0].message.content.strip()
assert label in {"billing", "bug", "other"}

The fixed label list and the check mean a small wording change cannot break the pipeline.

Test the fields, not the prose

A test that compares a whole paragraph will fail on harmless wording changes. Parse the JSON reply and test the fields: is total a number, does status equal paid? These checks pass across reruns that differ in wording.

Key points

  • Temperature zero removes sampling randomness but does not remove all variation, because server math can differ slightly between runs.
  • A seed makes repeats more likely where it is supported, but providers describe it as best effort.
  • Pinned, dated model names stop silent updates from changing results.
  • Structured outputs and fixed label lists leave less room for wording to change.
  • Log the model, seed, settings and any system fingerprint with each result so you can explain it later.

Common mistakes

  • Treating temperature zero as a promise of identical text.
  • Calling a moving model alias in a pipeline that needs stable output.
  • Writing tests that match exact prose.
  • Setting a seed and not saving it or the model name.

Check yourself · 2 of 3

A nightly job must give the steadiest results the provider allows. Which setup is best?

Choose one answer

Check yourself · 3 of 3

Which test is most robust for a model that returns an invoice summary as JSON?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic