pii-scrubber 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. pii_scrubber-0.1.0/LICENSE +21 -0
  2. pii_scrubber-0.1.0/PKG-INFO +408 -0
  3. pii_scrubber-0.1.0/README.md +359 -0
  4. pii_scrubber-0.1.0/pyproject.toml +53 -0
  5. pii_scrubber-0.1.0/setup.cfg +4 -0
  6. pii_scrubber-0.1.0/src/pii_scrubber/__init__.py +7 -0
  7. pii_scrubber-0.1.0/src/pii_scrubber/cli.py +269 -0
  8. pii_scrubber-0.1.0/src/pii_scrubber/core.py +144 -0
  9. pii_scrubber-0.1.0/src/pii_scrubber/diagnostics.py +76 -0
  10. pii_scrubber-0.1.0/src/pii_scrubber/entities.py +15 -0
  11. pii_scrubber-0.1.0/src/pii_scrubber/extractors.py +91 -0
  12. pii_scrubber-0.1.0/src/pii_scrubber/html_tools.py +40 -0
  13. pii_scrubber-0.1.0/src/pii_scrubber/mrz.py +100 -0
  14. pii_scrubber-0.1.0/src/pii_scrubber/national_ids.py +869 -0
  15. pii_scrubber-0.1.0/src/pii_scrubber/ner.py +73 -0
  16. pii_scrubber-0.1.0/src/pii_scrubber/nonpii_terms.py +54 -0
  17. pii_scrubber-0.1.0/src/pii_scrubber/ocr.py +85 -0
  18. pii_scrubber-0.1.0/src/pii_scrubber/open_file.py +27 -0
  19. pii_scrubber-0.1.0/src/pii_scrubber/redact.py +311 -0
  20. pii_scrubber-0.1.0/src/pii_scrubber/rules.py +183 -0
  21. pii_scrubber-0.1.0/src/pii_scrubber/workspace.py +66 -0
  22. pii_scrubber-0.1.0/src/pii_scrubber.egg-info/PKG-INFO +408 -0
  23. pii_scrubber-0.1.0/src/pii_scrubber.egg-info/SOURCES.txt +38 -0
  24. pii_scrubber-0.1.0/src/pii_scrubber.egg-info/dependency_links.txt +1 -0
  25. pii_scrubber-0.1.0/src/pii_scrubber.egg-info/entry_points.txt +2 -0
  26. pii_scrubber-0.1.0/src/pii_scrubber.egg-info/requires.txt +26 -0
  27. pii_scrubber-0.1.0/src/pii_scrubber.egg-info/top_level.txt +1 -0
  28. pii_scrubber-0.1.0/tests/test_core.py +43 -0
  29. pii_scrubber-0.1.0/tests/test_diagnostics.py +78 -0
  30. pii_scrubber-0.1.0/tests/test_e2e_cli.py +454 -0
  31. pii_scrubber-0.1.0/tests/test_e2e_recording.py +50 -0
  32. pii_scrubber-0.1.0/tests/test_extractors.py +33 -0
  33. pii_scrubber-0.1.0/tests/test_html.py +36 -0
  34. pii_scrubber-0.1.0/tests/test_mrz.py +54 -0
  35. pii_scrubber-0.1.0/tests/test_national_ids.py +414 -0
  36. pii_scrubber-0.1.0/tests/test_ner.py +30 -0
  37. pii_scrubber-0.1.0/tests/test_open_file.py +54 -0
  38. pii_scrubber-0.1.0/tests/test_redact.py +94 -0
  39. pii_scrubber-0.1.0/tests/test_rules.py +116 -0
  40. pii_scrubber-0.1.0/tests/test_workspace.py +77 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Charley Rutledge
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,408 @@
1
+ Metadata-Version: 2.4
2
+ Name: pii-scrubber
3
+ Version: 0.1.0
4
+ Summary: Scrub personally identifiable information from documents using regex rules and spaCy NER.
5
+ Author: Charley Rutledge
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/CharleyRutledge/pii-scrubber
8
+ Project-URL: Repository, https://github.com/CharleyRutledge/pii-scrubber
9
+ Project-URL: Issues, https://github.com/CharleyRutledge/pii-scrubber/issues
10
+ Project-URL: Changelog, https://github.com/CharleyRutledge/pii-scrubber/blob/main/CHANGELOG.md
11
+ Keywords: pii,redaction,privacy,gdpr,nlp,spacy,scrub
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: Text Processing :: Filters
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: spacy<4.0,>=3.7
28
+ Requires-Dist: click>=8.0
29
+ Provides-Extra: pdf
30
+ Requires-Dist: pymupdf>=1.24; extra == "pdf"
31
+ Provides-Extra: docx
32
+ Requires-Dist: python-docx>=1.1; extra == "docx"
33
+ Provides-Extra: ocr
34
+ Requires-Dist: pytesseract>=0.3; extra == "ocr"
35
+ Requires-Dist: Pillow>=10.0; extra == "ocr"
36
+ Provides-Extra: all
37
+ Requires-Dist: pymupdf>=1.24; extra == "all"
38
+ Requires-Dist: python-docx>=1.1; extra == "all"
39
+ Requires-Dist: pytesseract>=0.3; extra == "all"
40
+ Requires-Dist: Pillow>=10.0; extra == "all"
41
+ Provides-Extra: dev
42
+ Requires-Dist: pytest>=7.4; extra == "dev"
43
+ Requires-Dist: pymupdf>=1.24; extra == "dev"
44
+ Requires-Dist: python-docx>=1.1; extra == "dev"
45
+ Requires-Dist: pytesseract>=0.3; extra == "dev"
46
+ Requires-Dist: Pillow>=10.0; extra == "dev"
47
+ Requires-Dist: Faker>=20.0; extra == "dev"
48
+ Dynamic: license-file
49
+
50
+ # pii-scrubber
51
+
52
+ [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-support-ffdd00?logo=buy-me-a-coffee&logoColor=black)](https://buymeacoffee.com/m61v0m5kun)
53
+
54
+ A Python library for scrubbing personally identifiable information (PII)
55
+ from documents **before** you paste or upload them somewhere that isn't
56
+ under your control - an LLM chat tool, a support ticket, a shared drive.
57
+
58
+ **Runs entirely on your machine. No network calls, no telemetry, nothing
59
+ uploaded anywhere.** Detection is regex + a local, pretrained spaCy NER
60
+ model doing inference only - it does not learn from, retain, or transmit
61
+ your documents. You can read exactly what it does: pattern rules live in
62
+ [`rules.py`](src/pii_scrubber/rules.py), NER logic in
63
+ [`ner.py`](src/pii_scrubber/ner.py).
64
+
65
+ > **No PII scrubber is complete.** Regex and NER both have real blind
66
+ > spots - see [Known limitations](#known-limitations) below, all of which
67
+ > came from testing this against real documents. Spot-check the redacted
68
+ > output before you rely on it, especially for anything sensitive.
69
+
70
+ See [docs/USAGE_WALKTHROUGH.md](docs/USAGE_WALKTHROUGH.md) for a step-by-step
71
+ CLI walkthrough with a recorded terminal session - generated straight from a
72
+ real, passing run of the CLI (`tools/record_demo.py`), so the commands and
73
+ output shown are genuine, not hand-written. See
74
+ [CHANGELOG.md](CHANGELOG.md) for a full status report of what's covered
75
+ (document formats, languages tested, all 39 national ID formats, passport/
76
+ health-insurance detection) and what's explicitly not implemented yet.
77
+
78
+ ## Install
79
+
80
+ Not yet published to PyPI - see
81
+ [CONTRIBUTING.md § Releasing to PyPI](CONTRIBUTING.md#releasing-to-pypi)
82
+ for the one-time setup. Once released, this will work directly:
83
+
84
+ ```bash
85
+ pip install "pii-scrubber[all]" # pdf + docx + ocr support
86
+ python -m spacy download en_core_web_sm
87
+ ```
88
+
89
+ Until then, install from source:
90
+
91
+ ```bash
92
+ git clone https://github.com/CharleyRutledge/pii-scrubber.git
93
+ cd pii-scrubber
94
+ pip install -e ".[all]"
95
+ python -m spacy download en_core_web_sm
96
+ ```
97
+
98
+ Then, from the command line:
99
+
100
+ ```bash
101
+ pii-scrubber scrub your_document.pdf
102
+ ```
103
+
104
+ For library development (running the test suite, contributing), use the
105
+ `dev` extra instead:
106
+
107
+ ```bash
108
+ pip install -e ".[dev]"
109
+ python -m spacy download en_core_web_sm
110
+ ```
111
+
112
+ `ocr` also requires a system Tesseract OCR install (not installable via pip):
113
+
114
+ ```powershell
115
+ winget install --id UB-Mannheim.TesseractOCR
116
+ ```
117
+
118
+ ## Usage
119
+
120
+ ### Command line
121
+
122
+ ```bash
123
+ pii-scrubber scrub document.pdf # print redacted text + counts
124
+ pii-scrubber redact document.pdf # write document_redacted.pdf
125
+ pii-scrubber redact document.pdf --ocr # also redact PII baked into images
126
+ pii-scrubber redact document.pdf -o clean.pdf --no-ner # regex rules only
127
+ pii-scrubber redact document.pdf --open # prompt to choose an app to open the redacted file with
128
+ pii-scrubber scrub document.pdf --open # write scrubbed text to a temp file, then prompt the same way
129
+ pii-scrubber scrub document.pdf -o clean.txt --open # ...or to a chosen path
130
+ pii-scrubber doctor # check whether spaCy NER can actually load here
131
+ pii-scrubber upload document.pdf # copy a file into local, offline storage
132
+ pii-scrubber list # show what's stored locally
133
+ pii-scrubber menu # interactive menu - pick an action instead of flags
134
+ pii-scrubber # (no command) also launches the menu
135
+ ```
136
+
137
+ See [docs/USAGE_WALKTHROUGH.md](docs/USAGE_WALKTHROUGH.md) for a full
138
+ recorded walkthrough of these commands against a real file.
139
+
140
+ #### `pii-scrubber menu`
141
+
142
+ An interactive "PII - Scrubber" menu for running everything above without
143
+ remembering flags - upload a file, scrub it, redact it, check stored
144
+ files, or run `doctor`, all from a numbered prompt. Running `pii-scrubber`
145
+ with no arguments launches it directly.
146
+
147
+ #### Local file storage
148
+
149
+ `pii-scrubber upload <path>` copies a file into `~/.pii-scrubber/uploads`
150
+ - a local-only folder, nothing is sent anywhere over the network. Files
151
+ uploaded this way show up as pickable options in the menu's file prompts.
152
+ Scrub/redact runs started from the menu save their output into
153
+ `~/.pii-scrubber/outputs`, named `<original name>_scrubbed.txt` or
154
+ `<original name>_redacted<ext>`, deduped with a `(1)`, `(2)`, ... suffix
155
+ if a name's already taken so nothing is ever silently overwritten.
156
+ `pii-scrubber list` shows everything currently stored in both folders.
157
+
158
+ #### `pii-scrubber doctor`
159
+
160
+ Diagnoses whether the spaCy NER model (used for `PERSON`/`LOCATION`/
161
+ `ORGANIZATION`/`AFFILIATION` detection) can actually load in this
162
+ environment. On Windows, spaCy's compiled extension modules are
163
+ unsigned, and some machines block unsigned native code from loading via
164
+ **Smart App Control** (Settings → Privacy & security → Windows Security
165
+ → App & browser control) or an org-managed **WDAC** policy - surfacing
166
+ as `ImportError: DLL load failed ... An Application Control policy has
167
+ blocked this file`. This isn't a pii-scrubber bug; regex-based rules
168
+ (email, phone, national IDs, etc.) are unaffected and keep working via
169
+ `--no-ner`.
170
+
171
+ When `doctor` detects this specific block, it offers to jump straight
172
+ to the relevant Windows UI instead of making you hunt for it:
173
+
174
+ - **Smart App Control settings** - shows whether it's Off / Evaluation
175
+ (can be turned off right there) / On (Microsoft only supports turning
176
+ it off via a full Windows reinstall).
177
+ - **Event Viewer's CodeIntegrity log** - shows the exact policy and file
178
+ hash that got blocked, useful for a targeted WDAC exception or an IT
179
+ request.
180
+
181
+ Nothing is opened without an explicit "y" at the prompt.
182
+
183
+ ### Python API
184
+
185
+ ```python
186
+ from pii_scrubber import scrub, scrub_file
187
+
188
+ result = scrub("Contact Jane Doe at jane.doe@example.com or 555-123-4567.")
189
+ print(result.text)
190
+ # "Contact [PERSON] at [EMAIL] or [PHONE]."
191
+ print(result.counts)
192
+ # {"PERSON": 1, "EMAIL": 1, "PHONE": 1}
193
+
194
+ # Extract + scrub a file directly
195
+ result = scrub_file("contract.docx")
196
+ ```
197
+
198
+ Supported file types via `scrub_file`: `.txt`, `.md`, `.html`/`.htm`, `.pdf`,
199
+ `.docx`, `.csv`, `.json`.
200
+
201
+ ### Format-preserving redaction
202
+
203
+ `scrub_file` returns flattened plain text. To instead get a redacted copy of
204
+ the document in its **original file format**, use `redact_file`:
205
+
206
+ ```python
207
+ from pii_scrubber import redact_file
208
+
209
+ out_path = redact_file("contract.docx")
210
+ # writes contract_redacted.docx next to the original, structure intact
211
+
212
+ redact_file("intake.pdf", output_path="intake_clean.pdf")
213
+ # PDF: original layout/images kept, PII burned out with black boxes
214
+
215
+ redact_file("intake.pdf", ocr=True)
216
+ # also OCRs embedded images (scanned IDs, screenshots) and blacks out
217
+ # any image whose recognized text contains PII. Requires the `ocr` extra
218
+ # and a system Tesseract install (see below) - off by default.
219
+
220
+ redact_file("intake.pdf", open_after=True)
221
+ # launches the redacted file in its default app once written, so you can
222
+ # immediately eyeball the result - off by default (surprising behavior for
223
+ # anything running unattended: scripts, CI, batch jobs).
224
+ ```
225
+
226
+ | File type | What's preserved |
227
+ |---|---|
228
+ | `.txt` / `.md` | plain text, redacted in place |
229
+ | `.docx` | paragraphs and table cells, PII replaced with `[LABEL]` text |
230
+ | `.csv` | rows/columns, redacted per cell |
231
+ | `.json` | keys and structure, string values redacted, numbers/bools untouched |
232
+ | `.pdf` | original layout and images; PII is truly removed (not just hidden) and covered with a black box, not a `[LABEL]` |
233
+ | `.html` / `.htm` | tags/attributes/scripts/styles untouched, only visible text redacted |
234
+
235
+ ### Disabling NER
236
+
237
+ Regex-only mode skips loading the spaCy model, useful when you only care
238
+ about structured identifiers or want to avoid the model dependency:
239
+
240
+ ```python
241
+ scrub(text, use_ner=False)
242
+ ```
243
+
244
+ ### Detected entity types
245
+
246
+ | Label | Source |
247
+ |---|---|
248
+ | EMAIL, PHONE, SSN, CREDIT_CARD, IP_ADDRESS, MAC_ADDRESS, IBAN, ADDRESS, URL, FILE_PATH, SOCIAL_PROFILE | regex |
249
+ | National IDs (39 countries, see table below) | regex, checksum-validated where a real algorithm exists |
250
+ | `PASSPORT_MRZ` (any issuing country) | regex, ICAO 9303 checksum-validated |
251
+ | Health insurance: `DE_KVNR` (Germany), `UK_NHS_NUMBER`, `CA_ON_HEALTH` (Ontario) | regex, checksum-validated |
252
+ | PERSON (also caught via title-prefixed regex, e.g. "MR CHARLEY RUTLEDGE") | regex + spaCy NER |
253
+ | LOCATION, ORGANIZATION, AFFILIATION | spaCy NER |
254
+
255
+ `FILE_PATH` catches `file://` URIs, which often leak a local OS username via
256
+ the path. `PASSPORT_MRZ` detects the two-line Machine Readable Zone printed
257
+ on every passport worldwide (ICAO 9303 standard) rather than a per-country
258
+ passport-number pattern - passport formats vary hugely by country and
259
+ mostly have no public checksum of their own, so a bare "letters + digits"
260
+ pattern would be far too collision-prone; the MRZ is identical in structure
261
+ across every issuing country and carries four real check digits. Verified
262
+ against ICAO's own published worked example - see `tests/test_mrz.py`.
263
+
264
+ **Driver's licences are deliberately not implemented.** Researched the UK
265
+ format specifically (the most well-documented one): it deterministically
266
+ encodes surname, birth date, and initials into 11 of its 16 characters,
267
+ but its own documentation describes the final characters as
268
+ "computer-generated"/random - there is no real checksum. US licences vary
269
+ by state with no federal standard and, as far as could be verified, no
270
+ checksum either. Implementing a format-only pattern for either would
271
+ reintroduce exactly the collision risk that `_US_PASSPORT` (removed
272
+ earlier - see git history) had: matching against ordinary alphanumeric
273
+ codes throughout a document. If you know of a driver's licence format
274
+ with a real public checksum, contributions are welcome.
275
+
276
+ #### National ID coverage
277
+
278
+ | Country | Label | Checksum algorithm |
279
+ |---|---|---|
280
+ | Ireland | `PPS_NUMBER` | letter checksum |
281
+ | Ireland (postal code) | `EIRCODE` | format only |
282
+ | United Kingdom | `UK_NINO` | format only (letter/prefix constraints) |
283
+ | United States | `SSN` | format only |
284
+ | France | `FR_INSEE` | mod 97 |
285
+ | Germany | `DE_RVNR` | weighted digit-sum |
286
+ | Spain | `ES_NIF` / `ES_NIE` | mod 23 letter lookup |
287
+ | Italy | `IT_CODICE_FISCALE` | position-weighted mod 26 |
288
+ | Netherlands | `NL_BSN` | elfproef (mod 11) |
289
+ | Poland | `PL_PESEL` | weighted mod 10 |
290
+ | Sweden | `SE_PERSONNUMMER` | Luhn |
291
+ | Norway | `NO_FODSELSNUMMER` | two-stage mod 11 |
292
+ | Portugal | `PT_NIF` | weighted mod 11 |
293
+ | Russia | `RU_INN` | two-stage weighted mod 11 |
294
+ | Turkey | `TR_TCKN` | weighted mod 10 |
295
+ | Romania | `RO_CNP` | weighted mod 11 |
296
+ | Hungary | `HU_SZEMELYI` | weighted mod 11 (direction depends on birth year) |
297
+ | Brazil | `BR_CPF` | two-stage weighted mod 11 |
298
+ | Canada | `CA_SIN` | Luhn |
299
+ | China | `CN_RESIDENT_ID` | ISO 7064 MOD 11-2 |
300
+ | South Korea | `KR_RRN` | weighted mod 11 |
301
+ | Australia | `AU_TFN` | weighted mod 11 |
302
+ | Algeria | `DZ_NIN` | modified Luhn |
303
+ | Austria | `AT_SVNR` | weighted mod 11 |
304
+ | Greece | `EL_AMKA` | Luhn |
305
+ | Mexico | `MX_IMSS` | digital-root weighted sum |
306
+ | Estonia | `EE_ISIKUKOOD` | two-scale mod 11 |
307
+ | Finland | `FI_HETU` | mod 31 letter lookup |
308
+ | Switzerland | `CH_AHV` | EAN-13-style checksum, fixed `756` prefix |
309
+ | Israel | `IL_TZ` | Luhn-family |
310
+ | Croatia | `HR_OIB` | ISO 7064 MOD 11,10 |
311
+ | Latvia | `LV_PERSONAS_KODS` | weighted mod 11 |
312
+ | North Macedonia | `MK_EMBG` | weighted mod 11 |
313
+ | Belgium | `BE_RRN` | mod 97 |
314
+ | Bosnia and Herzegovina | `BA_JMB` | weighted mod 11 (see note below) |
315
+ | Ukraine | `UA_RNOKPP` | weighted mod 11 mod 10 |
316
+ | Taiwan | `TW_ID` | letter-weighted positional sum |
317
+ | India | `IN_AADHAAR` | Luhn |
318
+ | Chile | `CL_RUT` | mod 11, cycling weights |
319
+ | Czech Republic / Slovakia | `CZ_SK_RODNE_CISLO` | divisible by 11 |
320
+
321
+ North Macedonia and Bosnia's formats both descend from the shared
322
+ former-Yugoslav JMBG numbering system and use the same weights, but their
323
+ reference algorithms differ in one edge case (weighted sum mod 11 == 1):
324
+ North Macedonia maps it to check digit 0, Bosnia treats it as genuinely
325
+ unallocatable. They're implemented as two separate checked functions, not
326
+ one shared one - an earlier version of this code wrongly assumed they were
327
+ identical, which silently rejected about 1 in 11 otherwise-valid North
328
+ Macedonian numbers (see `tests/test_national_ids.py` for the vector that
329
+ catches a regression).
330
+
331
+ All 39 were validated against hundreds of locale-appropriate synthetic
332
+ documents generated with [Faker](https://faker.readthedocs.io/) - see
333
+ `tools/audit_national_ids.py`. Where Faker itself can't generate a real
334
+ checksum-valid example for a country (it has gaps too - see the script's
335
+ output for specifics), the rule is instead verified with a hand-computed
336
+ test vector in `tests/test_national_ids.py`. More countries are welcome -
337
+ see [CONTRIBUTING.md](CONTRIBUTING.md).
338
+
339
+ Several of these are also commonly displayed with punctuation/spacing
340
+ rather than as a bare digit run, confirmed against authoritative sources
341
+ and handled explicitly: French INSEE (`1 85 03 75 116 001 27`), Swedish
342
+ personnummer's full-century form (`19960804-5820`), Dutch BSN
343
+ (`1234.56.789`), Spanish NIF/NIE (`12345678-Z`), and Australian TFN
344
+ (`123 456 782`) - in addition to IBAN and UK NINO, mentioned above. Not
345
+ every remaining rule has been checked for a real alternate display format
346
+ this thoroughly yet (e.g. Norwegian, Hungarian) - if you know of one,
347
+ please open an issue or PR.
348
+
349
+ ## Known limitations
350
+
351
+ - **NER is English-only and unreliable on other languages.** The bundled
352
+ spaCy model (`en_core_web_sm`) was trained on English. On non-English
353
+ text it will miss most names/places, and can misclassify ordinary words
354
+ as PERSON/ORGANIZATION (e.g. Spanish "gobierno"/"trimestre" flagged as
355
+ ORGANIZATION in testing). Regex rules (email, phone, credit card, etc.)
356
+ are largely language-agnostic and still work. For non-English documents,
357
+ treat NER output as noisy and either spot-check carefully or use
358
+ `use_ner=False` and rely on regex rules alone. Emails were reliably
359
+ redacted across every language tested (English, Spanish, French, German,
360
+ Chinese, Arabic, Japanese); name/location detection was not.
361
+ - **Rare NER false positives on placeholder/non-name text** (e.g. spaCy
362
+ occasionally tags "Lorem ipsum" boilerplate as PERSON). Harmless in
363
+ practice, but a reminder that NER output isn't ground truth.
364
+ - **Generic NER on real documents misses things.** spaCy's small English
365
+ model can fail to recognize a name with no surrounding sentence context
366
+ (e.g. a signer's name alone on a line in a letter footer), even when it
367
+ gets the same name right in a full sentence. A structural heuristic
368
+ catches some of these (a short all-caps line next to a detected address
369
+ is treated as a place name), but this isn't exhaustive.
370
+ - **Dense technical content (resumes/CVs, skills lists) can be
371
+ over-redacted.** Found by testing against a real technical resume: a
372
+ bulleted list of tool/framework names (Docker, jQuery, Neo4j, etc.) is
373
+ full of capitalized, proper-noun-shaped tokens that a generic NER model
374
+ frequently misreads as PERSON or ORGANIZATION - one real resume had 25
375
+ false PERSON matches before mitigation. A curated exclusion list
376
+ (`nonpii_terms.py`) fixes the common cases, but it's a fixed list, not
377
+ a general solution - an unlisted framework/tool name can still get
378
+ swept up. Contributions adding more terms are welcome.
379
+ - **Country/format-specific identifiers you haven't added a rule for won't
380
+ be caught.** The regex rules were built out against real US/Irish
381
+ documents during development; a national ID format, postal code, or
382
+ phone format from elsewhere may need its own rule - see
383
+ [CONTRIBUTING.md](CONTRIBUTING.md).
384
+ - **Without `ocr=True`, PII baked into an image is invisible to the
385
+ tool** - a photographed ID, a screenshot, a scanned signature. Only
386
+ real text layers are scanned by default.
387
+ - **OCR-based image redaction blacks out the entire image**, not just the
388
+ PII within it, since OCR text can't be reliably mapped back to exact
389
+ pixel coordinates inside the image.
390
+ - **A PDF's embedded font can occasionally have a broken glyph mapping**,
391
+ causing text extraction to silently drop or mangle a character. The
392
+ tool detects this (`�` replacement characters) and warns you, or -
393
+ with `ocr=True` - falls back to rasterizing and OCR'ing that page
394
+ instead of trusting the broken text layer.
395
+
396
+ ## Development
397
+
398
+ ```bash
399
+ pytest
400
+ ```
401
+
402
+ Contributions welcome - see [CONTRIBUTING.md](CONTRIBUTING.md). For
403
+ reporting a missed detection, see [SECURITY.md](SECURITY.md) (please don't
404
+ post real documents or real PII in a public issue).
405
+
406
+ ## License
407
+
408
+ [MIT](LICENSE)