Skip to content
Back to skills

Multiple Choice Logits Processor

ASecurity

Constrains LLM generation to a fixed set of valid choice tokens using a logits processor for structured single-token output.

  • 61 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 12, 2026
ai-agentspythongit

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill multiple-choice-logits-processor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Multiple Choice Logits Processor?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Multiple Choice Logits Processor
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-multiple-choice-logits-processor/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-multiple-choice-logits-processor)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: llm-multiple-choice-logits-processor
description: >
  Constrains LLM generation to a fixed set of valid choice tokens using a logits processor for structured single-token output.
---
# Multiple-Choice Logits Processor

## Overview

When an LLM must select from a discrete set of options (A/B/C/D, 1-9, yes/no), unconstrained generation can produce invalid answers, explanations, or refusals. A logits processor masks all tokens except the valid choices before sampling, guaranteeing a single valid token output. Works with vLLM, HuggingFace, and other frameworks.

## Quick Start

```python
import vllm
from logits_processor_zoo.vllm import MultipleChoiceLogitsProcessor

llm = vllm.LLM(model="Qwen/Qwen2.5-32B-AWQ", quantization="awq")
tokenizer = llm.get_tokenizer()

params = vllm.SamplingParams(
    n=1, top_k=1, temperature=0, max_tokens=1,
    skip_special_tokens=False,
    logits_processors=[
        MultipleChoiceLogitsProcessor(tokenizer, choices=["1","2","3","4","5"])
    ],
)
responses = llm.generate(prompts, params)
predictions = [r.outputs[0].text.strip() for r in responses]
```

## Workflow

1. Define the valid choice set (letters, digits, words)
2. Initialize `MultipleChoiceLogitsProcessor` with tokenizer and choices
3. Pass as `logits_processors` in sampling params
4. Set `max_tokens=1` — only one token needed
5. Parse the single-token output directly as the answer

## Key Decisions

- **temperature=0**: Greedy decoding for deterministic classification
- **Choice format**: Match what the prompt expects ("A"/"B" vs "1"/"2")
- **Multi-token choices**: For longer options, use constrained decoding (e.g., `outlines`, `guidance`) instead
- **Batch efficiency**: vLLM handles batched generation with logits processors natively

## References

- [Qwen14B_Retrieval_Qwen32B_logits-processor-zoo](https://www.kaggle.com/code/jagatkiran/qwen14b-retrieval-qwen32b-logits-processor-zoo)
- [Eedi Qwen32B vllm with logits-processor-zoo](https://www.kaggle.com/code/aerdem4/eedi-qwen32b-vllm-with-logits-processor-zoo)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.