Glossary
Temperature
A sampling setting that controls how predictable a language model's output is, by sharpening or flattening the probabilities it assigns to each possible next token.
Temperature is a setting that controls how random a language model’s output is. At every step of generation the model assigns a probability to each possible next token, and temperature reshapes those probabilities before one is picked. A low temperature, close to 0, sharpens the distribution so the most likely token wins almost every time, which gives focused, repeatable answers. A high temperature, around 1 or above, flattens it so less likely tokens are chosen more often, which gives more varied and sometimes more creative text, along with more mistakes. Temperature changes how the model chooses among the options it already has; it adds no knowledge and does little to fix answers that are wrong because the prompt lacked the facts. For extraction, classification and question answering over documents, a low setting is the usual choice.
How temperature works
A transformer ends each step by producing a raw score, called a logit, for every token in its vocabulary. A softmax function turns those scores into probabilities that add up to one. Temperature is a number that every logit is divided by before the softmax. Dividing by a value below 1 stretches the gaps between scores, so the top token’s probability rises and the rest shrink. Dividing by a value above 1 compresses the gaps, so probability spreads out across more tokens. At exactly 1, the probabilities are the model’s own, unchanged.
The model then samples one token from the adjusted distribution, appends it to the text and repeats. Because each choice feeds into the next step, a single unusual token early on can send the rest of the answer in a different direction. That compounding effect is why two runs at a high temperature can produce answers that differ in substance, not only in wording.
Worked numbers
Suppose the model is completing “The capital of France is” and three candidate tokens have logits of 2.0 for “ Paris”, 1.0 for “ located” and 0.1 for “ a”. The table shows the probability of each after the temperature is applied, rounded.
Temperature | “ Paris” | “ located” | “ a” |
|---|---|---|---|
0.2 | 99.3% | 0.7% | under 0.1% |
0.5 | 86.4% | 11.7% | 1.9% |
1.0 | 65.9% | 24.2% | 9.9% |
1.5 | 55.7% | 28.6% | 15.7% |
2.0 | 50.2% | 30.4% | 19.4% |
At 0.2 the model will pick “ Paris” on almost every run. At 2.0 it picks something else about half the time. Neither of the other two tokens is wrong here, since “located” and “a” can both lead to a correct sentence, but over a long answer with hundreds of choices, the high setting multiplies the chances of a token that leads somewhere unhelpful.
Temperature 0 and determinism
A temperature of 0 is usually treated as greedy decoding: always take the most likely token. That makes output highly repeatable, though often not perfectly so. Hosted models can still vary slightly between identical requests because of floating-point differences, batching with other requests and changes to the serving stack. If you need exactly the same output every time, store the result rather than relying on temperature alone. Some providers also expose a seed parameter that improves repeatability without guaranteeing it.
Temperature, top-p and other sampling settings
Temperature is one of several sampling controls, and they interact. Top-p sampling, also called nucleus sampling, keeps only the smallest set of tokens whose probabilities add up to p, such as 0.9, and samples from those. Top-k keeps a fixed number of the most likely tokens. Min-p, offered by some open-source servers, drops tokens whose probability is below a fraction of the top token’s. Temperature reshapes the distribution and the others truncate it, so combining a high temperature with a moderate top-p is a common way to get variety without the long tail of very unlikely tokens.
Most provider guidance suggests adjusting temperature or top-p, not both at once, because their effects overlap and are hard to reason about together. The range also varies by API: some accept 0 to 2, others 0 to 1, and some reasoning models fix the value or ignore it. Logprobs report the probabilities the model assigned to the tokens it chose, which is the most direct way to see how sharp or flat the distribution was for a given answer.
Choosing a temperature for the task
The right setting depends on whether there is one correct answer or many acceptable ones. The table gives starting points; test them on your own prompts.
Task | Starting temperature | Why |
|---|---|---|
Extraction, classification, structured output | 0 to 0.2 | One correct answer; variation is only noise |
Question answering over documents (RAG) | 0 to 0.3 | The answer should follow the retrieved text |
Code generation | 0 to 0.4 | Small changes can break code; lower is safer |
General chat and assistants | 0.5 to 0.8 | Natural phrasing with stable substance |
Brainstorming, marketing copy, fiction | 0.8 to 1.2 | Variety is the goal; review the output |
For structured output and JSON mode, keep temperature low. Constrained decoding keeps the syntax valid at any setting, but the values inside the fields still vary with temperature, and a date or a total that changes between runs is a bug. For chain of thought reasoning, a technique called self-consistency deliberately samples several answers at a moderate temperature and takes a majority vote, trading extra tokens for accuracy.
When you evaluate a model, temperature affects what you measure. LLM evaluation runs and LLM-as-a-judge graders are usually set to 0 so results can be compared over time, but a production system at 0.7 will behave differently from the one you tested at 0. Either test at the production setting or run each case several times and look at the spread. A golden dataset run five times at your real temperature tells you far more than one run at 0.
For agents, the setting can differ by step. The steps that choose a tool and fill in its arguments behave like extraction, so a low temperature keeps them consistent: the same request should call the same tool with the same parameters. Steps that draft a reply to a user can run warmer. Some teams route these steps to different calls with different settings, which also makes agent tracing easier, because a change in behaviour between two runs can be traced to the context rather than to random sampling. When an agent loops, a high temperature can also send it down a different path on each retry, which is occasionally useful for getting unstuck and usually makes failures harder to reproduce.
What temperature cannot fix
A common reaction to a wrong answer is to lower the temperature. That helps when the model is choosing between a right and a wrong token and the right one is already the most likely. It does not help when the most likely answer is itself wrong because the prompt lacked the facts, carried outdated ones or buried them in a long context. At temperature 0, a model with poor context gives the same wrong answer every time, confidently. Most hallucination in production comes from missing or misleading context, and the fixes are grounding the model in the right material and checking the faithfulness of answers to their sources.
Temperature also has nothing to do with the context window, cost or length. Max tokens sets how long an answer can be, and the length of the prompt sets most of the cost. A system prompt and few-shot prompting shape the style and format more reliably than temperature does, so it is worth fixing those first and treating temperature as a final adjustment.
A worked example: two dials in an invoice pipeline
Consider a team running invoice processing with a language model that reads each invoice and returns the vendor, due date and total. In testing, the same invoice sometimes comes back with a due date of 14 March and sometimes 14 April. The model is set to 0.7, inherited from a chat feature. Dropping it to 0 makes the answer consistent, but now it is consistently 14 April, which is wrong. The invoice has two dates on page two, the issue date and the due date, and the text the model received was a flattened page where the labels had drifted away from their values.
The team fixes the input, so the model receives the due date as a labelled field, and the answer becomes both consistent and correct. Temperature controlled whether the answer varied; the context controlled whether it was right. Both matter, and they are separate dials. The dates and settings in this example are illustrative.
Where Exabase fits
Exabase does not set or override your model’s temperature; you keep full control of sampling in your own model calls. It works on the other dial: the quality of the context the model samples from. Extract recognises invoices, resumes and contracts and returns structured fields such as vendor, invoice number, due date, line items and total, so a model receives labelled values instead of a flattened page. The invoice to JSON tool shows the output for a single file, and the best invoice extraction API comparison covers the wider market.
Exabase Memory keeps facts current by resolving contradictions as they are written, so a model at any temperature is choosing from the right plan, address or preference rather than two conflicting ones; the ask endpoint returns an answer drawn from the relevant memories. Research into context-augmented AI systems finds 28% fewer hallucinations when agents have access to reliable memory and context. Deep Search has its own precision setting, from 0 to 1 with a default of 0.3, that controls retrieval in the way temperature controls generation: low for broad coverage, high for the one passage that answers the question. The searching resources guide and the post on choosing a precision setting explain how to tune it, and RAG accuracy sets out the wider approach. For a look at why wrong answers happen, see we audited 1,000 wrong RAG answers.
Frequently asked questions
What does temperature do in an LLM?
It controls how random the output is. Low values make the model pick the most likely next token almost every time; high values spread the choice across more tokens, giving more varied text.
What is a good temperature for an LLM?
It depends on the task. Use 0 to 0.2 for extraction and classification, up to about 0.3 for question answering over documents, 0.5 to 0.8 for general chat, and 0.8 or higher for creative writing.
Does temperature 0 make output deterministic?
Mostly. It selects the most likely token at each step, but hosted models can still vary slightly between identical requests because of how they are served. Store results you need to reproduce exactly.
Does a lower temperature reduce hallucinations?
Only a little. It removes randomness, but if the model’s most likely answer is wrong because of missing or outdated context, a low temperature repeats the same wrong answer. Better context does more; see hallucination.
What is the difference between temperature and top-p?
Temperature reshapes the whole probability distribution. Top-p cuts it off, keeping only the most likely tokens whose probabilities add up to p. Most guidance suggests tuning one of them, not both.
Why do some models ignore the temperature setting?
Some reasoning models and specialised endpoints use a fixed sampling configuration that the provider has tuned, so they accept the parameter but do not apply it, or reject values other than the default.
Does Exabase control temperature?
No. You set temperature in your own model calls. Exabase supplies the context, through Memory, Deep Search and Extract, so whatever setting you choose is applied to accurate, relevant material.
Related pages: top-p, logprobs, hallucination, structured output, constrained decoding, max tokens, inference, transformer, RAG accuracy