Skip to main content

The ngrok for PHI. HIPAA-compliant wrappers for LLM APIs.

Project description

Redact Proxy

The ngrok for PHI.

Drop-in replacements for OpenAI, Anthropic, and Gemini SDKs that automatically redact PHI before sending to the API. Helps keep PHI out of LLM calls.

You still use your existing OpenAI/Anthropic/Gemini API keys. Redact Proxy runs locally—no Redact API keys, no signup, no data leaves your machine except to your chosen LLM provider.

Installation

# Basic (OpenAI + fast detection)
pip install redact-proxy

# With additional providers
pip install redact-proxy[anthropic]
pip install redact-proxy[gemini]

# With enhanced detection
pip install redact-proxy[balanced]   # Adds Presidio NER
pip install redact-proxy[accurate]   # Adds transformer model

# Everything
pip install redact-proxy[all]

Limitations

⚠️ USA / HIPAA focus: Detection patterns are optimized for US healthcare data—US date formats, SSNs, US phone numbers, Medicare/Medicaid IDs, and US facility names. European identifiers (NHS numbers, EU formats, GDPR-specific PII) are not currently supported.

⚠️ Not a guarantee: This tool reduces risk but does not eliminate it. False negatives are possible. It does not provide BAAs, does not secure your application logs, and is not a substitute for a full compliance program.

Quick Start

OpenAI

# Before (PHI may be sent to LLM)
from openai import OpenAI

# After (PHI redacted locally before sending) - just change the import!
from redact_proxy import OpenAI

client = OpenAI(phi_detection="fast")

# Same API, PHI automatically redacted
response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "user", "content": "Patient John Smith, DOB 01/15/1980, has diabetes"}
    ]
)
# OpenAI receives: "Patient [NAME], DOB [DATE], has diabetes"

Anthropic

from redact_proxy import Anthropic

client = Anthropic(phi_detection="fast")

response = client.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Patient John Smith has diabetes"}
    ]
)

Gemini

from redact_proxy import Gemini

client = Gemini(phi_detection="fast")

response = client.generate_content(
    "Patient John Smith has diabetes"
)

# Or use chat
chat = client.start_chat()
response = chat.send_message("Patient John Smith has diabetes")

How It Works

  1. Detect — Scans your message for PHI (names, dates, SSNs, etc.) using pattern matching and optional NER
  2. Replace — Substitutes PHI with placeholders like [NAME], [DATE], [SSN]
  3. Forward — Sends the redacted request to your LLM provider using your existing API key

All processing happens locally. The LLM never sees the original PHI.

Detection Modes

Mode Speed Method Use Case
fast ~1-5ms Regex patterns Real-time chat, most users
balanced ~20-50ms Patterns + Presidio NER Better name detection
accurate ~100-500ms Patterns + Presidio + Transformer Batch processing, high-risk
# Choose your mode
client = OpenAI(phi_detection="fast")      # Default - fastest
client = OpenAI(phi_detection="balanced")  # Better accuracy
client = OpenAI(phi_detection="accurate")  # Best accuracy

PHI Types Detected

  • Names: Patient, provider, family member names
  • Dates: DOB, visit dates, all date formats
  • Ages: All age formats (65 y/o, 65-year-old, etc.)
  • SSN: Social Security Numbers
  • MRN: Medical Record Numbers
  • Medicare/Medicaid IDs
  • Phone/Fax numbers
  • Email addresses
  • Addresses: Street, city, state, ZIP
  • URLs and IP addresses
  • Facilities: 5,286 US hospitals + 12,130 skilled nursing facilities (from CMS)

Advanced Usage

Custom Placeholder

client = OpenAI(
    phi_detection="fast",
    redact_placeholder="<REDACTED:{phi_type}>"
)
# Output: "Patient <REDACTED:NAME> has diabetes"

Direct Detection

from redact_proxy import PHIDetector

detector = PHIDetector(mode="fast")

# Just detect
findings = detector.detect("Patient John Smith, DOB 01/15/1980")
for f in findings:
    print(f"{f.phi_type}: {f.text} (confidence: {f.confidence})")

# Detect and redact
redacted_text, findings = detector.redact("Patient John Smith, DOB 01/15/1980")
print(redacted_text)  # "Patient [NAME], DOB [DATE]"

Why Redact Proxy?

  1. One-line migration: Just change your import
  2. Zero infrastructure: Works entirely locally
  3. Fast: Pattern-based detection in milliseconds
  4. Configurable: Choose speed vs accuracy tradeoff
  5. Comprehensive: Covers all 18 HIPAA Safe Harbor identifiers

Security Model

  • Where redaction happens: In-process, in your application's memory. No external service calls.
  • What leaves your machine: Only the redacted text goes to the LLM provider. Original PHI stays local.
  • PHI↔placeholder mapping: Stored in memory only, per-request. Not persisted to disk. Cleared after request completes.
  • Logging: Disabled by default. If you enable debug logging, ensure logs are stored securely.
  • Threat model: This tool redacts PHI from LLM API calls. Your application's own logs, error traces, analytics, and caches can still leak PHI—review your full data flow.

Common Pitfalls

These scenarios can leak PHI even when using Redact Proxy:

Pitfall Risk Mitigation
Streaming responses PHI in streamed chunks bypasses redaction Redact after full response is assembled
Tool/function calling Function arguments may contain PHI Redact tool inputs before passing to LLM
Retries & error handling Stack traces expose PHI in variables Scrub exceptions before logging
Background jobs Async workers may bypass the proxy Use Redact Proxy in worker code too
Prompt caching Cached prompts aren't re-redacted Cache only redacted prompts
LLM response content Model may echo back inferred PHI Review responses if PHI context was provided

Framework Examples

FastAPI

from fastapi import FastAPI, Request
from redact_proxy import OpenAI

app = FastAPI()
client = OpenAI(phi_detection="fast")

@app.post("/chat")
async def chat(request: Request):
    body = await request.json()

    response = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": body["message"]}]
    )

    return {"response": response.choices[0].message.content}

Next.js API Route

// app/api/chat/route.ts
import { NextRequest, NextResponse } from 'next/server';

export async function POST(request: NextRequest) {
  const { message } = await request.json();

  // Call your Python backend with Redact Proxy
  const response = await fetch('http://localhost:8000/chat', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ message }),
  });

  const data = await response.json();
  return NextResponse.json(data);
}
# Python backend (FastAPI) - handles the actual LLM call
from redact_proxy import OpenAI

client = OpenAI(phi_detection="fast")

# ... same as FastAPI example above

License

MIT

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redact_proxy-0.1.5.tar.gz (167.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redact_proxy-0.1.5-py3-none-any.whl (165.1 kB view details)

Uploaded Python 3

File details

Details for the file redact_proxy-0.1.5.tar.gz.

File metadata

  • Download URL: redact_proxy-0.1.5.tar.gz
  • Upload date:
  • Size: 167.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for redact_proxy-0.1.5.tar.gz
Algorithm Hash digest
SHA256 bb3f8484d42ff625ee8cbe1a59725364e0fddad902992a32e7deeaa63b26149e
MD5 61949803b89bbddfc18db3f7f9dbe30d
BLAKE2b-256 6da00cdebd61d77a87e292a071f6610dcd41ed72a1c24991a23e7a5ba797d974

See more details on using hashes here.

File details

Details for the file redact_proxy-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: redact_proxy-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 165.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for redact_proxy-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 15effd24f9b2600513419d44dc7383e509da77ce0df057fca7bfe88981af9e51
MD5 99372a48d0abe678b1a0597d8c827ec9
BLAKE2b-256 8ac9a1fdd55e0799a8be4d05cf1dd054b463f3dbe224c52b0c1c27b8d698a1d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page