LLM Sanitizer
A local privacy gateway for AI traffic. Before your AI agent (Codex, WorkBuddy, OpenClaw, Claude Code, Cline…) sends local files to a cloud LLM, LLM Sanitizer automatically replaces sensitive information — names, ID numbers, phone numbers, addresses, court names — with placeholders like [姓名_1]; on the way back it restores them precisely, and a live dashboard shows you exactly what was masked.
Primary audience: lawyers, legal professionals, and anyone who hands local documents to an AI agent and worries about data leakage.
Project Status
v0.2/v0.3/v0.4 released · v0.5 in progress. Local gateway, 15 Chinese-sensitive-data categories, live console, CLI, auto-start installer and CI are all in place —
pip install llm-sanitizer-gatewayto get started. Shipped: WebSocket proxy, one-click integration, all three protocols, docx/xlsx/pdf masking, Windows, image OCR; v0.5 adds org policy / audit export, desktop window, standalone executable. Contributions welcome.
Why
AI agents read local files (Word, Excel, PDF…) and send their contents to cloud models. Names, ID numbers, and court names leave your machine without you noticing. LLM Sanitizer adds a local gate before that happens:
Agent → [local gateway: mask] → cloud (sees only [姓名_1] placeholders)
Agent ← [local gateway: restore] ← cloud
↑
live dashboard: watch every mask event
Features
- Local-first gateway — listens on
127.0.0.1only; no system proxy, no certificates, no global traffic interception - Chinese-sensitive-data rules — ID numbers (with checksum validation), phone/landline, email, unified social credit codes, court & prosecutorial office names, names (context-aware), addresses, dates of birth
- Consistent, restorable tokens —
[姓名_1]-style placeholders persist across requests and restarts (map.json), restored exactly on the way back - SSE streaming support — handles token fragments split across network chunks
- All protocols — OpenAI (Responses/Chat) passthrough plus native adapters for Anthropic (Claude Code) and Google (Gemini); every mainstream model works per protocol (OpenAI-compatible: GPT/DeepSeek/Zhipu/Kimi/Qwen/Doubao/Groq/OpenRouter/local vLLM·Ollama…; Claude; Gemini) — see dev doc §8.2
- Zero third-party dependencies — pure Python standard library
- Live dashboard — real-time view of what was masked (placeholders only, never plaintext)
- Extensible — custom rules, custom word lists, new agents and document formats (see Extending)
Install
# Preferred:
pip install llm-sanitizer-gateway
llm-sanitizer start
# Source mode:
git clone https://github.com/JunyuZhan/llm-sanitizer.git
cd llm-sanitizer
python3 -m llm_sanitizer start
That's it. Two services come up:
- Gateway:
http://127.0.0.1:8790/v1— point your agent'sbase_urlhere - Dashboard:
http://127.0.0.1:8791— open in a browser to watch masking in real time
Requirements: Python 3.9+ on macOS / Linux / Windows (since v0.3).
Quick start
-
Configure the upstream (defaults to
https://api.openai.com/v1):export LLM_SANITIZER_UPSTREAM="https://api.deepseek.com" # your LLM provider export LLM_SANITIZER_KEY="sk-..." # your API key (optional if the agent already sends one)
-
Start the gateway:
python3 -m llm_sanitizer start
-
Point an agent at it — any OpenAI-compatible client works by setting
base_url = http://127.0.0.1:8790/v1. Step-by-step guides for Codex, WorkBuddy, and OpenClaw are in Agent integration. -
Verify it works: send a test message like
申请人张三,电话 13912345678from your agent, then open the dashboard — you should see new mask events appear within seconds.
Full walkthrough, configuration reference, upgrade & uninstall: Quick start.
How it works
| Stage | Data | Where it goes |
|---|---|---|
| Agent → gateway | raw request (conversation / file content) | in-memory only, masked then forwarded |
| Gateway → upstream | masked placeholder text | your configured LLM provider |
| Upstream → gateway | model response | restored locally, sent back |
| Gateway → dashboard/events | placeholders, categories, timestamps, paths | local JSONL, no plaintext |
map.json |
plaintext ↔ placeholder mapping | local disk, permissions 600 |
Documentation
| Doc | Contents | Lang |
|---|---|---|
| Quick start | install, configure, integrate, verify, upgrade, uninstall | EN · 中文 |
| 需求文档 | product requirements, acceptance criteria, risks, roadmap | 中文 |
| 开发文档 | architecture, modules, ADRs, status matrix, testing | 中文 |
| Security & trust | trust model, data flow, threat model, vulnerability reporting | EN · 中文 |
| Agent integration | Codex / WorkBuddy / OpenClaw setup | 中文 |
| Extending | custom rules, word lists, new formats, library API | EN · 中文 |
| FAQ | common questions & honest limitations | EN · 中文 |
| LEGAL.md | lawyer / legal use cases & compliance notes | 中文 |
Known limitations (be honest with yourself)
Full numbered list in PRD §9 (R1–R9); the most user-facing items are listed here without re-numbering.
- WebSocket supported (v0.2): the gateway ships a transparent WebSocket proxy — text messages are masked/restored, binary and control frames pass through. Verify with a test message after integrating.
- Recognition coverage: regex rules cannot catch every name, alias, or abbreviation. High-sensitivity cases need custom word lists (v0.2) or local models.
- Masking ≠ anonymization: placeholders prevent plaintext leakage, but context ("defendant, male, 30, Shenzhen") can still re-identify individuals.
- Restore is exact-match only: if the model rewrites a placeholder, it cannot be restored.
Read SECURITY.md before trusting this tool. Core fact: it is a man-in-the-middle gateway — it can read everything you send to the model. It runs only on your machine, listens only on 127.0.0.1, is open-source and auditable, and stores mappings locally with 600 permissions. Trust it only after reading the code.
Roadmap
| Version | Scope |
|---|---|
| v0.1 (released) | HTTP gateway, Chinese rules, live dashboard, installer, docs, e2e tests; PyPI release |
| v0.2 (released) | ✅ WebSocket proxy, ✅ custom word lists, ✅ one-click integration (FR-12), ✅ all three protocols, ✅ docx/xlsx format masking |
| v0.3 (released) | ✅ Windows (LOCALAPPDATA data dir, schtasks auto-start, 3-OS CI), ✅ PDF format masking |
| v0.4 (released) | ✅ Image OCR masking (optional) |
| v0.5 (in progress) | ✅ Org policy (policy.json: enforced/blocked categories, retention), ✅ Audit export (CSV/JSON, placeholder-only), ✅ Desktop window (pip install llm-sanitizer-gateway[desktop]), ✅ Standalone executable (PyInstaller, no Python needed); next: multilingual rules, rule marketplace, desktop window packaging |
Contributing
See CONTRIBUTING.md. Short version: Chinese comments/docs preferred for this project; any change touching privacy handling must describe the data-flow impact in the PR.
License
MIT — see LICENSE.
Disclaimer: this project does not constitute legal advice. Whether case materials may be processed by third-party LLMs is governed by your organization's rules, professional confidentiality obligations, and applicable privacy regulations.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_sanitizer_gateway-0.6.3.tar.gz.
File metadata
- Download URL: llm_sanitizer_gateway-0.6.3.tar.gz
- Upload date:
- Size: 85.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35f7240269bdf88299ff0dfd49a0f22f5c664e9aa32d27aab0c35a6aecd64c9b
|
|
| MD5 |
5099d068e6ec4d504ad7208f973d8f98
|
|
| BLAKE2b-256 |
1bdde07dbae65e11a5f9437f36376359d835adedc1337d1e4e58e5c0423880ee
|
File details
Details for the file llm_sanitizer_gateway-0.6.3-py3-none-any.whl.
File metadata
- Download URL: llm_sanitizer_gateway-0.6.3-py3-none-any.whl
- Upload date:
- Size: 61.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c39358b30432cc7ac96a5187f861899c3d36fbaca95c077c3e450aee834bb60
|
|
| MD5 |
aa7d10cd3c60a4a5f0ea28afcfc46b52
|
|
| BLAKE2b-256 |
cc41cf56aa1783ac42d7be14ffe3af40e60abbf23de50dfa74d9401b29608d37
|