Workflow: strip PII from a ticket before the AI node, put it back after

I made a small API for this and wanted to share the workflow, since the pattern works in any flow that sends customer text to an LLM.

The flow is three nodes around your AI step:

  1. Scrub PII (HTTP Request, POST /v1/scrub) swaps emails, phone numbers, card numbers, IBANs, US SSNs and common API keys for tokens like [EMAIL_1] and returns a vault object. Cards are Luhn-checked and IBANs mod-97 checked, so a 16-digit order number is left alone.
  2. Your AI step only ever sees the tokenized text.
  3. Restore PII (HTTP Request, POST /v1/rehydrate) takes the AI’s reply plus the vault and puts the real values back, so the email to the customer still has their address in it.

The AI step in the JSON below is a Set node stand-in, so you can import it and click Run with no credentials. Swap it for your OpenAI, Anthropic or AI Agent node and have it write to a field called reply.

What it does not do: it is pattern matching, not a model. It will not catch a person’s name or an address written in plain prose, and it will not catch every custom secret format. JSON payloads go to /v1/scrub-json instead, which also swaps out values under keys like password or api_key.

Disclosure: I am the maker. The hosted API is free for 50 calls a day with no key, and $9/month for 100,000 calls. If you self-host n8n and would rather nothing leave your server, the scrubber is MIT on GitHub (scrubguard-dev/scrubguard) and runs locally.

Site and docs: https://scrubguard-api.scrubguard.workers.dev
Happy to answer questions or fix a pattern it misses.