/major-ai-skills:logit-bias-token-steeringfrom major-ai-skills
Configure token-bias controls on supporting model APIs for constrained generation, then validate the returned values.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When asking an LLM for classification, routing decisions, or boolean validation, standard prompt engineering relies on natural language instructions ("Please answer with only the word YES or NO"). Despite these instructions, models often output leading punctuation, whitespace, or full sentences ("Yes, the code is secure."), breaking downstream parsers and wasting tokens.
Logit Bias directly modifies the pre-softmax logits (unnormalized log-probabilities) for specific token IDs in the model's vocabulary. Setting a bias of +100 guarantees the model selects strictly from your allowed token set, while -100 completely bans unwanted tokens (e.g., conversational filler words).
The Logit Bias Token Steering Protocol constrains the model at the sampling layer, achieving 100% deterministic 1-token outputs with zero parsing failure risk.
┌─────────────────────────────────────────────────────────────┐
│ Logit Bias Transformer Sampling │
│ │
│ Unbiased Sampler (Prompt: "Is this secure? YES or NO"): │
│ • Token "Yes" ──► Logit: 4.2 ──► Prob: 45% │
│ • Token "Certainly"──► Logit: 3.8 ──► Prob: 30% (Chit-chat)│
│ • Token "No" ──► Logit: 3.1 ──► Prob: 20% │
│ ↳ Model might generate "Certainly, here is the..." │
│ │
│ Logit Biased Sampler (`{"9642": 100, "2822": 100}`): │
│ • Token "YES" (9642) ──► Logit: 104.2 ──► Prob: 70% │
│ • Token "NO" (2822) ──► Logit: 103.1 ──► Prob: 30% │
│ • All Other Tokens ──► Logit: Normal ──► Prob: 0.00001% │
│ ↳ Model is mathematically FORCED to emit YES or NO in 1 tok│
└─────────────────────────────────────────────────────────────┘
Using tiktoken to resolve exact token IDs for the target model:
import tiktoken
from openai import OpenAI
from typing import Literal
client = OpenAI()
encoder = tiktoken.encoding_for_model("gpt-4o")
def get_token_id(word: str) -> int:
"""Extracts exact token ID for a single word."""
tokens = encoder.encode(word)
if len(tokens) != 1:
raise ValueError(f"'{word}' encodes to multiple tokens: {tokens}. Choose a single-token word.")
return tokens[0]
# Pre-compute token IDs for GPT-4o vocabulary
TOKEN_YES = get_token_id("YES")
TOKEN_NO = get_token_id("NO")
def evaluate_condition_deterministic(code_diff: str) -> bool:
"""Evaluates code with 100% mathematical constraint to YES or NO in 1 output token."""
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "Does this git diff introduce any security vulnerabilities? Answer YES or NO."
},
{
"role": "user",
"content": code_diff
}
],
max_tokens=1,
temperature=0.0,
# Force model to choose ONLY between YES (+100) and NO (+100)
logit_bias={
str(TOKEN_YES): 100,
str(TOKEN_NO): 100
}
)
output = response.choices[0].message.content.strip()
return output == "YES"
Ban conversational greetings by applying -100 to filler openers:
BANNED_WORDS = ["Certainly", "Sure", "Hello", "Hey", "Here", "I"]
ban_bias = {str(get_token_id(w)): -100 for w in BANNED_WORDS if len(encoder.encode(w)) == 1}
Map router decisions to discrete integer tokens (0, 1, 2, 3):
# Route to: 0=Frontend, 1=Backend, 2=Database, 3=DevOps
CATEGORY_BIAS = {str(get_token_id(str(i))): 100 for i in range(4)}
When generating JSON fields like {"is_vulnerable": true}, constrain the value tokens to true and false.
Running 1,000 automated policy verification checks:
| Metric | Natural Language Prompting | Logit Bias Protocol | Improvement |
|---|---|---|---|
| Output Tokens Generated | 185,000 tokens | 1,000 tokens | 99.4% Token Reduction |
| Downstream Parse Failures | 32 errors (format drift) | 0 errors | 100% Deterministic |
| Average Latency | 2.4 seconds | 0.06 seconds | 40x Faster Execution |
MANDATORY: For classification, binary gating, and routing prompts using OpenAI-compatible APIs, agents must specify
logit_biascombined withmax_tokens: 1. Never rely on conversational prompt requests when sampler-layer mathematical steering is available.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job