Hanzo Guard π‘οΈ
The "condom" for LLMs - Sanitize all inputs and outputs between you and AI providers.
Hanzo Guard is a Rust-based safety layer that sits between your application and LLM providers, protecting against:
- PII Leakage: Detects and redacts SSNs, credit cards, emails, phones, API keys
- Prompt Injection: Detects jailbreak attempts and prompt manipulation
- Unsafe Content: Integrates with Zen Guard models for content classification
- Rate Abuse: Prevents excessive API usage per user
- Audit Trail: Comprehensive logging for compliance
Architecture
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Application β βββΊ β Hanzo Guard β βββΊ β LLM Providerβ
βββββββββββββββ β β βββββββββββββββ
β ββββββββββββ β
β β PII β β
β β Detector β β
β ββββββββββββ β
β ββββββββββββ β
β βInjection β β
β β Detector β β
β ββββββββββββ β
β ββββββββββββ β
β β Content β β
β β Filter β β
β ββββββββββββ β
β ββββββββββββ β
β β Rate β β
β β Limiter β β
β ββββββββββββ β
β ββββββββββββ β
β β Audit β β
β β Logger β β
β ββββββββββββ β
ββββββββββββββββ
Quick Start
use ;
async
Installation
[]
= "0.1"
# With all features
= { = "0.1", = ["full"] }
# Minimal (PII only)
= { = "0.1", = false, = ["pii"] }
Features
| Feature | Default | Description |
|---|---|---|
pii |
β | PII detection and redaction |
injection |
β | Prompt injection detection |
rate-limit |
β | Per-user rate limiting |
content-filter |
β | Zen Guard API integration |
audit |
β | Structured audit logging |
full |
β | All features enabled |
Configuration
Builder Pattern
use Guard;
let guard = builder
.full // Enable all features
.with_zen_guard_api_key
.build;
Detailed Configuration
use ;
let config = GuardConfig ;
let guard = new;
PII Detection
Detects and redacts:
| Type | Example | Redaction |
|---|---|---|
| SSN | 123-45-6789 |
[REDACTED:SSN] |
| Credit Card | 4532-0151-1283-0366 |
[REDACTED:Credit Card] |
user@example.com |
[REDACTED:Email] |
|
| Phone | (555) 123-4567 |
[REDACTED:Phone] |
| IP Address | 192.168.1.1 |
[REDACTED:IP Address] |
| API Key | sk-abc123... |
[REDACTED:API Key] |
Prompt Injection Detection
Detects common jailbreak patterns:
- "Ignore previous instructions"
- "DAN mode" / "Developer mode"
- System prompt extraction attempts
- Role-playing manipulation
- Encoding tricks (base64, rot13)
- Context manipulation
let result = guard.sanitize_input.await?;
assert!;
Content Filtering
Integrates with Zen Guard models for content classification:
Safety Levels:
Safe- Content is appropriateControversial- Context-dependentUnsafe- Harmful content
Categories:
- Violent
- Non-violent Illegal Acts
- Sexual Content
- PII
- Suicide & Self-Harm
- Unethical Acts
- Politically Sensitive
- Copyright Violation
- Jailbreak
Context Tracking
Track requests with user/session context:
use ;
let guard = default;
let context = new
.with_user_id
.with_session_id
.with_source_ip;
let result = guard
.sanitize_input_with_context
.await?;
Rate Limiting
Per-user rate limiting with burst support:
let status = guard.rate_limit_status.await;
println!;
Audit Logging
Structured logging for compliance:
Integration with Zen Guard Models
Hanzo Guard can connect to Zen Guard for ML-based content filtering:
let guard = builder
.with_zen_guard_api_key
.build;
Zen Guard Models:
zen-guard-gen-8b- Generative classification (120ms)zen-guard-stream-4b- Real-time token-level (5ms/token)
See zenlm.ai for model details and API access.
Performance
| Operation | Time |
|---|---|
| PII Detection | < 1ms |
| Injection Detection | < 1ms |
| Content Filter (API) | ~120ms |
| Full Pipeline | ~125ms |
Related Projects
- Zen Guard - ML models for content safety
- Hanzo LLM Gateway - Unified LLM proxy
- Hanzo Agent SDK - Multi-agent framework
License
MIT - Hanzo AI Inc
Contributing
Contributions welcome! See CONTRIBUTING.md for guidelines.