Logit bias

On this page 7

Logit bias is a decoding parameter that adds a fixed numeric offset to the logits of selected tokens before the next token is sampled, so that a model becomes more likely, less likely or entirely unable to produce those tokens. In large language models it is one of the most direct token-level steering controls available at inference time, because it changes the output distribution without touching the prompt or the model weights.

The parameter is usually supplied as a map from token IDs to bias values, and it is applied at every generation step for the whole response. Its precision is also its main weakness: it operates on tokens, not words, so using it well requires a clear understanding of the model’s tokenizer and of how the softmax function turns raw scores into probabilities.

How logit bias reshapes the next-token distribution

Logit bias works by editing the raw scores that the language model head produces for every vocabulary entry. At each step an autoregressive model outputs one logit per token; the bias for each listed token is added to that logit, and only then are temperature, top-k, top-p or other sampling rules applied.

Because softmax is exponential, an additive change in a logit becomes a multiplicative change in odds. A bias of +1 multiplies the unnormalized weight of a token by about e, or roughly 2.7, while a bias of +5 multiplies it by about 148. Very large negative values such as -100 act as a practical ban, since the resulting probability is effectively zero, and very large positive values such as +100 usually force the token whenever it is allowed.

The following table shows how typical bias values translate into an approximate change in the relative weight of a token before renormalization.

Bias valueWeight multiplierTypical effect
-100About 0Token is effectively banned
-5About 0.007Token becomes rare but possible
-1About 0.37Mild discouragement
01No change
+1About 2.7Mild encouragement
+5About 148Token often dominates
+100Very largeToken is nearly always chosen
Approximate effect of common bias values

The final probability still depends on the competing logits. A +5 bias on a token whose original probability was one in a million may barely matter, while the same bias on a plausible candidate can make it the dominant choice. Interface limits also apply: many hosted APIs accept values only in a range of -100 to +100 and cap the number of biased tokens per request.

Why logit bias targets tokens rather than words

Logit bias is defined over token IDs from a specific tokenizer, so a word can correspond to several different entries. Byte-pair encoding and similar schemes typically produce separate tokens for a word with and without a leading space, for capitalized and lowercase forms, and for fragments of longer words.

To suppress the word “refund” reliably, a developer may need to bias “refund”, ” refund”, “Refund” and ” Refund”, and even then the model can spell the word from smaller subword pieces. Biasing a common fragment is risky, because the same token may appear inside unrelated words that the application still needs.

A second consequence is model specificity. Token IDs differ between tokenizer vocabularies, so a bias map prepared for one model family is meaningless, or harmful, when sent to another. Bias maps should be generated from the target tokenizer and versioned together with the model identifier.

Logit bias belongs to a family of controls that adjust logits or filter candidates, and each answers a different question. The comparison below separates static per-token offsets from penalties that depend on what has already been generated.

ControlWhat it changesDepends on output so far
Logit biasFixed offset for listed tokensNo
TemperatureSharpness of the whole distributionNo
Frequency penaltyOffset scaled by token count in outputYes
Presence penaltyOffset if a token appeared at allYes
Repetition penaltyDivides or scales repeated token logitsYes
Constrained decodingMasks tokens that break a grammarYes, via parser state
Logit bias and neighboring decoding parameters

The key distinction is that logit bias is context-blind: it applies the same offset at every position regardless of the sentence being built. Constrained decoding, by contrast, computes a dynamic mask from a grammar or schema, which is why it is the better tool for guaranteeing valid JSON, while logit bias suits simple vocabulary preferences and bans.

Practical uses in production systems

Logit bias is most valuable when an application needs a narrow, predictable output space or wants to exclude a small set of strings. Typical cases appear in classification, moderation and interface work, where a single token often carries the whole answer.

ScenarioRecommended settingReason
Single-token classifier+100 on label tokens, max tokens 1Forces one valid label
Blocking a banned word-100 on all its token variantsRemoves it at every position
Reducing filler phrases-1 to -3 on opening tokensDiscourages without breaking fluency
Preferring a house term+1 to +2 on its first tokenNudges word choice gently
Suppressing early stopsNegative bias on end-of-sequence tokenEncourages longer completions
Common scenarios and recommended bias settings

For classification, combining strong positive bias on label tokens with a max tokens limit of one turns a generative model into a constrained chooser, and the logprobs of those tokens can serve as confidence scores. For content rules, negative bias acts as a last-step safeguard, although it should complement rather than replace a proper moderation layer.

Mild values are usually the right starting point. Offsets between -3 and +3 shift style without distorting grammar, whereas extreme values should be reserved for tokens that must be always or never produced.

Limitations, risks and common mistakes

The most frequent failure is incomplete coverage of token variants, which lets a banned word slip through as a different token sequence. The opposite failure, overly aggressive positive bias, can trap the model in repetition loops because the favored token keeps winning at every step.

SymptomLikely causeFix
Banned word still appearsMissing space or case variantsBias every tokenizer variant
Output repeats one wordLarge positive biasLower the value or limit length
Unrelated words disappearShared subword fragment bannedBias whole-word tokens only
No effect after model changeDifferent tokenizer IDsRebuild the bias map
Garbled text near banned termModel routes around the banRephrase the prompt instead
Symptoms, causes and fixes

Some providers restrict or omit logit bias on reasoning models or newer endpoints, and its behavior can interact with hidden reasoning tokens. Logit bias is therefore a blunt but transparent instrument: excellent for small, well-defined vocabularies and poor for semantic goals such as avoiding a topic, which are better handled through the system prompt, fine-tuning or structured output features.

A non-technical view

A language model picks its next word piece by scoring every option. Logit bias lets you tilt those scores for chosen pieces. A positive value makes a piece more attractive. A negative value makes it less attractive. A very large negative value removes it from the menu completely.

Think of a judge scoring contestants, with a few names on a sticky note that get bonus or penalty points. The judge still decides. The note simply changes the odds. The catch is that the note lists word pieces, not whole words, so one missing spelling can let an unwanted word through.

A concrete example

A support team uses a language model to route incoming emails into one of four queues: billing, technical, account and other. Early tests return answers such as “This looks like a billing issue”, which the routing code cannot parse reliably.

The engineer looks up the token IDs for the four labels in the model’s tokenizer and applies a bias of +100 to each label token, with max tokens set to 1 and temperature set to 0. The model can now return only one of the four labels, and the logprob of the chosen token is stored as a confidence score.

Emails with confidence below 0.6 are sent to a human reviewer. After the change, every response is a valid label, parsing errors drop to zero, and reviewers handle only the uncertain fraction of messages. The outcome is a predictable classifier built from a general model without any fine-tuning.