An OpenAI-compatible proxy that masks personally identifiable information (PII) in LLM requests and responses using Microsoft Presidio.
Following the Presidio pip installation:
# Create and activate virtual environment
python -m venv venv
.\venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/macOS
# Install dependencies
pip install -r requirements.txt
# Download spaCy language model (required by Presidio)
python -m spacy download en_core_web_lguvicorn main:app --reloadAPI docs: http://localhost:8000/docs
| Endpoint | Description |
|---|---|
POST /analyze |
Detect PII entities in text |
POST /anonymize |
Anonymize PII in text |
POST /chat/completions |
OpenAI-compatible chat with PII masking |
curl -X POST http://localhost:8000/analyze \
-H "Content-Type: application/json" \
-d '{"text": "My name is Jane Doe, call me at 212-555-1234"}'curl -X POST http://localhost:8000/anonymize \
-H "Content-Type: application/json" \
-d '{"text": "Contact john@example.com or 555-123-4567"}'curl -X POST http://localhost:8000/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hi, my name is Jane Doe!"}]
}'Flow:
- Request: "Hi, my name is Jane Doe!" → Sent to LLM as: "Hi, my name is [PERSON]!"
- LLM response: "Hey [PERSON], nice to meet you!" → Returned as: "Hey Jane Doe, nice to meet you!"
| Variable | Description |
|---|---|
OPENAI_API_BASE |
Upstream LLM API base URL (default: https://api.openai.com/v1) |
OPENAI_API_KEY |
API key for upstream LLM |
Without OPENAI_API_KEY, the proxy returns mock responses (useful for testing PII masking).
Pass in extra_body or content_safety:
no_pii: true— Disable PII masking for this requestoutput_parse_pii: false— Don't replace placeholders in the response