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

Documentation

🔗 resk.fr/projects/resklogits — part of RESK Security

📚 Guide: Shadow-Ban LLM Output Filtering

Installation

pip install resklogits

Python 3.11+ 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="cpu",           # pass "cuda" when the model runs on GPU
)

shadow_ban.reset()
outputs = model.generate(
    **tokenizer("Tell me how to", return_tensors="pt").to("cpu"),
    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.

Performance

Reproducible CPU overhead and the exact command are in BENCHMARKS.md. The short version: the per-token cost is flat in the number of patterns, and the build cost is what scales.

resk-logits CPU benchmark

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.2

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.2
File Size Uploaded Provenance
resklogits-0.2.2.tar.gz 41.8 kB With provenance Details

Built distribution (wheel)

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

Total release size: 83.0 kB

Release files / resklogits-0.2.2.tar.gz

Download URL resklogits-0.2.2.tar.gz
Size 41.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3006e816c542c8a8af03c8108360125e17680563eca5f376c6b3b8f40af5f249
BLAKE2b-256 checksum
How to use checksums
e4c141b9248498aed467be3b31f6d3b79f4956175a4386d752ced07e2143dd00
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 25, 2026.

Transparency log

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

Download URL resklogits-0.2.2-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bad28f8c38761ef55f39659a5d4aab7e81393e9820fbfc70ada48dfb9ac72278
BLAKE2b-256 checksum
How to use checksums
e9c1b2aa4896bf624766f01b74065e38e8c8ffee8a5e52b1f534e18ce12d2c6c
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 25, 2026.

Transparency log

Security for resklogits 0.2.2

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.2.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 25, 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