Analytics Legends logoAI & Analytics Legends Sign inSign up
Concept card

Sampling Strategies

Sampling Strategies — AI & Analytics Legends section illustration for the SAP AI & Analytics knowledge base (concepts, studies, Academy)

As of 2026-11-24

What is Sampling Strategies?

A misconfigured sampler is one of the most common causes of unexplained output variance in production LLM systems — and for audit-critical SAP or Joule workflows, log the model version, prompt and sampling settings with every output: T=0 with a fixed seed narrows variation but does not guarantee identical output on a hosted model, and the EU AI Act asks high-risk systems for automatic logs (Art. 12) and appropriate accuracy and robustness (Art. 15), not for a sampling setting.

Sampling strategies are the algorithms that decide how a language model picks the next token from the probability distribution its final layer produces. They sit at the very last step between a trained model and what actually appears on screen, which makes a misconfigured sampler one of the most common — and most overlooked — causes of inconsistent behaviour in a production LLM deployment.

The problem they solve

Always picking the single most probable token, known as greedy decoding, produces text that degenerates into loops: because each choice reinforces the probability of choosing something similar next, the model gets stuck repeating a phrase or a sentence structure. Pure random sampling from the raw distribution goes the other way and produces text that is fluent word-to-word but incoherent as a whole. Every practical deployment sits somewhere between these two extremes, and where it should sit depends entirely on the task.

The main parameters

Temperature rescales the model's output distribution before the final normalisation step: a temperature of one leaves the trained distribution as-is, a temperature below one sharpens it toward the most likely tokens and pushes the output toward determinism, and a temperature approaching zero collapses it into greedy decoding.

Why it matters

  • Temperature and top-p are largely redundant — most practitioners fix one and vary the other, simplifying what looks like a large tuning surface.
  • An active repetition penalty can break structured outputs (JSON arrays, SQL clauses) by suppressing legitimate repetition — a concrete failure mode to test for.
  • Min-p is gaining adoption because it's more stable than top-p at high temperature — worth knowing before defaulting to nucleus sampling everywhere.

Key points

  • Temperature T=0 gives greedy output (argmax) — lowest variance, but not guaranteed identical on a hosted model; T=1.0 is unchanged from trained distribution; T>1 flattens toward uniform.
  • Top-p and temperature are largely redundant — pick one axis to tune. A moderate temperature (T≈0.7) with top-p=0.9 is a common balanced creative baseline; T=1.0 with top-p=0.95 for maximum diversity.
  • Top-k=40 is a common creative default; top-k=1 is equivalent to greedy decoding (reproducible only on a fixed model and serving stack).
  • An active repetition penalty can suppress legitimate repetition in structured outputs (JSON, SQL, XML) — keep at 1.0 (disabled) for code, JSON, SQL and extraction tasks.
  • Min-p (2023): sets a probability floor as a fraction of the top token's mass; min_p=0.05 is more temperature-stable than top-p and gaining adoption in open-weight runtimes (llama.cpp, vLLM).
  • Beam search (k=4–8 beams) improves quality for constrained structured output but multiplies inference compute by k — cost-prohibitive in high-throughput or agentic pipelines.
  • EU AI Act, high-risk systems: automatic logging (Art. 12) and appropriate accuracy and robustness (Art. 15). Log model version, prompt and sampling configuration; T=0 and a fixed seed reduce variation but are neither required by the Act nor a guarantee of identical output.
  • SAP Joule uses internally managed sampling configs; understanding these parameters matters when building custom LLM agents via SAP AI Core or open-weight models alongside Joule.
  • For extraction, classification, and SQL generation: T=0 on models that accept it (on Claude Sonnet 5, Sonnet 5.5, or Opus 4.7 and later, leave the default and pin model ID and prompt version). For explanation, summarisation, brainstorming: T=0.7–1.0 with top-p=0.9–0.95.
  • Log the full sampling configuration (T, top-p, top-k, seed, model version) alongside every LLM output in production — without it, debugging non-deterministic failures is structurally impossible.

Terms used on this page

Temperature (T)
Scaling factor applied to logits before softmax: z/T. T<1 sharpens the distribution toward argmax; T>1 flattens it toward uniform; T=0 is greedy (argmax) — lowest variance, but not guaranteed identical output on a hosted model.
Nucleus sampling (top-p)
Restricts token selection to the smallest set of candidates whose cumulative probability ≥ p, dynamically adjusting the candidate pool size based on distribution entropy (Holtzman et al. 2019).
Top-k sampling
Restricts token selection to exactly the k highest-probability tokens, regardless of their cumulative probability mass.
Min-p sampling
Sets a probability floor as a fraction of the top token's probability: tokens with p < min_p × p_top are excluded. More stable than top-p at high temperature; gaining adoption in open-weight runtimes (2023).
Repetition penalty
Factor >1 that lowers the logits of already-generated tokens (positive logits divided by it, negative logits multiplied) to reduce looping; it can also suppress legitimate repetition in structured outputs like JSON arrays or SQL clauses.
Greedy decoding
Decoding that always selects the highest-probability next token; equivalent to T→0 or top-k=1. The usual mode for audit-critical and structured-output tasks on models that still accept sampling parameters; the EU AI Act does not require it.
Beam search
Maintains k candidate sequences (beams) in parallel at each decoding step, selecting the highest-scoring sequence among the beams kept (a heuristic: the global optimum is not guaranteed); improves quality for constrained outputs at k× compute cost.
KV cache
The cached key-value projections from previous attention steps, enabling efficient autoregressive decoding without recomputing attention over the full context at every step.

Sources

  1. Holtzman et al. 2019 — The Curious Case of Neural Text Degeneration (nucleus sampling)
  2. OpenAI API reference — sampling parameters
  3. Anthropic API reference — sampling parameters
  4. Stahlberg & Byrne 2019 — On NMT Search Errors and Model Errors
  5. EU AI Act — Regulation (EU) 2024/1689 (Art. 9 risk management, Art. 12 record-keeping, Art. 15 accuracy and robustness)
  6. Shah et al. 2024 — FlashAttention-3: Fast and Accurate Attention on Hopper GPUs
  7. vLLM documentation — sampling parameters
  8. SAP AI Core — generative AI hub documentation
  9. SAP Business AI — official product page
  10. SAP Generative AI — official product page
  11. SAP News Center — Secure AI agents: how SAP and NVIDIA co-define enterprise-grade agent execution (OpenShell)
  12. SAP Help Portal — Orchestration service: templating module and model-parameter configuration
  13. SAP Help Portal — Prompt Registry: versioned, Git-synced prompt and orchestration-config templates
  14. Anthropic — Claude Platform release notes, 28 and 30 September 2026 (Sonnet 5.5 launch, Sonnet 4.5 deprecation)
  15. Anthropic — Claude Sonnet 5.5 migration guide (non-default temperature/top_p/top_k return a 400 error)
  16. Anthropic — Claude Opus 5.5 migration guide (sampling parameters removed; temperature 0 never guaranteed identical outputs)
  17. Anthropic — Model deprecations (Claude Sonnet 4.5, notified 30 September 2026, retirement 30 November 2026)
  18. NVIDIA — Open Agent Development Platform press release, 16 March 2026 (OpenShell)
  19. Snowflake — AI_COMPLETE (single string): model parameters
  20. Databricks — Foundation model REST API reference
  21. SAP-docs — Orchestration Config Management in the Prompt Registry (versioning, history)

Full card with the Consultant plan — €19.90/month. What the full card adds: the full decision framework · the SAP vs Snowflake / Databricks / Fabric comparison · the common pitfalls and their fix · the cheat sheet · the architecture schemas · the code blocks · the facts worth quoting.

Open in the app →

Open missions

SAP analytics jobs and contracts · freelance SAP contracts.