Prompts & AI use

Top-p

AI-assisted editorial review:

Top-p, also called nucleus sampling, is a sampling setting for large language models (LLMs). When the model picks its next token, it keeps only the most likely candidates whose combined probability reaches a threshold p, and samples from that group.[1][6] With top_p = 0.1, for example, only the tokens that make up the top 10% of the probability mass are considered.[2]

What does Top-p mean in simple terms?

An LLM writes one token (a word, part of a word, or another text unit) at a time. For each step it has a ranked list of possible next words, each with a probability. Top-p tells it how far down that list it may look: it adds up probabilities from the top until the total reaches p, ignores everything below, and picks one word from what is left.[6] A low value such as 0.1 leaves only the strongest candidates, so answers become more uniform; a value near 1 keeps almost all candidates, so answers vary more.[2][6] The number of candidates is not fixed: when the model is confident, a couple of words may already reach the threshold, and when it is unsure, dozens or hundreds may be needed.[6] Not every API lets you change it: models such as Claude Haiku 5.5 fix top_p at their default and ask you to steer behavior with prompts instead.[3]

How can Top-p be explained with an analogy?

It is like shortlisting supplier quotes until the shortlist covers 90% of the market share, then choosing only from that shortlist. When one supplier dominates, the list is short; when the market is fragmented, it is long.

Where is Top-p used?

Case 1

OpenAI API — Change one setting at a time

OpenAI's API reference describes top_p as nucleus sampling: the model considers only the tokens within the top_p probability mass, so 0.1 means only the tokens making up the top 10% of the probability mass.[2] The same reference accepts values from 0 to 1 and says, for both temperature and top_p, that it generally recommends altering one or the other, but not both.[2] For teams, this means testing one setting at a time so that any change in output can be traced to a single cause.
Result: Official guidance: adjust temperature or top_p, not both (OpenAI API reference).[2]

Case 2

Latest Claude models — Sampling settings are fixed

Anthropic's documentation states that on Claude Haiku 5.5, top_p must be left at its default of 0.99; any other value, including 1, returns a 400 error, and so does a request that sets both temperature and top_p.[3] The migration guide tells developers to remove temperature, top_p and top_k and to guide the model through prompting instead.[3] For older Claude models that support adjustable top_p, the extended-thinking documentation allows 0.95 to 1 when that mode is enabled.[4] Code that hard-codes a custom top_p therefore needs to be checked before switching models.
Result: On Claude Haiku 5.5, a non-default top_p is rejected with an error (Anthropic docs, as of October 2026).[3][4]

Case 3

The original study — Closer to human text than beam search

Holtzman and colleagues introduced nucleus sampling in a paper published at ICLR 2020.[1] Using GPT-2 Large, they showed that beam search, which always favors high-probability text, produced bland and repetitive output, while pure sampling often became incoherent.[1] In their main comparison, nucleus sampling with p = 0.95 had a perplexity of 13.13 against 12.38 for human text and received the highest score in a combined human and statistical evaluation (HUSE 0.97).[1]
Result: Nucleus sampling (p = 0.95) scored best among the decoding methods tested on HUSE (Holtzman et al., ICLR 2020).[1]

Case 4

Hugging Face Transformers — The candidate pool changes size

Hugging Face's guide to text generation shows top-p in its open-source Transformers library with GPT-2.[5] In its illustration with p = 0.92, the model needed the 9 most likely words to reach 92% of the probability mass at one step, but only the top 3 words at the next, more predictable step.[5] The guide notes that top-p and top-k both work well in practice and can be combined.[5]
Result: One setting (p = 0.92) kept 9 candidates at one step and 3 at another in the guide's example.[5]

Try it today

  1. Check whether the model and API you use accept top_p, and what range or default applies. OpenAI's reference allows 0–1; Claude Haiku 5.5 accepts only its default of 0.99.[2][3]
  2. Where top_p can be changed, pick one prompt you use often and run it five times at a low value (such as 0.1) and five times at a high value (such as 0.9), then compare how much the answers vary. This is an internal test, not an official benchmark.
  3. Agree on team starting points by task type, for example lower values for extraction and classification and higher values for brainstorming and copy, and confirm them with your own tests. Good values depend on the model and the task, so start from the model's published settings.[6]
  4. Change temperature or top_p, not both, so results stay easy to interpret.[2]
  5. Write the value explicitly in your code or prompt library, and re-check it whenever you change models; some newer models reject custom values.[3][6]

Limits and direction

Top-p adapts the candidate count to the shape of the distribution, which is its strength and its weakness. When the distribution is flat, the same p can let in many weak candidates; when it is peaked, only one or two remain.[1][6] A narrow candidate set can make output more stable but can also reinforce repetition, and a wide one can expose more alternatives and more errors.[6] Sampling settings change only how a token is chosen. They do not add knowledge or reasoning ability, so they do not guarantee factual accuracy.[6] Values also do not carry over cleanly between models, because each model produces different probabilities.[6]

Two developments are worth watching. First, newer sampling methods such as min-p set the cutoff relative to the top token's probability; its authors report better quality and diversity than top-p, especially at higher temperatures, and note adoption in open-source frameworks such as Hugging Face Transformers and vLLM.[7] Second, some vendors are removing sampling controls: models such as Claude Haiku 5.5 fix temperature and top_p and ask developers to guide behavior with prompts.[3] Teams that rely on top_p should expect to revisit their settings as models change.

Which concepts are related to Top-p?

  • Similar concept
    Prompt VersionBoth belong to the prompting and AI-use toolkit; record the top_p value together with the prompt version so results can be reproduced.
  • Similar concept
    Prompt LibraryOften appears alongside top_p in the prompting and AI-use toolkit; a shared library can store the agreed sampling settings for each prompt.
  • Similar concept
    Persona PromptingA related prompting technique: persona prompting shapes what the model says, while top_p shapes how freely it picks each next word.

Which sources explain Top-p?

  1. arXiv (ICLR 2020) — Holtzman et al., The Curious Case of Neural Text Degeneration (2019-04-22, v2 2020-02-14) — https://arxiv.org/abs/1904.09751
  2. OpenAI API Reference — Create completion: temperature and top_p parameters (accessed 2026-10-13) — https://developers.openai.com/api/reference/resources/completions/methods/create
  3. Anthropic Claude Platform Docs — Claude Haiku 5.5 migration guide: Remove sampling parameters (accessed 2026-10-13) — https://platform.claude.com/docs/en/models/haiku-5-5/migration-guide
  4. Anthropic Claude Platform Docs — Building with extended thinking: Sampling parameters (accessed 2026-10-13) — https://platform.claude.com/docs/en/build-with-claude/thinking
  5. Hugging Face Blog — How to generate text: using different decoding methods for language generation with Transformers (2020-03-01, edited 2023-07) — https://huggingface.co/blog/how-to-generate
  6. Sebastian Raschka — How do temperature, top-k, and top-p sampling differ? (accessed 2026-10-13) — https://sebastianraschka.com/faq/docs/temperature-topk-topp-sampling.html
  7. arXiv — Nguyen et al., Turning Up the Heat: Min-p Sampling for Creative and Coherent LLM Outputs (2024-07-01, v8 2025-11-20) — https://arxiv.org/abs/2407.01082