Skip to main content

LLM Sanitizer

CI

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.

🇨🇳 中文版 README


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-gateway to 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.1 only; 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's base_url here
  • 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

  1. 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)
    
  2. Start the gateway:

    python3 -m llm_sanitizer start
    
  3. 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.

  4. Verify it works: send a test message like 申请人张三,电话 13912345678 from 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

llm_sanitizer_gateway-0.6.1.tar.gz (83.2 kB view details)

Uploaded Source

Built Distribution

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

llm_sanitizer_gateway-0.6.1-py3-none-any.whl (59.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_sanitizer_gateway-0.6.1.tar.gz.

File metadata

  • Download URL: llm_sanitizer_gateway-0.6.1.tar.gz
  • Upload date:
  • Size: 83.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for llm_sanitizer_gateway-0.6.1.tar.gz
Algorithm Hash digest
SHA256 d58822252aea2468fd460b52abaa99cf70e43d55edf76be2bd7b0294d4d01130
MD5 fc5261864280b09c775e76cc968bd896
BLAKE2b-256 3783928eb0147be24bd94e1d8a4b3a8ae531a2462317318d3a687fa9cb1236a8

See more details on using hashes here.

File details

Details for the file llm_sanitizer_gateway-0.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_sanitizer_gateway-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b502e5da060b51843986e71ed65cee78e1219587dcbe42429a410ae911368a3
MD5 fb93529312af371c213ea8c59e64590a
BLAKE2b-256 b9dc4d2925b851079066686bf47b542454ceccb79b3f3dd78b0bc4dccf1cb6b3

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.3

2 files

0.6.2

2 files

This release

0.6.1 This release

2 files

0.6.0

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

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