Implementation Guide

How to Redact PII Before Sending Prompts to LLM APIs

Redact PII as a runtime control in the request path, not as a library each application adopts on its own. Detect personal data in the full outbound payload, including retrieved documents and tool outputs. Substitute typed placeholders, keep any reversal mapping in a scoped and expiring store, decide explicitly between fail-open and fail-closed, and log redaction events as metadata without raw values.

Why redaction belongs in the request path

Redact PII as a runtime control in the request path, not as a library each application adopts on its own. The request path is where the full assembled payload bound for the OpenAI or Anthropic API can be inspected, so it is where the control can see everything that is actually sent.

Three places to enforce redaction

The enforcement point matters as much as the detector. Placing redaction in the request path, rather than leaving each application to adopt its own library, gives one place to apply policy. Egress can then be restricted to that enforcement point, so direct API calls cannot bypass the control.

Redaction in the request path

The control runs as a sequence of five stages on every outbound request.

  1. DetectScan the full assembled payload, not only the user message.
  2. SubstituteReplace PII with masks or typed placeholders under policy.
  3. ForwardSend the redacted request to the OpenAI or Anthropic API.
  4. Re-hydrateRestore original values only where policy allows.
  5. LogRecord redaction events without storing raw PII.

Detection and substitution tradeoffs

Detect personal data in the full outbound payload, including retrieved documents and tool outputs, not only the user message. Replace what is found with masks or typed placeholders under policy.

Detection quality varies by entity type, so measure false negatives per entity type using a labeled test set built from real prompts, documents, and tool outputs.

Re-hydration, streaming, and tool calls

Keep any reversal mapping in a scoped and expiring store, and restore original values only where policy allows.

Streaming responses need testing at chunk boundaries to confirm that placeholders restore correctly, or not at all, as policy requires. Tool outputs are part of the outbound payload and should be scanned like any other content.

Failure modes, logging, and governance

Decide explicitly between fail-open and fail-closed behavior for detector errors and timeouts, and confirm that the system behaves as the chosen policy states.

Log redaction events as metadata without raw values. Logs, traces, and mapping stores should retain no raw PII beyond its expiry.

Verification checklist

  • Build a labeled test set from real prompts, documents, and tool outputs, and measure false negatives per entity type.
  • Attempt to bypass the control with direct API calls, and restrict egress to the enforcement point.
  • Test streaming responses at chunk boundaries and confirm placeholders restore correctly or not at all, as policy requires.
  • Force detector errors and timeouts and confirm behavior matches the chosen fail-open or fail-closed policy.
  • Inspect logs, traces, and mapping stores to confirm no raw PII is retained beyond its expiry.
  • Re-run the tests when detectors, policies, models, or prompt templates change.

Enforce redaction as a runtime control

See how runtime policy enforcement and audit logging apply to the prompts your agents send to external model APIs.

Request a Demo