Crate hanzo_guard

Crate hanzo_guard 

Source
Expand description

§Hanzo Guard

LLM I/O sanitization and safety layer - the “condom” for AI.

Hanzo Guard sits between your application and LLM providers, sanitizing all inputs and outputs to prevent:

  • PII Leakage: Detects and redacts personal identifiable information
  • Prompt Injection: Detects jailbreak and manipulation attempts
  • Unsafe Content: Filters harmful content via Zen Guard models
  • Rate Abuse: Prevents excessive API usage
  • Audit Violations: Logs all requests for compliance

§Quick Start

use hanzo_guard::{Guard, GuardConfig, SanitizeResult};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let guard = Guard::new(GuardConfig::default());

    // Sanitize input before sending to LLM
    let input = "My SSN is 123-45-6789, can you help me?";
    let result = guard.sanitize_input(input).await?;

    match result {
        SanitizeResult::Clean(text) => {
            // Safe to send to LLM
            println!("Clean: {}", text);
        }
        SanitizeResult::Redacted { text, redactions } => {
            // PII was redacted
            println!("Redacted: {} ({} items)", text, redactions.len());
        }
        SanitizeResult::Blocked { reason, category } => {
            // Content blocked
            println!("Blocked: {} ({:?})", reason, category);
        }
    }

    Ok(())
}

§Architecture

┌─────────────┐     ┌──────────────┐     ┌─────────────┐
│ Application │ ──► │ Hanzo Guard  │ ──► │ LLM Provider│
└─────────────┘     │              │     └─────────────┘
                    │ ┌──────────┐ │
                    │ │ PII      │ │
                    │ │ Detector │ │
                    │ └──────────┘ │
                    │ ┌──────────┐ │
                    │ │ Injection│ │
                    │ │ Detector │ │
                    │ └──────────┘ │
                    │ ┌──────────┐ │
                    │ │ Content  │ │
                    │ │ Filter   │ │
                    │ └──────────┘ │
                    │ ┌──────────┐ │
                    │ │ Rate     │ │
                    │ │ Limiter  │ │
                    │ └──────────┘ │
                    │ ┌──────────┐ │
                    │ │ Audit    │ │
                    │ │ Logger   │ │
                    │ └──────────┘ │
                    └──────────────┘

Re-exports§

pub use config::GuardConfig;
pub use error::GuardError;
pub use error::Result;
pub use guard::Guard;
pub use types::*;

Modules§

audit
Audit logging for Guard
config
Configuration for Hanzo Guard
content
Content filtering via Zen Guard API
error
Error types for Hanzo Guard
guard
Main Guard implementation
injection
Prompt injection and jailbreak detection
pii
PII (Personally Identifiable Information) detection and redaction
prelude
Prelude for convenient imports
rate_limit
Rate limiting for Guard
types
Core types for Hanzo Guard