Skip to content
mentoor

Topic 1 of 4 · 4 min read

Why the same prompt gives different answers

Goal: Name the source of variation behind a changed output: sampling, batching, a model update or tool state.

An LLM feature is a pipeline with several sources of variation, and a test that fails once tells you nothing until you know which source moved. Sending the same prompt twice can return two different answers. That is normal behaviour, not a bug.

Check yourself · 1 of 3

A support bot gives two differently worded but correct answers to the same question at temperature 0.8. What is the most likely source?

Choose one answer

Why it matters

If you cannot name the source, you fix the wrong thing. Teams pin a temperature when the real cause was a silent model update, or blame the model when a tool returned different data.

The four sources

  1. Sampling. The model produces a probability for each next token and then picks one. With a temperature above zero, the pick is random on purpose, so two runs diverge. One different early word changes everything after it.
  2. Serving and batching. Even with sampling turned off, the provider runs your request alongside others. Batch size changes the order of floating-point additions, and that can flip a close choice between two tokens. The Thinking Machines write-up traces temperature-0 variation to this effect.
  3. Model changes. A floating alias such as a "latest" model name can point to new weights next month. Providers also retire dated versions. Your prompt did not change, but the system answering it did.
  4. Everything around the model. Retrieved documents, tool results, the current date, a database row, a web search. If the input changes, the output changes, and the model is behaving correctly.

How to find the source

Replay the exact request: same model string, same parameters, same retrieved context, saved from the failing run. If the replay varies by itself, it is sampling or serving. If it is stable on the saved input, the input moved. If it is stable today but differed last week with an alias model name, suspect an update. Log the model string, parameters and full prompt with every call so you can do this.

Before and after

Before: a test asserts that a support bot reply equals a stored string. It passes Monday and fails Tuesday. Someone adds temperature=0 and moves on. It still fails on Thursday because the retrieval step now returns a newer help article.

After: the failing request is saved with its retrieved context. Replaying it five times gives five similar replies, so the model is steady. The context changed, which is the real finding.

What goes wrong

  • Treating variation as a defect to remove. Some variation is the cost of useful, flexible output. The goal is to measure it, not hide it.
  • Blaming the model for input changes. Retrieval, tools and clocks are often the larger source.
  • Pinning nothing. Using an alias model name in a regression suite means the baseline moves under you.
  • Not logging. Without the full request, a one-off failure cannot be reproduced and gets dismissed.

Examples

A reply that changed on Tuesday

A refund bot answered "30 days" on Monday and "within 30 days of delivery" on Tuesday. The saved request, replayed five times, gives both phrasings. That is sampling: the meaning is the same and the wording differs. A string-equality test would flag it as a failure.

The retrieval that moved

{"model": "gpt-example-2026-03-01", "temperature": 0, "context_ids": ["kb-114", "kb-207"]}

The failing run has kb-207; the passing run had kb-198. Same model, same settings, different retrieved article. The fix is in the retriever or the index, not in the prompt.

Key points

  • The same prompt can legitimately return different outputs; variation is a property to measure, not a bug to remove.
  • Sampling, serving-side batching, model updates and changing input context are four separate sources.
  • Replaying a saved request tells you whether the variation comes from the model or from the input.
  • Use dated model versions in regression suites, because floating aliases change underneath you.
  • Log the model string, parameters and full prompt with every call so failures can be reproduced.

Common mistakes

  • Assuming a changed output means the prompt or code changed.
  • Adding temperature 0 and treating the problem as solved.
  • Running the suite against a floating model alias.
  • Not recording the retrieved context or tool results with the output.

Check yourself · 2 of 3

A test passes for a month and then fails with no code change. The suite calls a model alias that ends in "latest". What should you check first?

Choose one answer

Check yourself · 3 of 3

You replay a failing request five times with the saved prompt, model string and retrieved context, and all five replies are the same. Where does the original variation most likely come from?

Choose one answer

Practice items, not counted towards your mastery.

Start here