Overview

8 Prompt sampling

Prompt sampling treats each model reply as one probabilistic draw rather than a final truth, so reliability improves when you generate multiple independent responses and combine them intelligently. This chapter builds on earlier prompt-design methods by focusing on what to do when even a strong prompt can still produce different answers from run to run, especially when sampling settings like temperature introduce variation. The central idea is to match the aggregation method to the output type and the decision at stake.

For numerical outputs, the recommended technique is the mean, which reduces the impact of outliers and works well for scores, estimates, and confidence values. For categorical outputs, the mode is more appropriate because it functions as majority voting over labels such as severity or routing decisions. For full-text analytical responses, self-consistency checks whether independently generated drafts converge on the same conclusion, while best-of-N is used when one complete response must be selected as the strongest candidate under explicit criteria.

The chapter also gives practical guidance on how many samples to use, how to interpret spread or vote splits as confidence signals, and when sampling is worth the extra cost. Moderate temperature and a small number of generations are usually enough to create useful diversity without turning outputs into noise, and sampling is most justified when wrong answers are costly or when output quality varies enough to affect decisions. Even then, sampling is presented as a reliability aid rather than a substitute for human review, especially in production settings.

Prompt sampling workflow. A single prompt drives N independent generations; the chosen technique then aggregates or selects across them to produce one stable result.

Summary

  • Prompt sampling improves reliability by generating multiple independent responses and aggregating or selecting across them.
  • For technique selection, use mean for numbers, mode for labels, self-consistency for convergent full outputs, and best-of-N for full response selection.
  • Spread and vote distribution are secondary confidence signals. Wider spread or a split vote is a cue to escalate or increase sample size rather than accept the result.
  • Knowing when a single generation is sufficient is as important as knowing when to sample.

FAQ

What is prompt sampling?Prompt sampling is the practice of generating multiple independent responses to the same prompt and then aggregating or selecting among them to produce a more reliable result.
Why is a single model response sometimes unreliable?A single response is only one probabilistic sample. Even with a strong prompt, outputs can vary from run to run when sampling settings like temperature, top_p, or top_k introduce variation.
When should I use the mean technique?Use mean when the output is numeric, such as a score, estimate, or confidence value. Averaging several generations helps reduce the impact of outliers and gives a more stable number.
When should I use the mode technique?Use mode when the output is categorical, such as a label, severity class, routing decision, or risk category. Mode selects the label that appears most often across generations.
What is self-consistency used for?Self-consistency is used for full responses where reasoning may vary but the conclusion should converge. It checks whether multiple independently generated drafts or explanations arrive at the same substantive answer.
What is best-of-N?Best-of-N is a technique for complete responses where you generate several candidates and choose the strongest one using predefined criteria. It is useful when you need one final response rather than an average or majority vote.
How many samples are usually enough?For many tasks, two to eight generations are sufficient. Four to eight often works well for numerical smoothing, while two to four is common for categorical, convergence, and self-consistency tasks.
How should temperature be set for sampling?Sampling usually works best at moderate temperature, often around 0.5 to 0.9 as a starting point. Temperature 0 minimizes variation, while very high temperatures can add too much noise and hurt aggregation quality.
When is sampling worth the extra cost?Sampling is worth it when the cost of a wrong output is higher than the added generation cost. It is especially useful for high-consequence classification, numerical scoring that drives decisions, and open-ended outputs with meaningful quality variation.
Does sampling replace human review?No. Sampling improves reliability, but in production settings the aggregated score, majority label, or selected candidate should still be reviewed by a qualified human before driving operational decisions.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Prompt Engineering in Practice ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Prompt Engineering in Practice ebook for free