Expand description
Safety-policy descriptor loading, validation, and discovery.
Rust twin of @codecai/web’s safety_policy.ts (slice 1) and
codecai.safety_policy (slice 11). Same shapes, same errors, same
canonical JSON form for hashing — a descriptor that hashes to
sha256:abc… in any client hashes to the identical digest here.
Used by clients that received safety_policy_id + safety_policy_hash
in READY and want to fetch and surface what the server is
enforcing. The descriptor is the sanitized, publishable shape —
categories, actions, classifier family, summary stats — never the
operator’s internal banned token IDs / classifier thresholds /
regex patterns.
Discovery follows the existing tokenizer-map convention:
<origin>/.well-known/codec/policies/<id>.json(mutable)<origin>/.well-known/codec/policies/sha256/<hex>.json(immutable)
A client that received a hash in READY SHOULD prefer the
content-addressed sibling — it’s provably immutable and skips the
mutable indirection.
Structs§
- Category
- Classifier
Block - Client
Hooks Block - Publisher
Block - Rules
Summary - Safety
Policy Descriptor - The sanitized, publishable safety-policy descriptor.
- Safety
Policy Pointer
Enums§
Constants§
Functions§
- discover_
safety_ policy - Resolve a safety-policy descriptor via
.well-known/codec/policies/. - load_
safety_ policy - Fetch + verify + cache a safety-policy descriptor.
- validate_
safety_ policy - Validate a parsed JSON value as a SafetyPolicyDescriptor candidate.
- well_
known_ policy_ hash_ url - Content-addressed URL by sha256 hex (no
sha256:prefix). - well_
known_ policy_ url - Per-policy URL by mutable id (e.g.
acme/strict-v3).