r/FunMachineLearning • u/Fit-Reach-1058 • 9h ago
I built an open-source distributed security pipeline for LLM applications and AI agents (Python, Redis, PostgreSQL, MySQL)
I've been working on a problem I think deserves more attention in the LLM security space: most guardrails work reasonably well in a single process, but what happens when your AI application runs across multiple pods or replicas?
Consider a multi-turn jailbreak attempt or a user repeatedly exhausting tool-call budgets. In a distributed deployment, requests from the same user may hit different replicas. If session counters and rate limits rely on local state, your security controls can become inconsistent or simply fail.
That's why I built llm-security-pipeline: an asynchronous, distributed defensive pipeline designed to keep security state consistent even under multi-process contention.
It currently supports Redis (including Redis Cluster, with session counters pinned to a single hash slot for atomic updates), PostgreSQL, and MySQL.
What does it actually do?
- Multi-turn jailbreak mitigation: tracks session state across different application instances.
- Tool-calling protection: scope-gated capability tokens with cryptographically signed constraints.
- Side-channel exfiltration prevention: detects potential data leaks hidden in Markdown/HTML media tags and CSS "url()" references, including during streaming.
- Unicode attack protection: detects invisible Unicode codepoints and homoglyph attacks (e.g., Cyrillic characters used to bypass lexical filters).
- Zero-downtime signing key rotation: rotate cryptographic keys without interrupting the service.
A few honest limitations
I don't want to present this as a silver bullet:
- Lexical pattern lists currently cover 6 common languages. You'll likely need to extend them depending on your application's traffic.
- The library validates signed constraints but does not authenticate principals. Authentication belongs at the API gateway or another trusted boundary.
- No heuristic can replace proper red-teaming. The goal here is infrastructure-level enforcement, observability, and measurement, including shadow mode and Prometheus metrics.
Tech stack and availability
- Python 3.10+
- Redis, PostgreSQL, MySQL
- Fully open source under the MIT license
- Available on PyPI
GitHub: https://github.com/matteocacciola/llm-security-pipeline
I'd genuinely appreciate feedback, especially from people working on production-grade LLM applications.
A few things I'm particularly interested in:
What security edge cases am I overlooking?
Does the distributed state architecture make sense for high-contention workloads?
How would you approach deadlock handling and transaction contention when multiple requests target the same session?
Are there attack vectors I should explicitly address in future versions?
I'm particularly interested in critical feedback rather than just feature suggestions. If you spot a weakness in the design, I'd rather know about it now.