LLM Temperature, Top-p and Other Settings Explained Simply

What does LLM temperature do? A simple guide to temperature, top-p, max tokens, stop sequences and system prompts, and which settings to use for each task.

LLM temperature is a setting that controls how predictable or varied a language model’s output is. Low temperature makes the model stick to its most likely words, which suits facts and code. Higher temperature lets it pick less likely words, which suits brainstorming and creative writing.

Temperature is one of a handful of settings that shape how a model responds. This guide explains the common ones, including top-p, max tokens, stop sequences, and system prompts, in plain language, with practical advice on when to change them.

Why LLMs need settings at all

Every time a model writes, it predicts the next token (a small chunk of text) by assigning a probability to every option in its vocabulary. Then it has to choose one. For a refresher on that process, see how LLMs work.

The settings below mostly control that choice. Should the model always take the top option? Should it sometimes pick the second or tenth? How long should it keep going? Different answers suit different jobs.

Note that not every app or model exposes every setting. Chat apps often hide them, while developer APIs and local tools usually let you adjust them. Some models also restrict or ignore certain settings, so check the documentation of the tool you use.

Temperature

Temperature reshapes the probabilities before the model picks a token.

  • Low temperature sharpens the distribution. The most likely tokens become even more likely, so output is focused, consistent, and repetitive across runs.
  • High temperature flattens the distribution. Less likely tokens get a bigger chance, so output becomes more varied and surprising, and eventually less coherent.

A simple analogy: imagine asking a friend to finish the sentence “For breakfast I had…” At low temperature, they say “toast” every time. At a moderate temperature, you sometimes get “pancakes” or “leftover pizza.” At a very high temperature, you might get “a violin,” which is creative but not useful.

Is temperature zero deterministic?

At or near zero, the model almost always picks its top choice, so answers become highly repeatable. In practice, small differences can still appear between runs because of how computations are carried out on the hardware and service. Treat low temperature as “very consistent,” not “guaranteed identical.”

Does lower temperature mean more accurate?

Not exactly. Lower temperature reduces random detours, which can help with factual and technical work. But if the model’s most likely answer is wrong, low temperature will give you that wrong answer consistently. It is one tool against AI hallucinations, not a cure.

Top-p (nucleus sampling)

Top-p limits which tokens the model can choose from. Instead of considering every possible token, it takes the smallest group of top tokens whose combined probability reaches a threshold, called p, and samples only from that group.

  • A low top-p keeps the model to a small set of very likely tokens.
  • A high top-p allows a wider range, including more unusual choices.

Top-p and temperature both control variety, in different ways. A common piece of advice is to adjust one of them and leave the other at its default, so you can tell which change made the difference.

Top-k

Some tools also offer top-k, which limits the choice to a fixed number of the most likely tokens, such as the top 40. It is a cruder version of the same idea as top-p.

Max tokens

Max tokens sets a ceiling on how long the response can be, measured in tokens. When the model hits it, generation simply stops, even mid-sentence.

Use it to:

  • Keep responses short and costs predictable
  • Prevent runaway output in automated systems

Be careful not to set it too low for tasks that need room, like writing code or long reports. If answers keep cutting off, this is the first setting to check. Remember that both your input and the output must fit in the model’s overall limit, explained in tokens and context windows.

Stop sequences

A stop sequence is a piece of text that tells the model to stop as soon as it produces it. For example, you might stop at a blank line or a specific marker when you only want one item from a list. Stop sequences are mostly useful when building apps that parse model output.

Frequency and presence penalties

Some APIs provide penalties that discourage repetition:

  • Frequency penalty reduces the chance of a token the more often it has already appeared.
  • Presence penalty reduces the chance of any token that has appeared at all, nudging the model toward new topics.

They can help when output gets repetitive, but strong values can make text awkward. Most people can leave them at default.

System prompts

A system prompt is a set of instructions given to the model before the conversation, usually hidden from the end user. It sets the role, tone, rules, and boundaries for every reply.

Examples of what a system prompt might say:

  • “You are a support assistant for a bike shop. Answer only questions about our products.”
  • “Reply in short bullet points. Ask a clarifying question if the request is ambiguous.”
  • “Never run commands that delete files without asking first.”

Unlike temperature, a system prompt changes what the model tries to do, not how randomly it picks words. In practice it is often the most powerful setting you have. Clear, specific instructions do more for quality than fine-tuning sampling numbers.

AI agents rely heavily on system prompts. They describe the agent’s tools, rules, and working style. To learn how agents use those instructions, see what is an AI agent.

Which settings to use for which task

There is no universal best value, and the right numbers differ between models. As a general direction:

Task Temperature Other tips
Code, data extraction, factual Q&A Low Clear system prompt, enough max tokens for full output
Summaries and analysis Low to moderate Provide the source text in the prompt
General chat and explanations Moderate (often the default) Defaults usually work well
Brainstorming and creative writing Moderate to high Ask for several options at once
Structured output for an app Low Use stop sequences or a defined format

When in doubt, start with the default settings, change one thing at a time, and compare results on a few real examples.

Settings in coding agents

If you use a coding agent such as Claude Code or Codex, you usually do not tune temperature yourself. The tool picks sensible settings for reliable code. The choices that matter more there are which model to use and how much effort or reasoning it should spend.

BotQuarters follows the same idea for teams of agents: you choose the AI and effort level per role, and a spending level per company, rather than tweaking sampling numbers.

FAQ

What is temperature in an LLM?

Temperature is a setting that controls randomness when a model picks its next token. Low values make output focused and consistent, while higher values make it more varied and creative, and very high values can make it incoherent.

What temperature should I use for coding?

A low temperature is generally best for code, because you want the model’s most reliable choices rather than creative variations. Many coding tools already set this for you, so you often do not need to change it.

What is the difference between temperature and top-p?

Temperature reshapes the probabilities of all possible tokens, making the choice sharper or flatter. Top-p limits the choice to the smallest set of top tokens that reach a set probability. Both affect variety, so it is usually best to adjust only one at a time.

What does max tokens do?

Max tokens caps how many tokens the model may generate in one reply. When the limit is reached, the output stops, even mid-sentence. It is useful for controlling length and cost, but setting it too low cuts answers short.

CEO of BotQuarters

Writes about AI agents, AI teams and getting real work done with them. BotQuarters turns a team of AI agents into a company you can watch at work.

Keep reading