Skip to main content

reskSecure

Per-user LLM firewall: unauthorized content becomes physically ungeneratable.

PyPI version PyPI downloads Python versions License

Documentation

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

📚 Guides: Capability Bitmasks: Real RBAC for LLM Applications · Data Protection in AI

Installation

pip install resksecure

Requires Python ≥ 3.13, PyTorch ≥ 2.0, transformers ≥ 4.35, resklogits ≥ 0.1.0.

Usage rapide (30 seconds)

Define a policy (policy.yaml):

version: "1.0"
policies:
  - mask: 7
    name: contributor
    default: true
    rules:
      - { phrase: "DROP TABLE", mode: hard }
      - { phrase: "salaries",   mode: bias, penalty: -5.0 }
    tools:
      send_email: { required_bit: 1 }
      read_sql:   { required_bit: 2 }

Enforce it inside generation:

from resksecure import BitmaskLogitsProcessor, load_policy, verify_tool_action

policy = load_policy("policy.yaml")
processor = BitmaskLogitsProcessor(
    mask=7, model_name="mistralai/Mistral-7B-v0.1",
    tokenizer=tokenizer, policy_set=policy, device="cuda",
)
outputs = model.generate(**inputs, logits_processor=[processor])

# Defense-in-depth: verify tool calls against the bitmask
if not verify_tool_action("send_email", user_mask=7, policy_set=policy):
    raise PermissionError("Action not authorized")

Pourquoi reskSecure ?

Prompt filters are jailbreakable; post-generation moderation detects violations after the content is already emitted. reskSecure works at the logits level: every candidate token is checked against an Aho-Corasick automaton before sampling. If a user's capability bitmask doesn't allow it, the model cannot start generating the banned phrase or the disallowed tool call — no prompt engineering can change that.

reskSecure Prompt-based filters Post-generation moderation Generic policy engines (OPA…)
Where it acts Inside the generation loop On the prompt On the finished output App/API layer
Bypassable by prompt injection ❌ ✅ ❌ ⚠️ if model emits
Forbidden content ever emitted No Yes Yes — first Yes
Per-user permissions ✅ capability bitmask ⚠️ prompt-level ❌ global policy ✅ but not generation
Tool-call gating at token level ✅ trigger phrases blocked per bit ❌ ❌ ⚠️ execution-time only
Policy reload without restart ✅ PolicyWatcher (rebuild the processor to apply) — — ✅
What it protects LLM output itself LLM input Nothing retroactively App resources

Documentation

Policy reference

Field Type Description
mask int Capability bitmask identifying this policy
name string Human-readable policy name
strict bool Stop generation at the first banned prefix
default bool Used when no exact mask matches
rules list Phrase rules: phrase, mode (hard = -inf, bias = penalty), penalty
tools dict Tool name → required_bit + optional trigger_phrases

How it works

User request + bitmask (e.g. 7)
   → BitmaskLogitsProcessor intercepts each token prediction
   → Aho-Corasick automaton (resklogits, GPU-accelerated) checks if the token
     starts/completes a banned phrase
   → hard mode: logit = -inf · bias mode: logit += penalty
   → complete match ⇒ EOS forced, generation stops immediately

Tool calls are gated at the token level too: without the required bit, the first token of send_email( can never be generated.

Features: hard/bias severity modes · strict prefix mode · thread-safe (mask, model) automaton cache with TTL · YAML policies with hot-reload · post-generation verify_tool_action defense-in-depth · receives a raw integer bitmask (auth/JWT stays in your app).

Package structure

src/resksecure/
  policy_loader.py         YAML parsing, Policy/PolicySet models
  trie_factory.py          Builds VectorizedAhoCorasick from a Policy
  bitmask_processor.py     BitmaskLogitsProcessor
  tool_guard.py            Post-generation tool action verification
  cache.py                 Thread-safe TTL cache for automata
  policy_watcher.py        Hot-reload daemon

Ecosystem

Built on resklogits · pairs with Resk-LLM (input-time detection) and ReskPoints (action logging). The Resk full-stack app wires all three together.

License

RESK Software License — commercial use requires a paid license. See LICENSE or contact contact@resk.fr.

Metadata

Release files for resksecure 0.1.1

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

Source distribution (sdist)

Source distribution for resksecure 0.1.1
File Size Uploaded Provenance Actions
resksecure-0.1.1.tar.gz 16.1 kB Without provenance Details for resksecure-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 30.5 kB

Release files / resksecure-0.1.1.tar.gz

Download URL resksecure-0.1.1.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d4a75b0ac9f44dc7cb8a8fe3032547b7636cd737ef41f5284dea923d495fe4de
BLAKE2b-256 checksum
How to use checksums
88d2b7106378701ccd71a110a7bf49afa7b249096cdfaf978764771c0d567af1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / resksecure-0.1.1-py3-none-any.whl

Download URL resksecure-0.1.1-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e749e0cc2686fc51d9fe9d86c9c8c15f06a03a5522c9fbb57f3317a0757af29d
BLAKE2b-256 checksum
How to use checksums
52de6b21c8623b51b37f8dec4da23dba5ece55fb375e166237cedbc08bd67582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for resksecure 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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