
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
PII redaction is the process of detecting and removing or masking personally identifiable information, such as names, emails, phone numbers, ID numbers and addresses, before data is stored, logged or sent to another system. In LLM applications, it is one of the first controls engineers add when real customer data starts flowing through prompts.
The reason is simple: anything you put into a prompt can end up in logs, in a third-party API, in a vector database or in a model's response. When engineers deploy AI systems inside a client's business, protecting sensitive data is part of the job, not an afterthought. This guide explains what PII redaction is, where it belongs in an LLM pipeline and how to implement it step by step.
What counts as PII?
The U.S. National Institute of Standards and Technology defines PII in NIST SP 800-122 as information that can be used to distinguish or trace an individual's identity, alone or combined with other information. In Europe, Article 4 of the GDPR uses the broader concept of “personal data”: any information relating to an identified or identifiable person.
In practice, LLM teams usually look for:
Direct identifiers: full names, email addresses, phone numbers, national ID or passport numbers, account numbers.
Financial and health data: credit card numbers, bank details, medical information.
Quasi-identifiers: date of birth, postal code, job title plus employer — harmless alone, identifying in combination.
Secrets that are not PII but behave like it: API keys, passwords and access tokens pasted into chats or tickets.
Why LLM applications need PII redaction
The OWASP Top 10 for LLM Applications lists sensitive information disclosure as a key risk: LLMs can expose personal data, proprietary information or credentials through their outputs, and data sent to models can be retained or reused in ways the user did not expect. Redaction reduces that risk at several points:
Third-party model APIs. Sending less personal data to external providers reduces exposure and simplifies compliance reviews.
Logs and traces. Observability tools often store full prompts and responses. Unredacted logs become a second copy of your customer database.
RAG indexes. Documents with personal data, once embedded into a vector store, can be retrieved for the wrong user.
Fine-tuning and evaluation datasets. Personal data in training sets can be memorized and reproduced.
Redaction, masking and pseudonymization
Redaction
The sensitive value is removed or replaced with a generic tag, for example [EMAIL]. It is the safest option, but the model loses the original value.
Masking
Part of the value is hidden, such as showing only the last four digits of a card. Useful when a person needs partial context.
Pseudonymization (reversible tokens)
Each value is replaced with a consistent placeholder like <PERSON_1>, and the mapping is stored securely outside the model. The LLM can still reason about “the same person” across a conversation, and the application restores real values in the final response only when the user is authorized to see them.
How to implement PII redaction in an LLM pipeline
1. Map where data flows
List every path personal data can take: user input, uploaded files, retrieved documents, tool and API responses, logs, analytics and model outputs. Redaction is only as strong as the path you forgot.
2. Detect PII with layered methods
Combine pattern rules (regular expressions with checksums for emails, phone numbers and card numbers) with named entity recognition for names, locations and organizations. Open-source frameworks like Microsoft Presidio provide analyzers and anonymizers that you can extend with custom recognizers for local ID formats or internal account numbers.
3. Redact before the model and before the logs
Run detection on inputs before they reach the LLM and on everything you write to logs or traces. Treat this as a boundary: a single service or middleware that every request passes through is easier to audit than redaction scattered across the code.
4. Scan outputs too
Models can echo personal data from retrieved context or tool results. A final output check catches leaks before a response reaches the user or another system. This works alongside other AI guardrails such as topic filters and policy checks.
5. Restore values only where needed
If you use reversible tokens, keep the mapping in a secure store with short retention and access controls, and rehydrate values only in the final step for authorized users.
6. Test and measure detection quality
Build a labeled test set with realistic examples in every language and format your client uses. Measure recall (how much PII you catch) and precision (how much normal text you wrongly remove). Missed PII is a security problem; over-redaction makes answers useless.
Common mistakes
Only redacting user input. Retrieved documents, tool responses and logs leak just as easily.
Assuming English-only patterns. Phone, ID and address formats vary by country; test with local data.
Relying on the prompt. Telling the model “do not reveal personal data” is not a control. Instructions can be bypassed, as explained in our guide to prompt injection.
Forgetting retention. Even redacted data should have clear retention limits.
FAQ
Is PII redaction enough for compliance?
No. It is one technical control. Compliance also involves legal basis, consent, data processing agreements, retention policies and access controls. Redaction makes those obligations easier to meet.
Can an LLM detect PII by itself?
LLMs can help classify ambiguous cases, but sending raw data to a model to find PII defeats part of the purpose. Most teams run deterministic and NER-based detection first and use models selectively.
Does redaction hurt answer quality?
Sometimes. Pseudonymization with consistent placeholders usually preserves enough context for the model to reason correctly while keeping real values out of the prompt.
Keep learning with Coderhouse
Protecting client data is part of shipping AI systems that companies can trust. If you want to learn how to build, secure and deploy production AI applications inside real businesses, start with the Forward Deployed AI Engineering Course. You can also explore the other two paths:
Data Analytics Course — learn to work with real business data responsibly, from SQL to dashboards.
GTM Engineer Course (waitlist) — join the waitlist for early access to the program on automating go-to-market systems with CRM data and AI.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.