Skip to main content

Module safety_policy

Module safety_policy 

Source
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
ClassifierBlock
ClientHooksBlock
PublisherBlock
RulesSummary
SafetyPolicyDescriptor
The sanitized, publishable safety-policy descriptor.
SafetyPolicyPointer

Enums§

CategoryAction
ClassifierHost
EngineFeature
SafetyPolicyError

Constants§

POLICY_WELL_KNOWN_BASE

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).