hanzo_guard/
lib.rs

1//! # Hanzo Guard
2//!
3//! LLM I/O sanitization and safety layer - the "condom" for AI.
4//!
5//! Hanzo Guard sits between your application and LLM providers, sanitizing
6//! all inputs and outputs to prevent:
7//!
8//! - **PII Leakage**: Detects and redacts personal identifiable information
9//! - **Prompt Injection**: Detects jailbreak and manipulation attempts
10//! - **Unsafe Content**: Filters harmful content via Zen Guard models
11//! - **Rate Abuse**: Prevents excessive API usage
12//! - **Audit Violations**: Logs all requests for compliance
13//!
14//! ## Quick Start
15//!
16//! ```rust
17//! use hanzo_guard::{Guard, GuardConfig, SanitizeResult};
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//!     let guard = Guard::new(GuardConfig::default());
22//!
23//!     // Sanitize input before sending to LLM
24//!     let input = "My SSN is 123-45-6789, can you help me?";
25//!     let result = guard.sanitize_input(input).await?;
26//!
27//!     match result {
28//!         SanitizeResult::Clean(text) => {
29//!             // Safe to send to LLM
30//!             println!("Clean: {}", text);
31//!         }
32//!         SanitizeResult::Redacted { text, redactions } => {
33//!             // PII was redacted
34//!             println!("Redacted: {} ({} items)", text, redactions.len());
35//!         }
36//!         SanitizeResult::Blocked { reason, category } => {
37//!             // Content blocked
38//!             println!("Blocked: {} ({:?})", reason, category);
39//!         }
40//!     }
41//!
42//!     Ok(())
43//! }
44//! ```
45//!
46//! ## Architecture
47//!
48//! ```text
49//! ┌─────────────┐     ┌──────────────┐     ┌─────────────┐
50//! │ Application │ ──► │ Hanzo Guard  │ ──► │ LLM Provider│
51//! └─────────────┘     │              │     └─────────────┘
52//!                     │ ┌──────────┐ │
53//!                     │ │ PII      │ │
54//!                     │ │ Detector │ │
55//!                     │ └──────────┘ │
56//!                     │ ┌──────────┐ │
57//!                     │ │ Injection│ │
58//!                     │ │ Detector │ │
59//!                     │ └──────────┘ │
60//!                     │ ┌──────────┐ │
61//!                     │ │ Content  │ │
62//!                     │ │ Filter   │ │
63//!                     │ └──────────┘ │
64//!                     │ ┌──────────┐ │
65//!                     │ │ Rate     │ │
66//!                     │ │ Limiter  │ │
67//!                     │ └──────────┘ │
68//!                     │ ┌──────────┐ │
69//!                     │ │ Audit    │ │
70//!                     │ │ Logger   │ │
71//!                     │ └──────────┘ │
72//!                     └──────────────┘
73//! ```
74
75pub mod audit;
76pub mod config;
77pub mod content;
78pub mod error;
79pub mod guard;
80pub mod injection;
81pub mod pii;
82pub mod rate_limit;
83pub mod types;
84
85pub use config::GuardConfig;
86pub use error::{GuardError, Result};
87pub use guard::Guard;
88pub use types::*;
89
90/// Prelude for convenient imports
91pub mod prelude {
92    pub use crate::config::GuardConfig;
93    pub use crate::error::{GuardError, Result};
94    pub use crate::guard::Guard;
95    pub use crate::types::*;
96}