| Crates.io | leanr-rag-gateway |
| lib.rs | leanr-rag-gateway |
| version | 0.1.0 |
| created_at | 2025-10-25 14:57:02.574421+00 |
| updated_at | 2025-10-25 14:57:02.574421+00 |
| description | Multi-lane RAG gateway with cost routing and verified safety proofs using lean-agentic |
| homepage | https://ruv.io |
| repository | https://github.com/agenticsorg/lean-agentic |
| max_upload_size | |
| id | 1900311 |
| size | 34,792 |
A drop-in gateway for Retrieval-Augmented Generation (RAG) systems that provides formally verified policy enforcement, PII masking, and cost-aware routing.
The gateway supports three routing lanes:
RagQuery → Policy Check → Lane Selection → Retrieval/Generation → PII Masking → Proof Generation → RagResponse
↓ ↓ ↓ ↓
Audit Log Cost/SLA Filter Regex Patterns Claims
```rust use leanr_rag_gateway::{Policy, RagGateway, RagQuery};
// Configure policies let policies = vec![ Policy::allow_user("alice"), Policy::deny_user("mallory"), Policy::mask_pii(), ];
let mut gateway = RagGateway::new(policies);
// Process a query let query = RagQuery { question: "What is our refund policy?".to_string(), sources: vec!["policies.txt".to_string()], user_id: "alice".to_string(), latency_sla: Some(150), cost_budget: Some(0.01), };
match gateway.process(query) { Ok(response) => { println!("Answer: {}", response.answer); println!("Lane: {}", response.metrics.lane_used); println!("Latency: {}ms", response.metrics.latency_ms); println!("Cost: ${:.4}", response.metrics.cost_usd);
// Verify proof certificate
assert!(response.proof.verify());
}
Err(e) => eprintln!("Error: {}", e),
} ```
```bash cargo run --example demo ```
The gateway automatically detects and masks:
Each response includes a proof certificate with:
Example claims:
access_granted(user=alice)pii_masked(answer)sources_authorized(["policies.txt"])cost_within_budget(0.001 <= 0.01)The gateway maintains a comprehensive audit log:
```rust let audit_log = gateway.audit_log(); let report = audit_log.export_compliance_report()?;
println!("Blocked: {}", audit_log.blocked_count()); println!("Successful: {}", audit_log.success_count()); println!("{}", report); ```
Run the test suite:
```bash cargo test -p leanr-rag-gateway ```
All 7 tests validate:
The gateway integrates with the Lean 4 trusted kernel (leanr-core) to provide:
Compiled with optimizations:
Apache-2.0
See CONTRIBUTING.md for development guidelines.