Before sending support tickets, transcripts, logs, or documents to an LLM, use this practical PII redaction workflow to detect sensitive fields, preserve useful context, and restore approved values safely.
Overview
LLM applications often process text that was created for a different purpose: a customer email, an incident report, a voice transcript, a code review comment, or a knowledge-base document. Those inputs may contain names, email addresses, phone numbers, postal addresses, account identifiers, payment references, health details, or other information your application should not send to an external model.
PII redaction for LLMs is the process of finding those values and replacing, removing, or transforming them before inference. The goal is not simply to erase everything that looks personal. Excessive masking can make a prompt unusable, while weak detection can expose information that should have been excluded. A production workflow should therefore balance privacy, task quality, traceability, and operational simplicity.
A useful pipeline is:
- Classify the input: identify its source, sensitivity, language, and intended model task.
- Detect entities: combine pattern rules, structured-field checks, and entity recognition for less predictable data such as names or addresses.
- Apply a defined treatment: remove, mask, generalize, or tokenize each entity according to policy.
- Validate the sanitized text: scan again for missed values and check that the prompt still contains enough context.
- Call the model: send only the minimum necessary representation.
- Restore selectively: substitute original values only in a controlled system after validating the model output.
Redaction is one layer of an LLM privacy workflow, not a substitute for access controls, retention decisions, provider review, encryption, or appropriate legal and compliance assessment. Treat the sanitization service, placeholder map, prompts, outputs, and logs as parts of the same data path.
Checklist by scenario
Customer support and service tickets
- Detect emails, phone numbers, order numbers, customer IDs, addresses, names, and free-form descriptions that may contain additional personal details.
- Use stable placeholders such as
[CUSTOMER_1]and[ORDER_ID_1]when the model needs to distinguish people or records across a conversation. - Keep only the context needed for classification, summarization, or routing. Remove signatures, unnecessary message history, and attachments when they do not affect the task.
- Before restoration, verify that the output is an approved summary or classification rather than arbitrary text that could contain prompt injection or altered identifiers.
Logs, traces, and developer workflows
- Inspect headers, query strings, request bodies, environment variables, authorization values, cookies, IP addresses, and file paths.
- Do not assume that a field named
user_idis harmless. Map identifiers to their actual meaning and sensitivity. - Sanitize before data enters observability systems, prompt caches, evaluation datasets, or error-reporting tools. Redacting only at the model boundary may leave sensitive copies elsewhere.
- For AI-assisted code review, preserve code structure but remove secrets and personal comments that are unrelated to the review. The AI code review workflow should include the same input-sanitization step as any other LLM application.
Documents and retrieval-augmented generation
- Redact before chunking and embedding when the vector store does not need the original values.
- Attach access metadata to each chunk and avoid placing the original text in unrestricted metadata fields.
- Decide whether placeholders should be consistent across a document. Consistency can preserve relationships, but it also creates a linkage risk if the mapping is exposed.
- Test retrieval as well as generation. A sanitized document can still reveal sensitive context through filenames, titles, citations, or nearby text.
For a broader architecture review, compare this step with the ingestion and access-control stages in a RAG chatbot workflow. A vector database comparison should include filtering and operational controls, not only search quality.
Voice notes and transcripts
- Run detection after transcription because spoken names, numbers, and addresses may be normalized inconsistently.
- Account for filler words, spelling variations, homophones, and numbers spoken as words.
- Keep audio and transcript retention separate. Removing text PII does not automatically sanitize the original recording.
- Use a second pass for sensitive categories that speech recognition commonly miswrites, such as account numbers or medication names.
If the application converts recordings into text and then summarizes them, document each boundary in the voice and speech pipeline, including where raw audio, transcripts, and summaries are stored.
Choose masking, removal, or tokenization
Removal is appropriate when the entity has no value to the task. For example, a support-summary prompt may not need a customer’s full signature or personal phone number.
Masking or generalization retains a useful category without exposing the exact value. Examples include [EMAIL], [PHONE], an age range instead of an exact birth date, or a city instead of a full address. This is simple, but it may reduce the model’s ability to reason about relationships.
Tokenization replaces a value with a unique placeholder and stores the original-to-token mapping outside the model boundary. For example, Jordan Lee might become [PERSON_1]. Use tokenization when the application needs consistent references or controlled restoration. The mapping should be encrypted, access-restricted, short-lived where possible, and excluded from prompts, analytics, and ordinary application logs.
Do not restore automatically merely because a placeholder appears in the response. Validate the output against an expected schema, permitted fields, and the original request. For structured workflows, schema validation and permission checks should occur before any restoration or downstream tool call. The principles in this tool-calling guide apply equally to redacted and restored data.
What to double-check
Detection coverage
Build a test set from realistic, approved examples. Include punctuation, spacing, line breaks, casing changes, international formats, transliterated names, multiple languages, OCR errors, and values split across fields. Test emails with unusual but valid formatting, phone numbers with extensions, addresses without postal codes, and identifiers that resemble ordinary numbers.
Measure both false negatives and false positives. A false negative sends sensitive data onward; a false positive may corrupt a legitimate product name, code sample, date, or ticket reference. Review results by entity type rather than relying on one overall score.
Context preservation
Ask whether the model can still complete the task after sanitization. A sentiment classifier may need the message body but not a name. A support agent may need to know that two references belong to the same customer, without knowing the customer’s identity. A summarizer may need dates and sequence but not exact addresses.
Provider and operational boundaries
Confirm where sanitized prompts, outputs, traces, backups, and evaluation examples are stored. Review provider settings and contractual or regional requirements through your organization’s current privacy process rather than assuming that a setting or policy remains unchanged. Minimize data before transmission even when a provider offers controls, because minimization reduces the number of systems that receive the original value.
Observability and failure handling
Log entity types and redaction counts where useful, but avoid logging the original values or the token map. Define what happens when the detector fails, times out, encounters an unsupported language, or produces an uncertain match. A safe default may be to block the request, route it for review, or use a more conservative sanitizer rather than send unverified text.
Common mistakes
- Relying only on regular expressions: Patterns work well for many emails, phone numbers, and identifiers, but names, addresses, and contextual disclosures require additional techniques and review.
- Redacting only obvious fields: A JSON field called
notes, a filename, an email signature, or an error message can contain more PII than the named fields. - Using one placeholder for every person: This removes useful relationships. Prefer stable, scoped tokens when identity distinction matters.
- Keeping the mapping beside the prompt: Store token maps in a separate protected component with limited lifetime and access.
- Restoring into untrusted output: Treat model output as untrusted data. Validate structure, allowed placeholders, and destination before substitution.
- Ignoring downstream copies: Caches, traces, retries, prompt-evaluation datasets, vector stores, and analytics may retain unsanitized input.
- Skipping regression tests: Detection rules can change when libraries, models, parsers, locales, or upstream data sources change. Use a prompt testing and regression process similar to the one described in this prompt testing framework.
When to revisit
Review the redaction workflow before seasonal planning cycles, whenever workflows or tools change, and at a regular privacy review interval chosen by your organization. Revisit it immediately when you add a data source, introduce a new language, change an LLM provider, alter model routing, enable a new logging destination, or begin storing prompts for evaluation.
Use this short release checklist:
- List every input, intermediate, and output location that can contain original or reconstructed data.
- Confirm the current entity policy for names, contact details, addresses, account identifiers, secrets, and regulated fields.
- Run multilingual and messy-input tests, then inspect false positives and false negatives by category.
- Verify that token maps are isolated, access-controlled, encrypted where appropriate, and absent from ordinary logs.
- Test failure behavior, retries, provider fallbacks, caches, and asynchronous queues.
- Check that restoration occurs only after schema, authorization, and output validation.
- Record the review date, owner, changed rules, test results, and next trigger for review.
As your LLM application grows, treat PII redaction as a versioned production component rather than a one-time prompt setting. Pair it with careful model selection, routing, and monitoring; the provider fallback guide and reliability checklist are useful reminders that privacy behavior must remain consistent across every execution path.