Guide / Privacy

Redact before the prompt, not after the leak

Support tickets, emails and CRM notes are the most useful context you can give a model, and the most dangerous thing you can paste into one. Here is where the data actually escapes and how to stop it without wrecking the answer.

Four places the text ends up

  • Your own logs. The request body that built the prompt is usually logged, and logs outlive their purpose by years.
  • The provider's retention window. Most APIs keep requests for a period for abuse monitoring, and some train on what you send unless you opt out.
  • Prompt evaluation tools, if you fan out to several models or log completions for review.
  • Your database. The completion gets stored, and a completion often quotes the input back.

You rarely need the raw values after the request is served. You need the model to understand that a card number is present, and you need the record to remain joinable to the customer. Both are possible without sending the value.

Redact, but keep the shape

Replacing everything with asterisks destroys the answer: the model cannot tell an email from a card, and cannot tell whether two mentions are the same person. Labelled placeholders solve both.

curl -s -X POST 'https://piishield.p.rapidapi.com/v1/redact' \\
  -H 'Content-Type: application/json' \\
  -H 'X-RapidAPI-Key: YOUR_KEY' \\
  -H 'X-RapidAPI-Host: piishield.p.rapidapi.com' \\
  -d '{"text":"Hi, I am Jane Doe, jane@acme.com, card 4111 1111 1111 1111","style":"label"}'

With style: "label" the same value becomes the same token everywhere: [EMAIL_1] twice stays one entity, [EMAIL_2] is a different person. The model can still reason about "the card ending in 1111 was declined and the customer at [EMAIL_1] asked twice".

The three styles, and when each is right

StyleOutputUse when
mask************1111a human needs the last four to verify identity
label[CREDIT_CARD_1]the model must follow entities across a conversation
hash[EMAIL_a3f19c02]you need to join records later without storing the value

The restore pattern

If your product has to show the original value back to the customer, keep the mapping on your side and never send it to the model.

const scan = await fetch('https://piishield.p.rapidapi.com/v1/scan', { ... });
const { findings } = await scan.json();

// build the placeholder map locally
const map = new Map();
let text = input;
for (const f of findings.sort((a, b) => b.start - a.start)) {
  const token = '[' + f.type + '_' + (map.size + 1) + ']';
  map.set(token, f.value);
  text = text.slice(0, f.start) + token + text.slice(f.end);
}

// send only the redacted text, then restore what you display
const answer = await askTheModel(text);
const restored = answer.replace(/\[[A-Z_]+_\d+\]/g, (t) => map.get(t) ?? t);

Note the reverse-order splice: replacing from the end keeps the earlier offsets valid. Doing it forwards is the classic off-by-N bug.

What the detectors actually catch

Structured data is reliable and checksummed: emails, phone numbers, cards with Luhn, IBANs with mod-97, IPs, JWTs, API keys, crypto wallets, MAC addresses. Freeform data is not: names and addresses are pattern shapes, so they carry lower confidence and can miss unusual formats.

That is why every finding comes with an offset and a confidence score. Review the low-confidence band instead of trusting one pass, and never treat redaction as a guarantee.

Cost of getting this wrong

A single card number in a log is a PCI incident. A customer's email in a prompt sent to a provider that trains on inputs is a disclosure you cannot retract. Neither is hypothetical, and both are cheap to prevent at the boundary.

Try it on your own text

The demo runs the real endpoint, ten calls per visitor per day, no key needed.

Open the redactor API reference