PII redaction for LLMs

PII redaction for LLMs removes or replaces personal identifiers before they enter model context. Apply it to the user prompt and to data added by retrieval or tools. Use placeholders when the model only needs to refer to someone, and keep any mapping used to restore values within the authorised application boundary.

Example

A ticket includes maya.reed@example.com in the description and its reply history. Replace each occurrence with [EMAIL_1] in that processing scope. Keep the product, delivery date and reason for the complaint so the model can recommend the next step.

What to do

  1. Draw the path from the user interface through prompt assembly to the model. Highlight any knowledge-base results, images, files and tool results that can add extra input.
  2. Choose what to remove, replace or keep. Remove fields the model has no reason to see. Use stable placeholders within the task when it needs to tell two records apart.
  3. Mask structured fields by type and inspect free text for identifiers and company-specific strings. Include local phone formats, line breaks and repeated identifiers in your fixtures.
  4. Check the model-bound representation after context has been assembled. Keep restoration mappings and originals scoped to the users and tools that are authorised to receive them.
  5. Measure missed identifiers and wrongly masked fields separately. Add a fixture whenever you discover a format or workflow that the current rule misses.

How to verify

Build a set of fictional inputs with labelled expected replacements. Compare the masked output field by field, confirm repeated placeholders refer to the right record, and run a task check to make sure the result is still useful.

Limits

A combination of facts can still identify a person even after obvious identifiers are replaced. Treat placeholder mappings and source records as sensitive and check each input format you intend to allow.

Frequently asked questions

Where should the redaction happen?
Check every path that contributes to the final model input. In an agent, that often includes both the initial prompt and each later tool result.
Should I remove names or replace them with placeholders?
Remove them if the task needs no reference to the person. Use consistent placeholders if the model needs to distinguish people or preserve their relationships within the task.
How do I test local phone numbers?
Use representative fictional fixtures for the regions and formats your customers use. Include dates, postcodes and order IDs as negative examples so you can catch overmasking.

Spendplane for this workflow

See the masking demo and synthetic benchmark

Start free

Related reading