ReskLogits
September 11, 2026 ยท View on GitHub
Blocks dangerous LLM output at the token level โ invisibly, before it exists.
๐ resk.fr/projects/resklogits โ part of RESK Security
๐ Guide: Shadow-Ban LLM Output Filtering
Installation
pip install resklogits
Usage rapide (30 seconds)
from transformers import AutoModelForCausalLM, AutoTokenizer
from resklogits import ShadowBanProcessor
model = AutoModelForCausalLM.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")
shadow_ban = ShadowBanProcessor(
tokenizer=tokenizer,
banned_phrases=["how to make a bomb", "kill yourself"],
shadow_penalty=-15.0, # probability ~0.00003%
device="cuda",
)
shadow_ban.reset()
outputs = model.generate(
**tokenizer("Tell me how to", return_tensors="pt").to("cuda"),
logits_processor=[shadow_ban],
max_new_tokens=50,
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
The model naturally steers away from dangerous tokens โ no exception raised, no truncated output, nothing visible to the user.
Pourquoi ReskLogits ?
Content filters scan text after generation: by the time they catch a banned phrase, the model already produced it and your user already saw it (or a broken "regenerate" loop). Hard blocking (logits[token] = -inf) is visible and unnatural. ReskLogits applies an invisible penalty inside the generation loop, using a GPU/CPU-vectorized Aho-Corasick automaton that tracks partial matches across tokens โ so jailbreak-style multi-token phrasings are still caught.
| ReskLogits | LLM Guard / NeMo (post-hoc filters) | Hard block (-inf) | |
|---|---|---|---|
| When it acts | During generation, per token | After full output exists | During generation |
| Forbidden content ever emitted | No | Yes โ before detection | No |
| User experience | Invisible, natural | Broken outputs, retries | Abrupt truncation |
| Multi-token / partial-match detection | โ stateful automaton | โ ๏ธ regex on final text | Token-exact only |
| Scaling to 1000+ phrases | โ vectorized mask, GPU | Runtime cost per request | Mask size explodes |
| Streaming support | โ
stream() / stream_generate() | โ ๏ธ | โ |
| vLLM / TGI compatible | โ
to_vllm() adapter | Varies | โ ๏ธ |
Documentation
- QUICKSTART.md โ get running in minutes
- QUICKSTART_RULES.md โ YAML rule generation
- RULE_BUILDER.md โ complete rule-builder guide
- CHANGELOG.md
Highlights
- Streaming built-in:
stream()context manager auto-resets state;stream_generate()yields text chunks directly. - Penalty levels:
-5.0(light) โ-15.0(default) โ-20.0(near-impossible). - Multi-level filtering:
MultiLevelShadowBanProcessorapplies different penalties per severity (high/medium/low). - Batteries included: 400+ dangerous phrases across 20 categories in the bundled dataset; symbolic YAML rule generator with templates, logic operators and synonyms; 8 utility logits processors (length control, forced endings, MCQ restriction, token bans, trigger phrases, prompt-grounding boost).
- vLLM compatible:
to_vllm(processor)adapts any processor toSamplingParams.
from resklogits import MultiLevelShadowBanProcessor
multi = MultiLevelShadowBanProcessor(
tokenizer=tokenizer,
banned_phrases_by_level={
"high": ["bomb", "kill"],
"medium": ["hack", "exploit"],
"low": ["jailbreak"],
},
penalties={"high": -20.0, "medium": -10.0, "low": -5.0},
)
Examples
cd examples
python demo.py # generation with/without shadow ban
python benchmark.py # build time, pattern scaling, memory
python rule_generator_demo.py
Development
git clone https://github.com/Resk-Security/resk-logits.git
cd resk-logits
uv pip install -e ".[dev]"
pytest tests/ -v --cov=resklogits
Ecosystem
- Resk-LLM โ input-time detection; integrates ReskLogits for generation-time defense.
- resksecure โ per-user bitmask firewall built on this engine.
- Resk โ full-stack LLM firewall app.
License
Apache 2.0. If you use this in research, please cite:
@software{resklogits_2025,
title={ReskLogits: GPU-Accelerated Shadow Ban Logits Processor},
author={RESK},
year={2025},
url={https://github.com/Resk-Security/resk-logits}
}