Articles

How to redact PII before sending it to an LLM — and restore it after

A working pattern for LLM features on customer data: redact on the way out, restore on the way back, and know exactly where it breaks.

If your product sends customer text to a language model — a support summary, a dispute triage, an agent that reads tickets — the model provider sees whatever you send. The usual fix is to remove sensitive values first. The catch: the model's answer then refers to placeholders, and your user wants their real data back in the reply.

This article shows the full round trip — redact on the way out, send only tokens to the model, restore the real values in the reply — and the places where the pattern needs care.

Why masking alone breaks the round trip

Masking replaces every value with something like [REDACTED]. That is right for logs. It is wrong for an LLM round trip: if a ticket mentions two customers, the model can't tell them apart, and you can't put the right names back into its answer.

You need replacements that are consistent (the same value always gets the same token) and reversible (you can turn tokens back into values).

Two reversible approaches

StrategyWhat the model seesHow you restore
tokenize[EMAIL_1], [CREDIT_CARD_1]send back the token_map you got at redaction
fpea different value in the same formatthe key alone; token_map is empty

Placeholders like [EMAIL_1] are the easiest for a model to reason about. Format-preserving encryption (fpe) keeps values looking real — useful when the text passes through validators or tools that expect a card or an Aadhaar number — and there is no map to keep between the two calls.

The round trip in code

Get a free key with POST /v1/signup, then:

python
import os, requests

API = "https://api.obscate.com"
H = {"x-api-key": os.environ["OBSCATE_API_KEY"]}

ticket = "Ravi Kumar (ravi@example.com) says card 4242 4242 4242 4242 was charged twice."

# 1. Redact before the prompt leaves your service
r = requests.post(f"{API}/v1/redact", headers=H,
                  json={"text": ticket, "strategy": "tokenize"}).json()
# r["redacted"] == "[PERSON_1] ([EMAIL_1]) says card [CREDIT_CARD_1] was charged twice."

# 2. The model only ever sees tokens
reply = call_your_llm("Draft a short reply to this ticket:\n" + r["redacted"])
# e.g. "Hi [PERSON_1], we have refunded the duplicate charge on [CREDIT_CARD_1]."

# 3. Put the real values back, using the map from step 1
restored = requests.post(f"{API}/v1/restore", headers=H,
                         json={"text": reply, "token_map": r["token_map"]}).json()["text"]
# "Hi Ravi Kumar, we have refunded the duplicate charge on 4242 4242 4242 4242."

The map-free variant swaps two lines:

python
r = requests.post(f"{API}/v1/redact", headers=H,
                  json={"text": ticket, "strategy": "fpe"}).json()
assert r["token_map"] == {}          # nothing to store between calls

reply = call_your_llm(r["redacted"])  # card and email are replaced by format-valid values

restored = requests.post(f"{API}/v1/restore-fpe", headers=H,
                         json={"text": reply}).json()["text"]

Treat the token map as sensitive

With tokenize, the token_map holds the original values — it is as sensitive as the text you started with. Keep it in memory for the life of the request, and never write it to logs, queues or analytics. With fpe there is nothing to keep: restoring needs only the key.

Where the pattern needs care

  • Names are best-effort. Structured identifiers are found by checksums and patterns; person names rely on a statistical model. On our synthetic benchmark, person-name detection scores F1 0.80. Add a deny-list for names you already know, and review what gets through.
  • Invented values. If the model invents a new card number or email, key-only restore will transform it as if it were a token. Names and places are not affected, because their tokens are authenticated. Validate model output that will be acted on.
  • Redaction has to see the data. Obscate's hosted API processes the text in memory for the duration of the request and does not store or log it. If your policy says the data must never leave your network, you need detection running inside it — Obscate's self-hosted edition is planned and not yet available.

Checklist

  1. Redact before anything leaves your service: prompts, tool calls and logs.
  2. Use tokenize when the model needs to reason about entities; use fpe when downstream systems validate formats or you don't want to store a map.
  3. Restore only the model's output, and only within the request that produced it.
  4. Add deny-lists for names you know; treat name detection as best-effort.
  5. Never log token maps.

Sources

Try the redact → restore round trip on your own text — no signup.

Get a free API key

Free plan: 1,000 requests a month, all strategies. Your key is shown once — we store only a hash of it.