hushspec
Portable specification types for AI agent security rules.
hushspec is the Rust reference implementation of the HushSpec open policy format. It provides parsing, validation, evaluation, resolution, detection, signing, and audit trail capabilities for HushSpec policy documents.
Installation
[]
= "0.1"
Optional features:
# Ed25519 policy signing and verification
= { = "0.1", = ["signing"] }
# HTTPS-based extends resolution
= { = "0.1", = ["http"] }
Quick Start
use ;
// Parse a policy
let yaml = r#"
hushspec: "0.1.0"
name: my-policy
rules:
egress:
allow: ["api.github.com"]
block: []
default: block
"#;
let spec = parse?;
// Validate
let result = validate;
assert!;
// Evaluate an action
let action = EvaluationAction ;
let decision = evaluate;
assert_eq!;
Core API
| Module | Purpose |
|---|---|
schema |
Parse and serialize HushSpec YAML/JSON documents |
validate |
Structural validation with typed errors and warnings |
evaluate |
Evaluate actions against policies (allow/warn/deny) |
resolve |
Resolve extends chains from filesystem, HTTP, or builtins |
merge |
Merge child policies into base policies |
conditions |
Conditional rule evaluation (time windows, runtime context) |
detection |
Prompt injection, jailbreak, and exfiltration detection |
receipt |
Structured audit trail with decision receipts |
sink |
Receipt sinks (file, stderr, callback, filtered, multi) |
panic |
Emergency deny-all kill switch |
signing |
Ed25519 policy signing and verification (feature-gated) |
governance |
Governance metadata validation |
Fail-Closed Design
HushSpec follows a fail-closed philosophy:
- Unknown YAML/JSON fields are rejected at parse time (
deny_unknown_fields) - Invalid documents produce typed
ValidationErrorvalues - Ambiguous or unrecognized rules result in
Deny - All regex patterns are validated at parse time
CLI
The h2h CLI tool is available as a separate crate:
See hushspec-cli for details.
License
Apache-2.0