Course contentsShow
← AI Engineering
Lesson 1458 of 1,88635. Safety and Content ModerationFree lesson

PII Redaction Strategies

Techniques for removing, masking, or replacing detected PII while maintaining output coherence and utility.

PII Redaction Strategies

What you'll learn: How to safely remove or mask personally identifiable information (PII) from LLM outputs while keeping responses useful and coherent.

The Redaction Challenge

You've detected PII in your model's output—now what? Simply deleting it might break sentences or make responses useless. Like a newspaper redacting classified information, you need strategies that protect privacy while maintaining readability.

Core Redaction Approaches

Complete Removal

Strip the PII entirely and optionally fill the gap:

  • "John Smith lives at..." → "lives at..." (abrupt)
  • "John Smith lives at..." → "[NAME] lives at..." (clearer)

Replacement with Placeholders

Substitute detected PII with generic tokens that preserve sentence structure:

  • Email: john.doe@company.com → [EMAIL] or user@example.com
  • Phone: 555-123-4567 → [PHONE] or XXX-XXX-XXXX
  • Names: Sarah Johnson → [PERSON] or Person A

Partial Masking

Keep format but hide sensitive parts:

  • SSN: 123-45-6789 → XXX-XX-6789
  • Credit card: 4532 1234 5678 9010 → 4532 XXXX XXXX 9010

Semantic Replacement

Replace with plausible alternatives from the same category:

  • john.smith@gmail.com → user123@email.com
  • Alice Martinez → A. M. (initials preserve context)

Choosing the Right Strategy

Match your approach to use case:

  • Logging/debugging: Placeholders preserve structure for analysis
  • User-facing responses: Semantic replacement maintains natural flow
  • Legal compliance: Complete removal may be required

Key Takeaway: Effective PII redaction balances privacy protection with output utility—choose removal, masking, or replacement strategies based on your context, compliance requirements, and user experience needs.