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 value | Weight multiplier | Typical effect |
|---|---|---|
| -100 | About 0 | Token is effectively banned |
| -5 | About 0.007 | Token becomes rare but possible |
| -1 | About 0.37 | Mild discouragement |
| 0 | 1 | No change |
| +1 | About 2.7 | Mild encouragement |
| +5 | About 148 | Token often dominates |
| +100 | Very large | Token is nearly always chosen |
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 compared with related decoding controls
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.
| Control | What it changes | Depends on output so far |
|---|---|---|
| Logit bias | Fixed offset for listed tokens | No |
| Temperature | Sharpness of the whole distribution | No |
| Frequency penalty | Offset scaled by token count in output | Yes |
| Presence penalty | Offset if a token appeared at all | Yes |
| Repetition penalty | Divides or scales repeated token logits | Yes |
| Constrained decoding | Masks tokens that break a grammar | Yes, via parser state |
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.
| Scenario | Recommended setting | Reason |
|---|---|---|
| Single-token classifier | +100 on label tokens, max tokens 1 | Forces one valid label |
| Blocking a banned word | -100 on all its token variants | Removes it at every position |
| Reducing filler phrases | -1 to -3 on opening tokens | Discourages without breaking fluency |
| Preferring a house term | +1 to +2 on its first token | Nudges word choice gently |
| Suppressing early stops | Negative bias on end-of-sequence token | Encourages longer completions |
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.
| Symptom | Likely cause | Fix |
|---|---|---|
| Banned word still appears | Missing space or case variants | Bias every tokenizer variant |
| Output repeats one word | Large positive bias | Lower the value or limit length |
| Unrelated words disappear | Shared subword fragment banned | Bias whole-word tokens only |
| No effect after model change | Different tokenizer IDs | Rebuild the bias map |
| Garbled text near banned term | Model routes around the ban | Rephrase the prompt instead |
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.