Security guards for LLM-powered and agentic AI applications. Zero dependencies. Covers OWASP Top 10 for LLMs 2025.
Project description
llm-trust-guard
Security guards for LLM-powered applications. Zero dependencies. Python port of the npm package.
Installation
pip install llm-trust-guard
Quick Start
from llm_trust_guard import InputSanitizer, EncodingDetector, CompressionDetector
# Check for prompt injection
sanitizer = InputSanitizer(threshold=0.3)
result = sanitizer.sanitize(user_input)
if not result.allowed:
print(f"Blocked: {result.matches}")
# Check for encoding bypass attacks
encoder = EncodingDetector()
result = encoder.detect(user_input)
if not result.allowed:
print(f"Encoded threat: {result.violations}")
# Check structural similarity to known attacks (NCD)
detector = CompressionDetector()
result = detector.detect(user_input)
if not result.allowed:
print(f"Similar to: {result.ncd_analysis.closest_category}")
Guards (Phase 1)
| Guard | Purpose | Method |
|---|---|---|
InputSanitizer |
Prompt injection detection (170+ patterns, 11 languages) | Regex + PAP |
EncodingDetector |
Encoding bypass (9 formats: Base64, URL, Unicode, Hex, HTML, ROT13, Octal, Base32) | Decode + scan |
CompressionDetector |
Structural similarity to known attacks | gzip NCD (135 templates) |
HeuristicAnalyzer |
Synonym expansion + structural + statistical analysis | 8 attack categories |
OutputFilter |
PII/secret detection and masking in LLM output | Regex + redaction |
Key Features
- Zero dependencies — only Python stdlib (re, zlib, base64, html)
- Same patterns as the npm package — feature parity with llm-trust-guard v4.13.1
- Fast — all checks complete in <5ms
- Python 3.9+ compatible
More Guards Coming
The npm package has 31 guards total. Python Phase 2 will add:
- ExternalDataGuard, AgentSkillGuard, SessionIntegrityGuard
- SchemaValidator, ToolResultGuard, TokenCostGuard
Links
- npm package (TypeScript — 31 guards)
- OWASP Top 10 for LLMs 2025
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
llm_trust_guard-0.1.0.tar.gz
(31.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_trust_guard-0.1.0.tar.gz.
File metadata
- Download URL: llm_trust_guard-0.1.0.tar.gz
- Upload date:
- Size: 31.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11c4acb78e241f4e5b4bd874e18fa6b85c950b65d337d038a81e852be6e4d2a2
|
|
| MD5 |
d35dce622d419d29eefb264cdf838b2f
|
|
| BLAKE2b-256 |
413fa9f38d34a772a2b40bb863ab90d4f658b48cf01841eb5e804ac9d9691983
|
File details
Details for the file llm_trust_guard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_trust_guard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
591b5250b6370e15973669f7b6f46319bf88e058e0f98965604d1b3cde4e86e4
|
|
| MD5 |
3bf0f9f7baa2959ea6d65b315d8a221b
|
|
| BLAKE2b-256 |
0992573ec9c2aee08fd8d84366f52f1b889645d72b391ee72dbe3f32518dd0db
|