All posts
PII 11 min read

Redact PII Before Sending Prompts to OpenAI or Anthropic

Two config changes per provider: base URL and one header. What OpenAI and Anthropic keep by default, which identifiers to detect, what fail-closed means.

Elliot Nordin Building SignalVault · Stockholm
On this page · 9 sections

The short answer: put something between your client and the provider that rewrites the request before it leaves, and make two configuration changes per provider, the base URL and one header. Everything else is choosing which identifiers to detect, deciding what happens when one is found, and keeping a record of the decision.

What does not work is relying on the provider's own data controls. OpenAI's no-training default, Anthropic's retention terms and both companies' zero-data-retention programmes decide what the provider keeps. None of them changes what the provider receives. If a Swedish personnummer is in the prompt, it crosses the wire, is processed, and is in scope for every retention exception in the provider's terms. Redaction is the one control that changes the content of the request itself.

This post is the practical companion to our guide to detecting and redacting PII before it reaches an LLM, which covers the architecture and the regulations. Here we do the setup, provider by provider.

What do OpenAI and Anthropic do with your prompts by default?

OpenAI's data usage documentation states that data sent to the API has not been used to train its models since 1 March 2023 unless you opt in. Abuse-monitoring logs are kept for up to 30 days by default, longer where the law requires it or where it is needed to prevent harm. The Responses API also keeps application state for 30 days by default, or when store is true. Zero Data Retention and Modified Abuse Monitoring exclude customer content from those logs, but both are subject to prior approval and additional requirements, arranged through sales. According to its data residency guide, data residency is chosen per project when the project is created, for eligible organizations, and some regions are available only through sales.

Anthropic's API and data retention page says prompts and outputs are not retained by default, with exceptions: a group of "Covered Models" that require 30-day retention and are not eligible for ZDR, batch processing at 29 days, and content flagged by trust-and-safety systems, which may be kept for up to two years even under a ZDR or HIPAA arrangement. ZDR is enabled per organization through the sales team, and a number of features (Files API, batches, code execution, among others) sit outside it by design. The page also states that retained data is never used for training without express permission. Data residency is available on the Messages API through an inference_geo option.

These are contracts and settings, and they change; re-read the pages above before an audit, not this post. More to the point, every one of them operates after the provider has the data. A prompt that never contained the identifier is the only prompt no retention exception applies to.

Where should redaction happen?

There are three places to remove personal data from an LLM request, and they are not equivalent.

A detection library in your application code (Microsoft Presidio is the usual reference) gives you full control and a full maintenance burden: every call site, tool argument and background job has to go through it.

An observability SDK redacts the copy it stores. That protects your logs, but the request still reaches the provider as written.

A proxy that rewrites the forwarded request is the only one of the three that changes what the provider sees, and it covers every call site at once because the client knows one base URL. The rest of this post assumes a proxy.

One pattern you will see in articles that currently rank for this query is "redact, then restore": swap values for numbered tokens, call the model, then put the original values back into the response. It works for demos. In production it means storing a token map, trusting the model not to alter a token, and re-introducing the value on the way back, which is what you were trying to avoid. Typed placeholders such as [REDACTED:pii] with no restore step are enough for most workloads; models handle them well.

What do I need before I start?

Three things, all in the SignalVault dashboard except the last:

  • An app and its SignalVault API key. The key is shown once when you create it; put it in an environment variable such as SIGNALVAULT_API_KEY.
  • A PII rule on that app. Start it on warn, which records what it finds without changing anything, and move it to redact once you have read a few days of results.
  • Your existing OpenAI or Anthropic key. Nothing changes about it: the proxy passes it through for the upstream call.

How do I set it up for OpenAI?

No SDK is needed: the proxy accepts the same requests as OpenAI's API. Send the request you send today to https://api.signalvault.io/proxy/openai/v1/chat/completions instead of https://api.openai.com/v1/chat/completions, and add one header, X-SignalVault-Key. Your OpenAI key stays in the Authorization header; the proxy passes it through for the single upstream call and does not store it.

Here is that request with curl. It is also the quickest way to test the setup before you change any code; -D - prints the response headers:

curl -sS -D - https://api.signalvault.io/proxy/openai/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "X-SignalVault-Key: $SIGNALVAULT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-6-luna", "messages": [{"role": "user", "content": "Reply with OK. My email is anna@example.com"}]}'

With the PII rule on redact, the headers include x-signalvault-decision: redact, and the audit record shows the request as OpenAI received it, with [REDACTED:pii] where the address was.

Any other HTTP client works the same way. In OpenAI's SDKs, the two changes are the base URL and a default header:

# Python, openai >= 1.x
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["OPENAI_API_KEY"],
    base_url="https://api.signalvault.io/proxy/openai/v1",
    default_headers={"X-SignalVault-Key": os.environ["SIGNALVAULT_API_KEY"]},
)
// Node, openai >= 4.x
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: "https://api.signalvault.io/proxy/openai/v1",
  defaultHeaders: { "X-SignalVault-Key": process.env.SIGNALVAULT_API_KEY },
});

Both SDKs also read OPENAI_BASE_URL from the environment, so in a container you can set the base URL without touching code. The header still has to be set in the client.

One limit to know: SignalVault's proxy covers the Chat Completions endpoint (client.chat.completions.create). The Responses API (client.responses.create) is not proxied, so if the same process also calls the Responses API, set the base URL on the client you use for chat completions instead of through OPENAI_BASE_URL.

Two details specific to OpenAI. For streaming, send stream_options: {"include_usage": true}, otherwise the final usage block is absent and the request is recorded with zero tokens. And watch the optional user field, the end-user identifier: it is not part of the prompt and is not rewritten. If the same value also appears in the prompt and a rule redacts it there, a fail-closed proxy should refuse the request rather than forward a half-masked one. SignalVault does, with a request_redaction_guard violation and the reason value_remains. Send an opaque identifier in user, not an email address.

How do I set it up for Anthropic?

The same two changes. Send to https://api.signalvault.io/proxy/anthropic/v1/messages instead of https://api.anthropic.com/v1/messages, keep your x-api-key and anthropic-version headers as they are, and add X-SignalVault-Key:

curl -sS -D - https://api.signalvault.io/proxy/anthropic/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "X-SignalVault-Key: $SIGNALVAULT_API_KEY" \
  -H "content-type: application/json" \
  -d '{"model": "claude-haiku-5-5", "max_tokens": 1024, "messages": [{"role": "user", "content": "Reply with OK. My email is anna@example.com"}]}'

In Anthropic's SDKs the base URL ends at /anthropic, without /v1, because the SDK appends /v1/messages itself:

# Python, anthropic SDK
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["ANTHROPIC_API_KEY"],
    base_url="https://api.signalvault.io/proxy/anthropic",
    default_headers={"X-SignalVault-Key": os.environ["SIGNALVAULT_API_KEY"]},
)
// Node, @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
  baseURL: "https://api.signalvault.io/proxy/anthropic",
  defaultHeaders: { "X-SignalVault-Key": process.env.SIGNALVAULT_API_KEY },
});

ANTHROPIC_BASE_URL works the same way as its OpenAI counterpart.

What matters for redaction on the Anthropic side is the shape of the request. The system prompt is a top-level system field rather than a message, and tool use arrives as tool_use and tool_result content blocks. A proxy has to rewrite all of these; a system prompt that interpolates a customer record is a common way past a redactor that only looks at messages. Anthropic streams carry usage on their own, so there is no stream_options equivalent to remember. Full details of what is rewritten for each provider are in the proxy documentation.

Which identifiers should the rule detect?

Pick by the countries your users are in. A European consumer product should detect email, phone, payment cards, IBAN and the national identity and tax numbers of its markets. The detection reference lists each identifier with the name to use in a rule, an example, and how a match is confirmed.

Confirmation is what separates a usable rule from one your team turns off after a week. A Swedish personnummer is only a match if its date of birth is plausible and its Luhn digit checks out. An IBAN has to have the right length for its country and pass mod-97. A Dutch BSN counts only when it follows the word BSN on the same line and passes the 11-check, because nine digits on their own are usually an order number. Regex without validation flags timestamps and invoice numbers, and a rule that refuses legitimate requests gets disabled.

The identifier list and its checks were extracted into pii_catalog, an open-source Elixir package (Apache-2.0). Its SOURCES.md names the official rule each check was written from, and its README lists the known false positives and misses.

Region names save you from maintaining the list. A rule set to eu picks up the EU identity and tax numbers, EU VAT numbers, IBAN and the Danish, Finnish and Swedish numbers; nordics, gb, ch and us work the same way, and a country code such as se or de narrows it to one country. A region also includes identifiers added later; name identifiers one by one if you prefer a fixed list.

What happens to a request that contains PII?

A rule has an action, and the action decides the outcome.

Under redact, the matched values are replaced in place and the request is forwarded. The provider receives [REDACTED:pii] or [REDACTED:secret] where the value was, the response comes back as usual, and the response carries a header, x-signalvault-decision: redact, so your tests can assert that redaction happened rather than assume it.

Under block, the request never leaves. The client receives HTTP 400 with code: "content_policy_violation" and a violations array naming the rule type and action, in the provider's own error envelope, so the SDK raises its ordinary bad-request error. Block suits values that should never be sent, such as an API key in a coding assistant.

The third outcome is the one to look for when comparing tools: after masking, a fail-closed proxy re-checks the rewritten request against the rules and compares it with the original. If the rule type has nothing to mask, if a match cannot be removed cleanly, or if an exact copy of a masked value still sits somewhere the proxy does not rewrite, the request is refused with HTTP 400 and a reason, and nothing reaches the provider. The same applies when the scan itself cannot finish: a rule scan that exceeds its one-second limit while a block or redact rule is enabled is refused with the reason scan_timeout rather than forwarded unchecked. The same holds for content the rules cannot read: an image, a PDF or another content block the scanner cannot inspect is refused under a block or redact rule, with the reason unscanned_content. Fail-closed means the error path is a refusal, never a quiet pass-through.

Each decision writes an audit record: rule and identifier type, action, app, environment, model, provider, request ID and timestamp. Under a redact rule the stored request is the rewritten one, so the record holds the placeholder and where the match was, never the original value. Our guide to AI audit logging covers what that record is for and how long to keep it. The redaction is the control; the record is the evidence that it ran.

What to do next

  • Write down what you have on the provider side: training default, retention period, whether ZDR or a regional endpoint applies, and the date you checked.
  • Point a staging client at the proxy with the two changes above. Leave the PII rule on warn for a few days and read the violations before enforcing anything.
  • Choose identifiers by region, per application. Add the countries your users are actually in.
  • Switch PII to redact and secrets to block. See how rules and actions combine.
  • Check that user, metadata and any other field the proxy does not rewrite carry opaque IDs, never the values that appear in prompts.
  • Add a test that asserts x-signalvault-decision: redact on a request containing a known test identifier, and one that expects HTTP 400 on a blocked one.
  • Export the audit records once and confirm the people who will ask for them can read the format.

Try it on your own traffic

SignalVault is the proxy described above: two configuration changes, check-digit validation for most Nordic and EU identifiers, redaction in flight, and a refusal when the request cannot be made safe. The free trial lets you point a staging environment at it and see what your current prompts contain before you enforce anything. Start the free trial or read the quickstart.

Or start with what you already have: the log audit reads a JSON Lines log of your model calls and counts the personal data in it by type, with no account needed.

See this on your own traffic

SignalVault sits in front of your OpenAI or Anthropic client with a one-line URL change and writes the trace — tool calls, guardrail decisions and redactions included.

Related reading