How it works
- After policy checks and the prompt injection firewall, the gateway runs the configured detector over every message’s text content,
prompt,inputand the arguments of tool calls. - Each finding is replaced in place. Without a vault key the replacement is
[REDACTED:<TYPE>]. With a vault key it is a numbered token such as[PII_1], and the original value is stored encrypted beside the request trace. - Everything downstream sees only the redacted text: input guardrails, the cache key, the provider, the audit log and exported trace spans.
- When the model answers, the completion text and the arguments of its tool calls are scanned too. What reaches your client depends on the model’s
pii_output_mode.
Configuration
Key fields
builtin runs the in-process regex detector. http calls your detection sidecar at pii.http_url. off disables detection entirely. Any other value stops startup.Version name to base64-encoded 32-byte AES-256 key. Standard or URL-safe base64, with or without padding. A key that is not exactly 32 bytes stops startup rather than silently falling back to one-way redaction. Version names are 1–32 letters, digits,
- or _.How the completion is handled. See Outbound PII. It can be set only on models declared in
gateway.yaml; models registered through the console or a workspace are always passthrough.gateway.yaml and the environment, so a change needs a restart.
Detectors
Built-in entities
When two matches overlap, the entity higher in this table wins, so an IBAN’s digits are not also reported as a phone number.
HTTP sidecar
Withdetector: http the gateway sends each text to your service and redacts the spans it returns. Use this for NER-grade detection (names, addresses, other languages).
start and end are byte offsets into text; spans outside the text are ignored. entity_type becomes the <TYPE> in the placeholder. The call times out after 10 seconds, and any non-200 status is treated as a detection failure.
Outbound PII
The completion text is always scanned and the redacted copy is what the audit log and the cache store.pii_output_mode decides what the client receives:
If any output guardrail applies to the request, the response is buffered and redacted exactly as in
buffer mode, whatever pii_output_mode is, and time to first token becomes time to last token.
In buffer mode, and whenever output guardrails force buffering, a detector failure on the completion leaves the client with an empty response rather than the unredacted text. If the arguments of a tool call cannot be checked, the request is refused with a 500.
Output redaction is always one-way; the vault applies only to the request.
Reversible redaction
With a vault key configured, each redacted value is encrypted with AES-256-GCM and stored alongside the trace, bound to its organization, trace, token and position. This covers gateway redaction ([PII_n]) and, on the request side (llm_input) only, value-replacing guardrails: a pii guardrail in placeholder mode issues [PII_n], a mutating secrets guardrail [SECRET_n] and a mutating regex guardrail [REGEX_n]. Masks and other rewrites, such as stripped SQL comments, are recorded as before/after pairs, and Show original restores them as well. Values are stored only when the request body itself is recorded (see Request Logging); a request sent with X-ManyLayers-Store-Logs: false keeps no values.
1
Generate a key
pii.vault in the YAML.2
Reveal an original
A caller holding
gateway.traces.sensitive.read (Gateway admins by default) opens a trace in Request Traces and selects Show original, or calls the API:$TRACE_ID is the X-ManyLayers-Trace-Id response header of the original request. The response holds id, request_body (tokens replaced by their values) and restored (how many tokens and rewrites were undone), and is sent with Cache-Control: no-store. Every attempt, allowed or denied, is written to the organization’s access log.Rotate the vault key
Rotate the vault key
Add a new version and make it current:
MANYLAYERS_PII_VAULT_KEYS="v1:<old>,v2:<new>" and MANYLAYERS_PII_VAULT_KEY_VERSION=v2, then restart. New values are sealed with v2; existing values keep decrypting with v1. Remove v1 only after every trace it sealed has aged out of audit retention — a removed version makes its values unreadable.Why Show original can refuse
Why Show original can refuse
The endpoint returns
409 not_reconstructable rather than a possibly wrong original when the caller’s own text already contained a [PII_n]-shaped string, when two rewrites left identical text from different originals, or when the stored body no longer matches its recorded changes. It returns 404 when the body was not recorded or nothing was redacted reversibly, and 503 pii_vault_not_configured when the service has no key.Redaction for logs only
Redaction for logs only
To keep prompts intact for the model but scrub the stored copy, set
pii.detector: off and add a logging config with redaction.pii: true. See Request Logging.Gateway redaction runs before every guardrail. A
pii guardrail adds category-level control per workspace and rule; both can run together, and the guardrail sees the already-redacted text.Next steps
Guardrails
Add per-workspace PII, secrets and regex checks on input and output.
Request Logging & Audit
Control which bodies are stored and how they are redacted.
Caching
How redacted requests form cache keys.
Prompt Injection Firewall
The check that runs just before redaction.