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>