LLM Prompt Sanitization: Preventing PII Leaks
Personally Identifiable Information (PII) includes any data that could uniquely identify a specific individual, such as social security numbers, email addresses, phone numbers, or proprietary API keys.
Pasting raw customer data into third party LLMs (like ChatGPT or Claude) is a massive GDPR compliance violation. This sanitizer utilizes complex RegEx patterns to detect and mask sensitive entities entirely client side, before the prompt ever touches the network.
Core Architecture & Mathematical Formula
Raw Text + RegEx Detectors ➔ MASKED_ENTITY ➔ API Call ➔ Re-injection
The system replaces real emails with placeholders like `[EMAIL_1]`, sends the anonymized text to the AI, and upon receiving the response, automatically swaps the real emails back into the text.
Best Practices & Essential Guidelines
- Never Trust AI Providers with Secrets: Even if an AI provider claims they do not train on API inputs, server side logs can be hacked or subpoenaed. If the data never leaves your browser, it cannot be leaked.
- Sanitize Internal IDs: Beyond just names and emails, ensure you sanitize internal database UUIDs or sequential customer IDs, as these can leak information about your scale or user volume to competitors.
- Review Masked Output Manually: RegEx detection is not perfect. Always visually inspect the sanitized output to ensure a highly non standard email address or formatted phone number did not slip past the filters.