Scope: this reduces risk; it is not an anonymization guarantee. Regexes recognise formats, not every kind of sensitive information; truly confidential material should go to a local model. All sample data here is made up. Framing: a solo developer's workflow. The destination can be any cloud model (Kimi, GLM, Qwen, DeepSeek, or Claude / GPT as examples); the scripts are vendor-neutral. If you use Claude: Anthropic has not supported mainland China, Hong Kong or Macau since 2026-11-12 (checked 2026-11-23).
Situation
- Audience: you want a cloud model to process contracts, support transcripts, logs or customer sheets that contain emails, phone numbers, ID numbers, keys, internal IPs or client names.
- When to use: the task needs a cloud model's capability but the specific personal/client details don't matter to it (e.g. "categorize this support chat").
- When not to use: the sensitive data is the subject of the task (e.g. "verify this person's ID number") — use a local model; data that law or contract forbids sending out — ask compliance, don't rely on masking.
Outcome
- A local script replacing emails, phone-number-shaped strings, ID-shaped numbers, card-shaped numbers, IPs, common key prefixes and your listed names/companies/projects with placeholders like
[EMAIL_1]; - a mapping file that never leaves the machine, used to restore placeholders in the model's reply;
- a pre-upload review checklist.
Steps
- Decide whether it may go to the cloud at all using the classification table. "Confidential" stays local.
- List names in
names.txt: client names, company names, project code names, internal system names, one per line. Regexes can't find names; only you can. - Run the redaction:
python3 redact.py in.txt out.txt map.json names.txt.map.jsonis written with mode 600 (the script forces 600 even if the file already existed); keep it local — never upload or commit it. - Read
out.txtyourself for what slipped through (addresses, company abbreviations, business details, text inside screenshots); add tonames.txtand rerun if needed. - Upload
out.txtwith a note: "bracketed placeholders are redactions; keep them verbatim". - Restore: save the reply as
ans.txt, runpython3 restore.py ans.txt map.json back.txt. - Delete
map.jsonand intermediates when done (or keep them on an encrypted disk).
Templates
The scripts are in the Chinese section (code is in English). Classification table (English):
| Level | Examples | Handling |
|---|---|---|
| Public | published articles, official docs | may go to the cloud as is |
| Internal | ordinary work docs, logs without personal data | redact then cloud, or local |
| Sensitive | client data with personal information, financial detail | local only; ask compliance before any cloud use |
| Confidential | keys, unpublished contract terms, NDA-covered content | never to a cloud or third-party AI; only a local model on a machine you control may process it |
Failure cases
- Regex misses (boundaries found while testing): formats only. Names, addresses, company abbreviations and "that big client" are not replaced — rely on
names.txtand a human read. - False positives: 16-digit order numbers or date strings can look like card numbers; 18-digit strings may be other IDs. Hence the review and the visible
map.json. - A leaked mapping file defeats the purpose: it holds every original value.
- The model rewrites placeholders: ask for verbatim retention and check placeholder counts before restoring.
- Other formats: text only. PDFs, images and spreadsheets must be converted first; text inside screenshots is especially risky; not handled here.
China alternatives
china_availability: yes: the scripts use only the local standard library. Use Kimi / GLM / Qwen / DeepSeek or any domestic service as destination; whether a data category may go to a given service depends on your contracts, company policy and applicable law — this is not compliance advice.- ID and phone formats follow common mainland-China shapes; add rules for other countries yourself.
Safety notes
- Never send "confidential" material to a cloud model, redacted or not (processing it with a local model on a machine you control is fine).
- Redacted text can sometimes be re-identified from context; for high risk use a local model.
- Scripts and mapping run locally only; never commit a real mapping file — only samples belong in repos.
- Don't use real keys or ID numbers as test data; use made-up data like the sample here.
Test notes
- 2026-11-23, local machine (WSL2 Linux, Python 3.8, stdlib only), made-up sample text: an email, a phone-shaped number, an 18-char ID-shaped number, a card-shaped number, an IPv4, a fake
sk-key and two names/project names — 8 values replaced; a repeated email got the same placeholder;map.jsonmode 600 (a pre-existing 644 file is forced to 600);leakcheck.pypassed, and on un-redacted text it fails and prints placeholder names only, never the values; replacement is a single pass: withNAMEin the names list and[NAME_1]/[EMAIL_1]already in the input, new placeholders skip the existing ones and restoring reproduces the original (name case follows the first occurrence);restore.pyrestored placeholders in a reply. - Not tested: real documents; PDF/images; Chinese addresses and names; how any cloud model handles the placeholders.
Verification
- Run on the sample and confirm
out.txtcontains no original values (leakcheck.pyplus a human read). - Before real work, run the whole flow on a realistic fake document.