Relay had no content controls (recount I19): any prompt went to the provider. relay-guardrails (new crate, tested without TensorZero): - detectors for e-mail, phone (international or North American formatted), payment cards (Luhn), IBANs (mod-97), US SSNs and API secrets (sk-, AKIA, gh*_, xox*, PEM private keys); checksums keep order numbers and amounts; - pii: redact (in place, [REDACTED_KIND], x-relay-guardrails: kind=n on the answer) or block (400 guardrail_blocked, never echoing the data); - operator deny rules (regex + message) and max_prompt_chars; - the policy comes from RELAY_GUARDRAILS_JSON or RELAY_GUARDRAILS_PATH and is validated at startup (bad JSON, unknown fields or a bad regex stop the gateway); without one nothing changes. The gateway adds the layer inside auth and outside spend caps, metering and billing, so a refused prompt never opens a hold or reaches a provider and a redacted one is what billing and the provider see (cargo check -p gateway). Tests: 10 (policy + the axum layer: upstream sees only the redacted body, blocked requests never reach inner layers, other routes/bad JSON/clean prompts untouched, oversized bodies refused). Relay owned crates with a scratch database: 240 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
586 B
TOML
23 lines
586 B
TOML
[package]
|
|
name = "relay-guardrails"
|
|
version = "0.1.0"
|
|
edition = "2021"
|
|
license = "Apache-2.0"
|
|
description = "Relay request guardrails: PII redaction or blocking and operator deny rules, before any hold or provider call."
|
|
|
|
[lib]
|
|
path = "src/lib.rs"
|
|
|
|
[dependencies]
|
|
axum = { workspace = true }
|
|
http-body-util = { workspace = true }
|
|
regex = { workspace = true }
|
|
serde = { workspace = true }
|
|
serde_json = { workspace = true }
|
|
thiserror = { workspace = true }
|
|
tracing = { workspace = true }
|
|
|
|
[dev-dependencies]
|
|
tokio = { workspace = true }
|
|
tower = { version = "0.5.3", features = ["util"] }
|