PII redaction for LLM applications is a practical control, not a one-time cleanup task. This guide explains how to identify personal information in logs, support tickets, documents, and evaluation datasets; choose between masking, pseudonymization, synthetic replacement, and deletion; test detection quality; and establish a recurring review process before sensitive text reaches an AI provider.
Overview
Personally identifiable information (PII) is information that can identify a person directly or indirectly. Common examples include names, email addresses, telephone numbers, postal addresses, account identifiers, customer references, device identifiers, and free-form descriptions that reveal personal circumstances. The exact definition and handling requirements depend on your organization, the data context, and the regions in which you operate, so treat this article as an engineering and governance framework rather than legal advice.
The safest default is to minimize sensitive data before it enters an LLM workflow. Redaction should happen as close to the collection point as practical, before text is placed in prompts, retrieved as context, stored in traces, or copied into evaluation datasets. It is also important to inspect outputs and application logs: a prompt may be sanitized while an error message, tool call, or model response still contains the original value.
A reliable workflow has five stages:
- Define which data categories are prohibited, restricted, or permitted.
- Detect structured and unstructured personal information.
- Transform or remove matches according to the use case.
- Test detection, transformation, and restoration behavior where applicable.
- Monitor changes in data sources, providers, code, and model workflows.
Do not assume that a generic text summarizer, keyword extractor, or other AI development tool will reliably remove PII by itself. Use deterministic rules, specialized detection libraries, human review, or a combination of these approaches for higher-risk workflows.
What to track
1. Data categories and locations
Start with a data inventory. Record where text originates, where it is transformed, and where it may be retained. Typical locations include support tickets, chat transcripts, uploaded documents, application logs, prompt traces, vector stores, test fixtures, analytics exports, and manually created evaluation sets.
For each source, record the expected data categories and the acceptable handling method. A support ticket may contain a customer name and email address, while a diagnostic log may contain an account ID, IP address, or copied request body. Free-form text deserves special attention because users may disclose health, financial, employment, authentication, or other sensitive details without using predictable labels.
2. Detection coverage
Track whether your detector can identify at least these test categories:
- Names, including names with titles, initials, accents, and unusual word order.
- Email addresses with common and uncommon domain formats.
- Telephone numbers with country codes, extensions, spaces, and punctuation.
- Postal addresses, including multiline and international formats.
- Account IDs, ticket numbers, customer references, and other organization-specific identifiers.
- Dates, URLs, IP addresses, payment references, and device identifiers when relevant to your application.
- Free-form sensitive content that cannot be found with a simple pattern.
Combine pattern matching with contextual detection. A regular expression can identify an email-like string, but an account ID may only be recognizable from surrounding words or a database-backed format. Conversely, an overly broad rule can flag harmless text and make an LLM prompt less useful.
3. Transformation behavior
Track what happens after a match is found. The replacement should be consistent, understandable to the model, and safe to log. For example, [email protected] might become [EMAIL_001], while a name could become [PERSON_001]. Avoid replacement values that accidentally resemble real people or credentials.
| Method | How it works | Useful when | Main caution |
|---|---|---|---|
| Masking | Replaces part or all of a value with symbols or a category label. | The model only needs to know that a value exists. | It can remove context and may not preserve relationships across messages. |
| Pseudonymization | Replaces a value with a stable token that can be mapped back under controlled conditions. | You need consistent references during a session or evaluation. | The mapping is sensitive and must be separately protected. |
| Synthetic replacement | Substitutes generated, clearly fictional values while preserving useful structure. | Testing workflows that require realistic-looking text. | Generated replacements must not resemble real individuals or secrets. |
| Deletion | Removes the value and, when necessary, nearby context. | The information is unnecessary for the task. | It may reduce task quality or leave grammatically confusing text. |
4. Provider and pipeline settings
Maintain a review record for each LLM provider and processing component. Check the current documentation and your account configuration for data retention, logging, training controls, regional processing, access permissions, deletion behavior, and available administrative settings. These details can change, so do not rely on an old screenshot or an informal assumption.
Also track internal exposure: who can view raw input, sanitized input, prompts, outputs, traces, backups, and redaction mappings? A redaction pipeline is incomplete if the unredacted request is still written to a debug log before the sanitizer runs.
Cadence and checkpoints
Use a scheduled review rather than waiting for an incident. A monthly review suits fast-changing prototypes or applications with frequent data-source changes. A quarterly review may be sufficient for stable systems, provided high-risk changes trigger an immediate check.
At each monthly or quarterly checkpoint
- Sample new inputs: Review a controlled, access-approved sample from every active source. Do not copy raw production text into a public testing tool.
- Run the detection suite: Include positive examples, negative examples, formatting variations, multilingual or regional formats where relevant, and free-form disclosures.
- Inspect transformation output: Confirm that replacements are consistent, reversible only where intended, and free of accidental secrets.
- Review logs and traces: Search for raw emails, phone numbers, names, account IDs, and prompt fragments in operational systems.
- Check provider settings: Compare the current configuration and documentation with your approved data-handling requirements.
- Record exceptions: Document missed detections, false positives, manual overrides, and unresolved risks with an owner and due date.
Repeat the review immediately after adding a new input channel, changing a detector, switching providers, introducing retrieval-augmented generation, changing logging behavior, expanding geographic coverage, or modifying an evaluation dataset. A model update may not change the redaction code, but it can change how much surrounding context appears in prompts and outputs, so test the complete workflow.
Copyable PII review checklist
- Have all current input and output locations been inventoried?
- Are prohibited and permitted data categories documented?
- Are names, emails, phone numbers, addresses, account IDs, and free-form sensitive content in the test suite?
- Are both missed detections and false positives measured or reviewed?
- Is redaction performed before prompts, retrieval, tracing, and third-party calls?
- Can a replacement token reveal information through its format or sequence?
- Is any re-identification mapping isolated, access-controlled, and retained only as needed?
- Are raw inputs excluded from routine logs, analytics, and error reports?
- Have provider settings and current documentation been checked?
- Has an owner recorded the next review date and open exceptions?
Copyable test-case template
ID: PII-001
Category: email | name | phone | address | account_id | free_form
Input: [controlled test text]
Expected detection: yes/no
Expected replacement: [EMAIL_001] or deletion
Context preserved: yes/no
Re-identification allowed: yes/no
Observed result: [record result]
Severity if missed: low/medium/high
Owner and review date: [record details]How to interpret changes
A higher number of detected matches does not automatically mean the system became safer. It may indicate that a new source contains more personal information, a detector became more sensitive, or a formatting change exposed previously unseen cases. Interpret detection results alongside source volume, category, severity, and false-positive rate.
Prioritize missed high-impact data over harmless false positives, but do not ignore excessive false positives. If every identifier is replaced, the model may lose the context needed to resolve a support issue or compare two events. Consider category-specific policies: delete an unnecessary address, use a stable session token for a customer reference, and preserve only a coarse attribute when exact detail is not required.
When a test fails, isolate the stage responsible. The detector may have missed a variation; the transformer may have exposed surrounding text; the logger may have captured the original input; or the provider configuration may not match the approved design. Re-run the same test after each fix and add the failure to the regression suite.
Keep redaction separate from prompt quality work, while testing them together at the application boundary. A sanitized prompt can still produce an inaccurate answer, and a well-engineered prompt can still expose sensitive content. For related controls, see the prompt injection defense guide and the LLM application pre-launch checklist.
When to revisit
Set a recurring monthly or quarterly calendar reminder and assign a named owner. Revisit this article and your implementation whenever you onboard a new dataset, change an LLM provider, add a retrieval source, expand into a new region or language, alter application logging, update a detection library, or rerun privacy tests after a pipeline change.
At the next checkpoint, compare the current data inventory, detector test results, transformation rules, provider settings, access list, and unresolved exceptions with the previous review. Refresh terminology and regional requirements using authoritative internal or external guidance rather than copying old policy language. Keep a short change log so reviewers can see what changed and why.
The practical next step is to create the test cases today, run them at the boundary immediately before the LLM request, inspect logs for leakage, and schedule the next review. Treat PII redaction as a maintained control in your LLM application lifecycle—not as a single preprocessing script—and your team will have a clearer basis for safer experimentation, evaluation, and production use.