Guides

Non-Deterministic LLM Prompts in 2026: Temperature, Sampling, Seeds, and How to Make Outputs Reproducible

Why LLMs return different answers to the same prompt in 2026, how temperature and top-p actually work, and the four reproducibility levers that matter.

·
Updated
·
8 min read
evaluations llms rag
Non-deterministic LLM prompts in 2026: temperature, sampling, seeds, reproducibility.
Table of Contents

Non-deterministic LLM prompts in 2026: TL;DR

LeverWhat it changesWhen to use
TemperatureSharpens (low) or flattens (high) the next-token distributionSet to 0 for tasks needing consistency; 0.7 to 1.0 for creative tasks
Top-kKeeps the K highest-probability tokens, drops the long tailUse to bound rare-token risk; common K is 40 to 100
Top-p (nucleus)Keeps the smallest set of tokens with cumulative probability ≥ pDefault sampler in most APIs; common p is 0.9 to 0.95
Seed + system_fingerprintPins the random seed and the backend versionUse for evaluation reproducibility; not bitwise guaranteed
Pinned model versionLocks the model snapshot (no “latest”)Always pin in production and in eval datasets
N-rollout evaluationRuns each prompt N times and reports mean + varianceThe only honest way to score non-deterministic systems

Non-determinism is not a defect; it is the consequence of probabilistic decoding plus hardware-level non-associativity. In 2026 the working answer is to bound variance with temperature, seed, and version pinning, and to design your evaluation to tolerate semantic equivalence rather than byte-exact match.

Why LLMs are non-deterministic in the first place

A language model assigns a probability to every possible next token given the context. A decoder picks one. The math at each step is:

  1. Forward pass produces logits (raw scores) for every token in the vocabulary.
  2. Temperature divides logits by T.
  3. Softmax converts logits to probabilities.
  4. Optional top-k or top-p truncation.
  5. The decoder samples one token from the resulting distribution.
  6. The token is appended to the context and the loop continues.

Even at temperature=0 (where step 5 becomes argmax), step 1 is not bitwise-deterministic on real hardware. GPU kernels often sum floating-point values in parallel and floating-point addition is not associative, so the order of summation can change the last bits of the logits. In tight contests between two top tokens, this can flip the argmax. In production, additional non-determinism comes from:

  • Batch composition. Two requests batched differently change the kernel’s reduction order.
  • Datacenter routing. The same API call may land on a different GPU type.
  • MoE routing. Mixture-of-experts models route tokens to different experts based on batch context.
  • Speculative decoding and continuous batching in vLLM and TGI introduce additional non-determinism.

This is why temperature=0 alone is not enough. You also want seed + system_fingerprint pinning + pinned model version + a tolerant evaluator.

Sampling parameters, properly explained

Temperature

Temperature T divides each logit by T before softmax. The effect:

  • T=0: argmax. The highest-probability token wins. Deterministic on paper.
  • T=0.7 to 1.0: typical for chat and content generation. Some randomness, mostly stays on high-probability tokens.
  • T>1: flattens the distribution. More creative and more chaotic.

Formula (for token i, logit z_i):

p_i = exp(z_i / T) / sum_j exp(z_j / T)

As T -> 0, the distribution becomes a one-hot at the argmax token. As T -> infinity, it approaches uniform.

Top-k

Top-k truncates the distribution to the K highest-probability tokens, then renormalizes. Typical K values are 40 to 100. Lower K reduces diversity and the risk of rare-token hallucinations; higher K allows more variety.

Top-p (nucleus)

Top-p keeps the smallest set of tokens whose cumulative probability is at least p, then renormalizes. Typical p values are 0.9 to 0.95. Unlike top-k, top-p adapts to how peaky or flat the distribution is at each step.

Combining

Production APIs typically expose temperature and top_p (and sometimes top_k). The pragmatic defaults:

  • Determinism-leaning workloads: temperature=0, top_p=1, seed pinned, model version pinned.
  • Balanced chat: temperature=0.7, top_p=0.95.
  • Creative generation: temperature=1.0, top_p=0.95.

If you set temperature=0, top_p has no further effect.

Seed and system_fingerprint

OpenAI’s API exposes a seed (integer) plus a system_fingerprint returned in each response. Setting seed and pinning to a specific system_fingerprint gives best-effort reproducibility. If the fingerprint changes between calls, the backend changed and reproducibility is not guaranteed. Other providers offer model-version pinning and varying degrees of seed support depending on the model and the SDK; treat seed availability as model-specific and read each provider’s docs before relying on it.

The reproducibility ladder

Use this checklist to bound non-determinism as much as the platform allows.

  1. Pin the model version. Never call gpt-4o; call gpt-4o-2024-08-06 or the equivalent dated snapshot. Same for Claude, Gemini, and Mistral.
  2. Set temperature=0.
  3. Set top_p=1 (no effect if temperature=0, but explicit beats implicit).
  4. Pin the seed. Use the same integer across runs.
  5. Pin the system_fingerprint or backend version. For OpenAI, record and validate system_fingerprint. For self-hosted, pin the vLLM or TGI version, the model checkpoint hash, the dtype, and the batch configuration.
  6. For self-hosted, set the inference engine’s deterministic flags (vLLM --enforce-eager, disable speculative decoding) and accept the throughput cost.
  7. For reasoning models, pin both the model version and the reasoning budget; expect more drift than in non-reasoning models even with all of the above.
  8. Evaluate with semantic equivalence, not byte equality.

Even at the top of this ladder, you should expect occasional drift. The goal is to make drift rare and to detect it when it happens.

How non-determinism breaks evaluation, and how to fix it

A single-run evaluation of a non-deterministic system is statistically meaningless. The honest pattern:

  • For each prompt, run N rollouts (typically 3 to 10).
  • Score each rollout with your evaluator suite.
  • Report mean plus standard deviation plus worst case per metric.
  • Plot the distribution; a wide tail means the system is unsafe even if the mean looks good.

For research-grade reproducibility:

  • Log model version, sampling parameters, seed, system_fingerprint, dataset version, evaluator version.
  • Treat the eval result as a tuple, not a scalar.
  • Compare experiments by their full configurations, not by one score.

Future AGI’s Apache 2.0 ai-evaluation library and the Future AGI cloud evals API ship faithfulness, instruction following, groundedness, hallucination, tone, completeness, JSON validity, and custom LLM-judge evaluators that work consistently across OpenAI, Anthropic, Google, Mistral, and self-hosted endpoints. The library is designed for N-rollout evaluation: you call evaluate per rollout, then aggregate.

from fi.evals import evaluate

prompt = "Summarize the support ticket in one sentence."
context = "Customer cannot log in after the recent password reset email expired."

# Pseudocode: substitute your provider SDK call.
# To measure semantic variance, set a non-zero temperature (for example 0.7) and let each rollout sample differently.
# To measure platform drift at fixed temperature=0, keep the same seed across rollouts and watch for any deltas.
rollouts = []
for i in range(5):
    answer = "<your provider SDK call here>"
    score = evaluate(
        "faithfulness",
        output=answer,
        context=context,
    )
    rollouts.append((answer, score.score))

mean_score = sum(s for _, s in rollouts) / len(rollouts)
worst = min(s for _, s in rollouts)
print(f"Mean faithfulness: {mean_score:.2f}, worst rollout: {worst:.2f}")

For LLM-as-judge in your domain language:

from fi.evals.metrics import CustomLLMJudge
from fi.evals.llm import LiteLLMProvider

prompt = "Summarize the support ticket in one sentence."
answer = "<the model's response for this rollout>"

judge = CustomLLMJudge(
    provider=LiteLLMProvider(),
    model="your-pinned-judge-model-version",
    name="support-summary-grader",
    prompt="Score 1-5 whether the summary captures the customer's blocker.",
)
score = judge(input=prompt, output=answer)

For trace-level observability across agentic stacks (LangGraph, OpenAI Agents SDK, CrewAI, AutoGen, Mastra), the Apache 2.0 traceAI library emits OpenTelemetry spans that record sampling parameters, seed, model version, and the evaluator scores on every span. That lets you replay a run, compare two runs side by side, and find which prompt or which sampling configuration is unstable.

from fi_instrumentation import register, FITracer

tracer_provider = register(project_name="non-det-experiment")
tracer = FITracer(tracer_provider)

with tracer.start_as_current_span("rollout") as span:
    span.set_attribute("seed", 42)
    span.set_attribute("temperature", 0)
    span.set_attribute("model.version", "your-pinned-model-version")
    # ... your LLM call

For BYOK gateway routing, sampling-parameter enforcement, and live guardrails across providers, the Future AGI Agent Command Center sits in front of the major LLMs and lets you pin defaults across all of them. It uses FI_API_KEY and FI_SECRET_KEY plus your existing provider keys.

Agentic workflows: non-determinism compounds

In a single chat completion, non-determinism shows up once. In a five-step agent run, it can compound:

  • Step 1: planner picks tool A or tool B, depending on sampling.
  • Step 2: tool A returns one set of results, tool B returns another.
  • Step 3: the agent’s next plan depends on what step 2 returned.

The result is that two agent runs from the same starting state can take completely different trajectories. Some of this is unavoidable. To bound it:

  • Pin every model call with temperature=0 and a per-step seed.
  • Make tools deterministic where you can: idempotent APIs, pinned retrieval indices, cached web fetches.
  • Record every span with OpenTelemetry so you can replay a run.
  • Use trajectory-tolerant evaluators: score the final outcome and the path quality, not the exact tool sequence.
  • Run N agent rollouts per scenario in your eval suite, just like you would for single LLM calls.

For more on agent observability and evaluation, see our agent observability vs evaluation vs benchmarking 2026 writeup.

Open-source and self-hosted: extra non-determinism levers

When you run the model yourself (vLLM, TGI, llama.cpp, Ollama), you control more knobs:

  • dtype. bf16 and fp16 are not bitwise equal. Pin one and stick with it.
  • batch size. Static batch sizes plus deterministic kernels reduce drift; continuous batching introduces more.
  • Inference engine version. Pin the vLLM or TGI version; a kernel change can shift the argmax.
  • GPU type. A100, H100, and L40S may produce slightly different logits at the bit level due to kernel implementation differences.
  • Speculative decoding. Disable for strict determinism; accept the throughput cost.
  • MoE routing. For mixture-of-experts models, batch context affects routing. Smaller, padded batches reduce variability.

For research reproducibility, the standard practice is to ship a config file with the inference engine version, GPU type, dtype, batch size, sampling parameters, seed, and model checkpoint hash. Future AGI’s traceAI captures most of these automatically on each span.

Common questions and pitfalls

”I set temperature to 0 and still get different answers.”

Likely causes: the model version drifted (you called gpt-4o, not a pinned snapshot), the backend system_fingerprint changed, batch composition changed, or the model is a reasoning model whose hidden chain-of-thought sampling is independent of the visible temperature parameter.

”My evaluation scores swing 10 percent between runs.”

You are scoring a non-deterministic system with a single rollout. Run 5 to 10 rollouts per prompt, report mean plus standard deviation, and pin everything else (model, seed, sampling params, evaluator).

”I want bitwise reproducibility for compliance.”

You are likely going to need self-hosting with deterministic-mode flags on vLLM or TGI, a fixed GPU type, fp32 or bf16 with deterministic kernels enabled, and acceptance of the throughput cost. Even then, validate with a determinism eval before claiming reproducibility.

”Should I use temperature=0 in production?”

For factual, instruction-heavy, or extraction tasks: yes. For creative content, summarization with style variation, or open-ended chat: a small non-zero temperature (0.3 to 0.7) is usually better because it avoids degenerate repetition and reads more naturally.

Bottom line

In 2026 you cannot eliminate non-determinism in LLM systems, but you can bound it. The four levers that matter are: pin the model version, set temperature=0 (or document the chosen temperature and seed), pin the seed and system_fingerprint, and evaluate with N rollouts using semantic-equivalence evaluators rather than byte-exact match. For agentic workflows, layer in deterministic tools and trajectory-tolerant scoring. Future AGI’s evaluation, traceAI, and Agent Command Center components are designed to make this loop measurable. The teams that ship reliable LLM products do not try to make the underlying system deterministic; they design their evaluation and product UX to live with controlled variance. See our LLM evaluation guide and LLM prompts best practices for the wider playbook.

Frequently asked questions

What is non-determinism in LLMs?
Non-determinism means the same input prompt can produce different outputs across calls. The proximate cause is probabilistic next-token sampling: at each step the model produces a probability distribution over the vocabulary, and the decoding strategy samples from that distribution. Set sampling to greedy and the math becomes deterministic on paper, but other sources of non-determinism remain in real systems: batch ordering on GPUs, attention kernel choices, MoE expert routing in mixture-of-experts models, floating-point non-associativity in summation, and API-side load balancing between datacenters. As of 2026 OpenAI exposes a `seed` and `system_fingerprint`, and several other providers expose comparable seed-like controls; check your provider's docs for the exact contract, because full bitwise reproducibility is still hard to guarantee.
Why is non-determinism a problem in production?
Three reasons. First, evaluation: if the same prompt scores 4.1 on one run and 3.6 on the next, you cannot tell whether a prompt change moved the score or whether you sampled a lucky variance. Second, debugging: you cannot reproduce yesterday's bad response to root-cause it. Third, user trust: support agents, financial summaries, and legal drafting need consistent outputs so users can predict and verify behavior. Non-determinism does not mean the model is broken; it means you must measure variance and design the application to tolerate or reduce it.
How do temperature, top-k, and top-p actually work?
All three reshape the probability distribution over the next token. Temperature divides each logit by T before the softmax: T=0 makes the model fully greedy (the highest-probability token wins every time), T=1 leaves the distribution unchanged, T>1 flattens it and increases randomness. Top-k keeps only the K highest-probability tokens and renormalizes them, dropping the long tail. Top-p (nucleus sampling) keeps the smallest set of tokens whose cumulative probability is at least p, so the candidate pool adapts to how peaky or flat the distribution is. In practice you use temperature plus either top-k or top-p, not all three independently.
Does temperature=0 give deterministic outputs?
Mathematically yes, in practice no. Temperature=0 selects the argmax at each step, so a deterministic decoder running the same model on the same hardware with the same input should produce the same output. But production LLM APIs run on GPUs with batched, parallel kernels where floating-point summation order varies with batch composition, multiple datacenters route requests differently, and mixture-of-experts models route tokens to different experts depending on batch context. The result is that even at temperature=0 you can see small but real output drift. The 2026 fix is to use both temperature=0 and the API's seed plus system_fingerprint parameters, then validate with a determinism eval.
What parameters do I set for the most consistent outputs?
Start with temperature=0, top_p=1, the API's seed parameter pinned (when supported), and a fixed model version (not 'latest'). For OpenAI, also record the `system_fingerprint` returned in the response and re-run only if the fingerprint matches. For Anthropic Claude and other providers, pin to a specific dated model identifier rather than a moving alias. For self-hosted models, pin the inference engine version (vLLM, TGI), the dtype (bf16 vs fp16), the batch size, and the sampling parameters. Even with all of this you should expect occasional drift; design your evaluator to tolerate semantic equivalence, not byte-exact equality.
How is non-determinism different for reasoning models in 2026?
Reasoning-trained models (OpenAI o-series, Anthropic Claude with extended thinking, and other reasoning-mode models that have shipped in 2025 and 2026) generate hidden chain-of-thought before the final answer. The internal sampling is non-trivial; even at the same temperature, two runs can take different reasoning paths and reach the same answer, or reach different answers. Best-of-k sampling, used at frontier benchmarks, samples K reasoning runs and selects the best, which is inherently non-deterministic by design. For reasoning models, treat the answer as the unit you evaluate, not the chain-of-thought.
How do you evaluate non-deterministic outputs reliably?
Run each prompt N times (typically 3 to 10) and report mean plus standard deviation, not a single score. Use evaluators that score semantic equivalence rather than byte-exact match: faithfulness, instruction following, JSON schema validity, structural correctness, LLM-as-judge with explicit criteria. Future AGI's Apache 2.0 ai-evaluation library and the cloud evals API are designed for this loop; you batch N rollouts per prompt, score each, and report aggregates plus tail behavior. For research-grade reproducibility, pin the model version, sampling parameters, seed, and evaluator version in your experiment log.
Can I make agentic workflows deterministic?
Mostly not, end to end. Each model call inside an agent has its own non-determinism, and once a tool result or retrieval changes, the downstream state diverges quickly. The realistic discipline is: keep model calls as deterministic as possible (temperature=0, seed, pinned model), make tools deterministic where you can (idempotent APIs, pinned retrieval indices, cached web fetches), record every span via OpenTelemetry, and score agent runs with evaluators that allow multiple valid trajectories. Future AGI's Apache 2.0 traceAI library captures every span across LangGraph, OpenAI Agents SDK, CrewAI, AutoGen, and Mastra so you can compare runs after the fact.
Related Articles
View all
Stay updated on AI observability

Get weekly insights on building reliable AI systems. No spam.