Skip to main content

ReskLogits

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

Python 3.10+ on CPU or CUDA. Requires PyTorch 2.x and Transformers 4.35+.

Quick start (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.

Why 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

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}
}

Metadata

Release files for resklogits 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for resklogits 0.2.0
File Size Uploaded Provenance
resklogits-0.2.0.tar.gz 41.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for resklogits 0.2.0
File Interpreter ABI Platform
resklogits-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.6 kB

Release files / resklogits-0.2.0.tar.gz

Download URL resklogits-0.2.0.tar.gz
Size 41.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fd467d08659ec52643aa515d38f2e84d79a3768b678c7d02a2ccd73b75cc0833
BLAKE2b-256 checksum
How to use checksums
b20cb55b184a08886ffb4af784245decbad3ff73064a169b499b19a5f961fbf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / resklogits-0.2.0-py3-none-any.whl

Download URL resklogits-0.2.0-py3-none-any.whl
Size 41.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a65c18a32b43ded4e257300439c35891a126e5d3fc86407790c7dd77ddfd42c
BLAKE2b-256 checksum
How to use checksums
112c0e4e928d0894b70b8d24413cfe779f20724abf486a0c298fe38a5ec418ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for resklogits 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for resklogits-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page