Skip to content

hanzoai/rust-sdk

Hanzo Rust SDK

CI License

Official Rust SDK for Hanzo AI infrastructure, providing secure key management, post-quantum cryptography, LLM safety, content extraction, and core primitives for building AI applications.

Crates

This workspace contains the following crates:

AI Safety & Content

Crate Description
hanzo-guard LLM I/O sanitization with PII redaction, injection detection, rate limiting
hanzo-extract Content extraction from web/PDF with built-in sanitization

Security & Cryptography

Crate Description
hanzo-kbs Key Broker Service for confidential computing with privacy tiers
hanzo-pqc Post-Quantum Cryptography (ML-KEM, ML-DSA, hybrid modes)

Core Infrastructure

Crate Description
hanzo-message-primitives Core message types and schemas for Hanzo AI systems

Getting Started

Add the desired crates to your Cargo.toml:

[dependencies]
hanzo-guard = "0.1"
hanzo-extract = "0.1"
hanzo-kbs = "0.1"
hanzo-pqc = "0.1"

Examples

LLM Input Sanitization

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

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

    let result = guard.sanitize_input("My SSN is 123-45-6789").await?;

    match result {
        SanitizeResult::Clean(text) => println!("Clean: {text}"),
        SanitizeResult::Redacted { text, .. } => println!("Redacted: {text}"),
        SanitizeResult::Blocked { reason, .. } => println!("Blocked: {reason}"),
    }

    Ok(())
}

Content Extraction

use hanzo_extract::{Extractor, WebExtractor};

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

    // Extract and sanitize web content
    let result = extractor.extract_sanitized("https://example.com").await?;

    println!("Title: {:?}", result.title);
    println!("Text: {}", result.text);

    Ok(())
}

Key Management with Privacy Tiers

use hanzo_kbs::{
    kbs::Kbs,
    kms::{Kms, MemoryKms},
    types::PrivacyTier,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let kms = MemoryKms::new().await?;
    let kbs = Kbs::new(kms);
    
    // Initialize for GPU Confidential Computing
    kbs.initialize_vault(PrivacyTier::GpuCc, None).await?;
    
    Ok(())
}

Post-Quantum Cryptography

use hanzo_pqc::{
    kem::{Kem, KemAlgorithm, MlKem},
    signature::{Signature, SignatureAlgorithm, MlDsa},
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Generate ML-KEM keypair
    let ml_kem = MlKem::new();
    let keypair = ml_kem.generate_keypair(KemAlgorithm::MlKem768).await?;
    
    // Generate ML-DSA keypair
    let ml_dsa = MlDsa::new();
    let (verifying_key, signing_key) = ml_dsa.generate_keypair(SignatureAlgorithm::MlDsa65).await?;
    
    Ok(())
}

Development

# Build all crates
cargo build --all

# Run tests
cargo test --all

# Build for release
cargo build --release --all

Releasing

This monorepo supports per-package releases:

# Release a single package
./scripts/release-package.sh hanzo-kbs 0.1.1

# Release all packages
./scripts/release-package.sh all 0.2.0

See PUBLISHING.md for detailed release instructions.

License

All crates are dual licensed under MIT OR Apache-2.0.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

About

Hanzo AI Rust SDK.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages