Skip to main content
Protect sensitive data automatically before sending to LLMs.
[!IMPORTANT] PII masking is an enterprise privacy feature that detects and masks Personally Identifiable Information (PII) before your data is sent to LLM providers. This is critical for HIPAA, GDPR, and PCI-DSS compliance.

📋 Table of contents


What is PII masking?

PII (Personally Identifiable Information) masking automatically detects and replaces sensitive data with placeholders before sending queries to LLM providers. Example:
The LLM never sees your sensitive data!

Why it matters

The problem

When you send queries to cloud LLM providers (OpenAI, Anthropic, etc.), your data passes through their servers:
Risks:
  • 💳 Credit card numbers exposed
  • 📧 Email addresses harvested
  • 🔢 SSNs leaked
  • 📞 Phone numbers stored
  • 🏥 Medical data (HIPAA violation)

The solution

QWED masks PII before sending to LLMs:
Benefits:
  • HIPAA Compliant (Healthcare)
  • GDPR Compliant (EU Privacy)
  • PCI-DSS Compliant (Finance)
  • Zero Trust architecture

Installation

Step 1: install the PII extra

PII masking requires Microsoft Presidio (optional dependency):

Step 2: download the spaCy model

Presidio uses spaCy for NLP:
Total install size: ~150MB (why it’s optional!)

Verify installation

If installed correctly:

Quick start

Python API

CLI


Supported PII types

QWED detects 9 types of PII using Microsoft Presidio:

Detection examples


Usage examples

Example 1: healthcare (HIPAA)

Scenario: Medical assistant built on an LLM
Benefits:
  • ✅ PHI (Protected Health Information) never sent to cloud
  • ✅ HIPAA compliance maintained
  • ✅ Transparent audit trail in evidence

Example 2: finance (PCI-DSS)

Scenario: Fraud detection system
Benefits:
  • ✅ PCI-DSS Level 1 compliance
  • ✅ Card numbers never in LLM logs
  • ✅ Works with local LLMs (zero cloud exposure)
Scenario: Contract analysis

How it works

Architecture

Detection process

  1. Analyze: Presidio scans text for PII patterns
  2. Detect: Identifies entity types and positions
  3. Mask: Replaces with <ENTITY_TYPE> placeholders
  4. Send: Masked text goes to LLM
  5. Evidence: PII metadata saved for audit

One-way masking

QWED uses non-reversible masking:
  • ✅ Simple and secure
  • ✅ No mapping tables to leak
  • ✅ “Proving without revealing”
Design Decision: Values are permanently masked. We don’t try to “unmask” results.

Configuration

Custom entity types

Only detect specific PII types:

Disable for specific queries

Environment-based


Limitations

1. Detection accuracy

  • False Positives: May mask non-PII (e.g., “john” as name)
  • False Negatives: May miss obfuscated PII
  • Language: English only (v2.2.0)

2. Performance

  • Latency: Adds ~100-200ms per query
  • Memory: Requires ~150MB for spaCy model

3. Context loss

Masked data loses semantic meaning:
LLM might not understand the relationship. Mitigation: Use descriptive masking if needed (future feature).

FAQ

Q: Does PII masking work with Ollama?

A: Yes! In fact, it’s perfect for Ollama:
Your data never leaves your machine:
  • ✅ LLM runs locally
  • ✅ PII masked locally
  • ✅ Zero cloud exposure

Q: What if Presidio isn’t installed?

A: Graceful error with install instructions:

Q: Can I see what was masked?

A: Yes! Check the evidence:

Q: Does it work with caching?

A: Yes! Cached results also include PII info.

Q: What’s the performance impact?

A: Typically 100-200ms added latency. Negligible compared to LLM API call (~1-3s).

Q: Is it secure?

A: Yes:
  • ✅ Runs locally (not a cloud service)
  • ✅ Microsoft Presidio (production-tested at Microsoft)
  • ✅ No data sent to QWED servers
  • ✅ One-way masking (no reverse mapping)

Enterprise use cases

Healthcare: HIPAA compliance

Finance: PCI-DSS compliance


Next steps

  1. Install: pip install 'qwed[pii]'
  2. Test: qwed pii "your sensitive text"
  3. Integrate: Add mask_pii=True to your code
  4. Audit: Check evidence['pii_masked'] for compliance
See the QWEDLocal guide for more examples.