Skip to content

Ankit-Kumar20/llm-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LLM Proxy with Microsoft Presidio PII Masking

An OpenAI-compatible proxy that masks personally identifiable information (PII) in LLM requests and responses using Microsoft Presidio.

Installation

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_lg

Run the Proxy

uvicorn main:app --reload

API docs: http://localhost:8000/docs

Endpoints

Endpoint Description
POST /analyze Detect PII entities in text
POST /anonymize Anonymize PII in text
POST /chat/completions OpenAI-compatible chat with PII masking

Usage Examples

Analyze PII

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"}'

Anonymize Text

curl -X POST http://localhost:8000/anonymize \
  -H "Content-Type: application/json" \
  -d '{"text": "Contact john@example.com or 555-123-4567"}'

Chat Completions (with PII masking)

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:

  1. Request: "Hi, my name is Jane Doe!" → Sent to LLM as: "Hi, my name is [PERSON]!"
  2. LLM response: "Hey [PERSON], nice to meet you!" → Returned as: "Hey Jane Doe, nice to meet you!"

Configuration

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).

PII Control (per request)

Pass in extra_body or content_safety:

  • no_pii: true — Disable PII masking for this request
  • output_parse_pii: false — Don't replace placeholders in the response

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages