Links
- GitHub: github.com/Resk-Security/Resk-LLM
- PyPI: pypi.org/project/resk-llm
- Web: resk.fr
Prompt injection and jailbreak attacks are the most common LLM security threats today. Most defenses are either too slow for real-time use or locked behind proprietary APIs.
Resk-LLM is an open source Python toolkit that brings 11 threat detectors into a single FastAPI middleware. Install it, decorate your endpoint, and get instant protection against prompt injection, jailbreak, PII leakage, code injection, exfiltration, and more.
Installation
pip install resk-llm
FastAPI Middleware Example
from fastapi import FastAPI
from resk_llm import RESKSecurityMiddleware
app = FastAPI()
# Attach threat detection to your LLM route
app.add_middleware(
RESKSecurityMiddleware,
detectors=["injection", "jailbreak", "pii", "exfiltration"],
mode="block" # or "log" for monitoring
)
@app.post("/chat")
async def chat(message: dict):
# If we reach here, input passed all detectors
response = await call_your_llm(message["content"])
return {"response": response}
Available Detectors
| Detector | What It Catches |
|---|---|
| Prompt Injection | DAN, ignore-prior-instructions, role-play escapes |
| Jailbreak | Hypothetical traps, obfuscated instructions |
| PII Leakage | Emails, phone numbers, SSNs, credit cards |
| Exfiltration | Prompt stealing, data dumping |
| Toxic Content | Hate speech, harassment, profanity |
| Code Injection | SQL, shell, Python eval attempts |
| URL Phishing | Malicious URL patterns |
| And 4 more | Hidden content, base64 encoding, etc. |
Why Dual-Layer Defense?
Resk-LLM works on the input side, catching threats before they reach the model. For even stronger protection, pair it with resk-logits — a GPU-accelerated logits processor that blocks dangerous tokens at generation time. Combined, you get input filtering AND output sanitation in one pipeline.
Production Ready
- MIT licensed, open source
- Python 3.13+ and PyTorch 2.0+
- Zero external API dependencies
- Configurable per-route policies
- Log mode for evaluation, block mode for production
pip install resk-llm
Try it on your next project. Open an issue if a detector misses something — this is community-driven security, and feedback makes it better.
Top comments (0)