ReskLogits

September 11, 2026 ยท View on GitHub

Blocks dangerous LLM output at the token level โ€” invisibly, before it exists.

PyPI version Python Versions License Downloads GitHub stars GitHub issues GitHub last commit

๐Ÿ”— 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.

ReskLogitsLLM Guard / NeMo (post-hoc filters)Hard block (-inf)
When it actsDuring generation, per tokenAfter full output existsDuring generation
Forbidden content ever emittedNoYes โ€” before detectionNo
User experienceInvisible, naturalBroken outputs, retriesAbrupt truncation
Multi-token / partial-match detectionโœ… stateful automatonโš ๏ธ regex on final textToken-exact only
Scaling to 1000+ phrasesโœ… vectorized mask, GPURuntime cost per requestMask size explodes
Streaming supportโœ… stream() / stream_generate()โš ๏ธโœ…
vLLM / TGI compatibleโœ… to_vllm() adapterVariesโš ๏ธ

Documentation

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: MultiLevelShadowBanProcessor applies 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 to SamplingParams.
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}
}