polanon 0.2.0__tar.gz → 0.2.2__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.
- {polanon-0.2.0 → polanon-0.2.2}/CHANGELOG.md +70 -0
- {polanon-0.2.0 → polanon-0.2.2}/PKG-INFO +57 -16
- {polanon-0.2.0 → polanon-0.2.2}/README.md +56 -15
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/README.md +12 -10
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/compare_presidio.py +1 -1
- polanon-0.2.2/benchmarks/gold/monthly_roster.json +13 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/run.py +1 -1
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/README.md +3 -0
- polanon-0.2.2/benchmarks/samples/monthly_roster.txt +7 -0
- {polanon-0.2.0 → polanon-0.2.2}/docs/THREAT_MODEL.md +14 -7
- {polanon-0.2.0 → polanon-0.2.2}/polanon/__init__.py +1 -1
- {polanon-0.2.0 → polanon-0.2.2}/polanon/__main__.py +2 -1
- polanon-0.2.2/polanon/_known_parts.py +46 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/names_pl.py +92 -25
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/recognizers_pl.py +156 -5
- {polanon-0.2.0 → polanon-0.2.2}/polanon/output_sweep.py +42 -3
- {polanon-0.2.0 → polanon-0.2.2}/polanon/pipeline.py +20 -2
- {polanon-0.2.0 → polanon-0.2.2}/polanon/policy.py +1 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon.egg-info/PKG-INFO +57 -16
- {polanon-0.2.0 → polanon-0.2.2}/polanon.egg-info/SOURCES.txt +4 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_benchmark.py +1 -1
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_cli.py +10 -0
- polanon-0.2.2/tests/test_known_parts.py +103 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_layering.py +1 -1
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_names_guard.py +82 -0
- polanon-0.2.2/tests/test_output_sweep.py +141 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_pipeline_invariants.py +4 -2
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_recognizers_pl.py +197 -0
- polanon-0.2.0/tests/test_output_sweep.py +0 -72
- {polanon-0.2.0 → polanon-0.2.2}/CONTRIBUTING.md +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/LICENSE +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/MANIFEST.in +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/SECURITY.md +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/demo.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/cv.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/czat.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/faktura.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/invoice_se.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/invoice_uk.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/mail_klienta.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/notatka_wewnetrzna.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/rechnung_ch.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/umowa.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/gold/zgloszenie_it.json +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/cv.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/czat.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/faktura.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/invoice_se.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/invoice_uk.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/mail_klienta.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/notatka_wewnetrzna.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/rechnung_ch.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/umowa.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/benchmarks/samples/zgloszenie_it.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/docs/demo.gif +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/examples/anthropic_chat.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/examples/openai_chat.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/_detection.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/_matching.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/_view.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/allowlist.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/__init__.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/base.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/company_pl.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/denylist.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/international.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/ner.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/guards/secrets.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/judge/__init__.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/judge/base.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/judge/mock.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/judge/ollama.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/judge/parsing.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/judge/prompt.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/judge/remote.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/py.typed +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/stream_restore.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon/types.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon.egg-info/dependency_links.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon.egg-info/entry_points.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon.egg-info/requires.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/polanon.egg-info/top_level.txt +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/pyproject.toml +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/setup.cfg +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/__init__.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_allowlist.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_company_guard.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_denylist_guard.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_examples.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_international_guard.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_judges.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_mock_judge.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_ner_guard.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_pipeline.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_public_api.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_secrets_guard.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_stream_restore.py +0 -0
- {polanon-0.2.0 → polanon-0.2.2}/tests/test_types.py +0 -0
|
@@ -4,6 +4,76 @@ All notable changes to this project are recorded here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows
|
|
5
5
|
[semantic versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.2.2] - 2026-11-08
|
|
8
|
+
|
|
9
|
+
Found by masking synthetic CVs, profiles written as JSON and lists of repositories with the rules
|
|
10
|
+
alone.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Links to a person's profile** are a new built-in type, `LINK` (tokens `<LINK_1>`): LinkedIn
|
|
15
|
+
(`linkedin.com/in/...`), GitHub, GitLab, Bitbucket, Codeberg, GitHub and GitLab Pages, Stack
|
|
16
|
+
Overflow, Kaggle, Behance, Dribbble, Medium, Instagram, Facebook, X, YouTube and a few more.
|
|
17
|
+
Only the link up to the handle is masked, so `<LINK_1>/weather-app` still names the project.
|
|
18
|
+
A LinkedIn link carried the person's name, and a GitHub login reappeared in every repository.
|
|
19
|
+
The paths of a site's own pages (`github.com/features`, `facebook.com/groups/...`,
|
|
20
|
+
`youtube.com/watch`) stay readable. A guard that declares `LINK` as its own type keeps working.
|
|
21
|
+
- **The surname of a masked person and the handle of a masked profile link are masked on their
|
|
22
|
+
own** wherever they appear in the text: "Kowalski" alone after "Jan Kowalski", and
|
|
23
|
+
`"login": "jkowalski"`, `@jkowalski` and `jkowalski.github.io` after `github.com/jkowalski`, went
|
|
24
|
+
out in the clear. A lone surname in lowercase stays an ordinary word, as any known one-word name
|
|
25
|
+
does; a name only the language model found gives its surname only next to a first name the rules
|
|
26
|
+
know, and the handles of well-known brands (`github.com/microsoft/...`) stay readable.
|
|
27
|
+
- **Popular first names missing from the list**: Oliwier, Cyprian, Maurycy, Celina, Ksenia,
|
|
28
|
+
Lilianna, Matylda, Melania and Otylia, with their surnames: "Oliwier Nowak" went out whole.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **An e-mail address with its "@" written out** is masked whole: `jan.kowalski [at] example.com`,
|
|
33
|
+
`(at)`, `(małpa)`, also with `[dot]`. Only "jan" was masked, as a first name.
|
|
34
|
+
- **A street written without "ul."** is masked when a postcode follows it: in
|
|
35
|
+
`Długa 5 m. 4, 00-238 Warszawa` only the postcode was. A word and a number with no postcode
|
|
36
|
+
after them, such as `Windows 11`, stay readable.
|
|
37
|
+
- **A birth date written in English** is masked after its label: `Date of birth: 15 March 1985`,
|
|
38
|
+
`DOB: March 15, 1985` and `born 3rd May 1985` went out whole. With `DATE` turned on, such dates
|
|
39
|
+
are dates too.
|
|
40
|
+
|
|
41
|
+
## [0.2.1] - 2026-11-08
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- **`polanon --version`** prints the installed version. Contributed by barkya28 in
|
|
46
|
+
[#29](https://github.com/boromat/polanon/pull/29).
|
|
47
|
+
- **An eleventh benchmark document**, a monthly roster of surnames and periods, which keeps names
|
|
48
|
+
beside ordinary numbers masked without a language model. The corpus now has 169 annotated
|
|
49
|
+
values: the rules alone fully mask 86% of them and the rules with `pl_core_news_md` 98%.
|
|
50
|
+
|
|
51
|
+
### Fixed
|
|
52
|
+
|
|
53
|
+
- **E-mail addresses with Polish letters** are masked whole: `zofia.żak@example.com` was masked
|
|
54
|
+
as a name and half an address, and an address on an internationalised domain not at all.
|
|
55
|
+
Contributed by ShahadatTest in [#14](https://github.com/boromat/polanon/pull/14).
|
|
56
|
+
- **A phone number after "tel." is labelled a phone**, not a REGON: one nine-digit number in ten
|
|
57
|
+
passes the REGON checksum, and the model was told it was a company's register number.
|
|
58
|
+
Contributed by ShahadatTest in [#22](https://github.com/boromat/polanon/pull/22); "kom."
|
|
59
|
+
counts as a phone label as well, and "hotel" no longer does.
|
|
60
|
+
- **A phone number written with a bare 48 in front** is masked whole: `48123456789`, as SMS
|
|
61
|
+
gateways and CRM exports write it, went out unmasked, and in `48 123 456 789` the country code
|
|
62
|
+
stayed in the clear. A valid PESEL that starts with 48 keeps its type, and the minutes of a time
|
|
63
|
+
such as `10:48` are not pulled into the phone. Contributed by Aaqibhafeezkhan in
|
|
64
|
+
[#26](https://github.com/boromat/polanon/pull/26).
|
|
65
|
+
- **A restored name with a case ending is not reported as new**: "dla <OSOBA_1>a" restored as
|
|
66
|
+
"Jan Kowalskia" was flagged by the output sweep as personal data the model made up. A person,
|
|
67
|
+
company or place known from the conversation now covers its Polish case endings, while a longer
|
|
68
|
+
different name, letters glued on the left, and other types such as an address with a letter
|
|
69
|
+
added are still reported. Contributed by bfs2021 in
|
|
70
|
+
[#25](https://github.com/boromat/polanon/pull/25).
|
|
71
|
+
- **A month spelled like a first name is left alone in a date** written with dashes, slashes or
|
|
72
|
+
dots: "Jan" in `15-Jan-2024`, `2024/Jan/15` or `15.Jan.2024` was masked as a person. The same
|
|
73
|
+
separator has to stand on both sides, so a name beside an ordinary number, as in
|
|
74
|
+
`Nowak Anna 03/2024`, is still masked. Contributed by ShahadatTest in
|
|
75
|
+
[#23](https://github.com/boromat/polanon/pull/23).
|
|
76
|
+
|
|
7
77
|
## [0.2.0] - 2026-11-03
|
|
8
78
|
|
|
9
79
|
Before this release a pre-release review went through the library looking for ways personal data
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: polanon
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Reversible PII masking for LLM calls, Polish-first: checksum-validated PESEL, NIP, REGON and IBAN, Polish names in every case, stable tokens and streaming restore.
|
|
5
5
|
Author: BoroMat
|
|
6
6
|
License-Expression: MIT
|
|
@@ -93,6 +93,28 @@ of the box:
|
|
|
93
93
|
It also reads foreign invoices: EU, UK and Swiss VAT numbers, company register numbers, Bankgiro,
|
|
94
94
|
Plusgiro and sort codes, international phone numbers, street addresses and postcodes.
|
|
95
95
|
|
|
96
|
+
## How it compares
|
|
97
|
+
|
|
98
|
+
| | polanon | [Presidio](https://github.com/data-privacy-stack/presidio) | [pii-veil](https://pypi.org/project/pii-veil/) | [piimask](https://pypi.org/project/piimask/) |
|
|
99
|
+
|---|---|---|---|---|
|
|
100
|
+
| Restores the model's answer | Yes, from stable tokens such as `<OSOBA_1>`, also while it streams | Not built in: its deanonymizer decrypts spans at known positions; its docs include a sample that restores an LLM answer | Yes, from stable tokens and a saved mapping | Yes, from stable tokens |
|
|
101
|
+
| Polish identifiers with a checksum | PESEL, NIP, REGON, ID card, IBAN, payment cards | PESEL; IBAN and payment cards in general | PESEL, NIP, REGON, IBAN, payment cards; ID card and passport by pattern only | None; IBAN and payment cards in general |
|
|
102
|
+
| Polish names in every grammatical case | For listed first names and the surnames that agree with them, without a language model; spaCy adds the rest | With a Polish spaCy model and its `persName` label mapped | Not detected | Not detected; its README suggests adding an NER model |
|
|
103
|
+
| What the core needs | Nothing beyond the standard library | spaCy, numpy, pydantic and a few more; a language model only for names and places | pii-core and typer | Nothing beyond the standard library |
|
|
104
|
+
| On polanon's [sample documents](https://github.com/boromat/polanon/blob/main/benchmarks/README.md) | 98% fully masked with `pl_core_news_md`, 86% with rules alone | 66% with the same model (presidio-analyzer 2.2.366) | Not measured | Not measured |
|
|
105
|
+
| License | MIT | MIT | Apache-2.0 | MIT |
|
|
106
|
+
|
|
107
|
+
Compared from each project's own documentation and source on 3 November 2026. Only Presidio was
|
|
108
|
+
run on the sample documents, with the script in `benchmarks/`, and that is not neutral ground: the
|
|
109
|
+
eleven synthetic documents were written by polanon's author, who tuned its rules on them, and
|
|
110
|
+
Presidio had only the Polish model, also for the three invoices from abroad. Each has its place:
|
|
111
|
+
Presidio for many languages, structured data and its Azure integration; pii-veil for Polish
|
|
112
|
+
identifiers under Apache-2.0 when names do not matter; piimask for language-neutral identifiers
|
|
113
|
+
(e-mail, phone numbers, payment cards, IBAN, IP addresses, URLs) and US social security numbers,
|
|
114
|
+
with fake-value, hashing and partial strategies and an encrypted vault. polanon is for Polish text
|
|
115
|
+
on its way to a model, where the names in it
|
|
116
|
+
and the restored answer matter as much as the numbers.
|
|
117
|
+
|
|
96
118
|
## Install
|
|
97
119
|
|
|
98
120
|
| You want | Install |
|
|
@@ -110,6 +132,7 @@ Text comes from the arguments, from a file with `--file`, or from standard input
|
|
|
110
132
|
to stdout and the mapping to stderr, or to a file with `--mapping`:
|
|
111
133
|
|
|
112
134
|
```bash
|
|
135
|
+
polanon --version # print the installed version
|
|
113
136
|
polanon "Jan Kowalski, PESEL 50810112354"
|
|
114
137
|
polanon --file umowa.txt --ner --mapping mapping.json > masked.txt
|
|
115
138
|
cat umowa.txt | polanon --ner > masked.txt 2> mapping.json
|
|
@@ -170,24 +193,27 @@ the real SDKs, offline.
|
|
|
170
193
|
## What it detects
|
|
171
194
|
|
|
172
195
|
Checksum-validated Polish identifiers (PESEL, NIP, REGON, ID card, IBAN, payment cards), KRS numbers
|
|
173
|
-
next to their label, e-mail addresses and phone numbers, street addresses and postcodes,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
196
|
+
next to their label, e-mail addresses and phone numbers, street addresses and postcodes, links to
|
|
197
|
+
a person's profile (LinkedIn, GitHub, GitHub Pages, GitLab, social media) up to the handle, IPv4
|
|
198
|
+
and IPv6, MAC addresses, vehicle registrations after their label ("nr rej."), VINs, passport
|
|
199
|
+
numbers, birth dates, API keys, tokens and passwords, Polish first names with their surnames, and
|
|
200
|
+
company names anchored on a legal form ("Sp. z o.o.", "S.A.", "Ltd", "GmbH"). Once a person or a
|
|
201
|
+
profile link is masked, the surname or the handle alone is masked wherever it appears in the same
|
|
202
|
+
text: "Kowalski" after "Jan Kowalski", "jkowalski" in a JSON field after "github.com/jkowalski".
|
|
203
|
+
With the `ner` extra, a spaCy model adds places and the names nothing else marks. An optional
|
|
204
|
+
second stage lets a small local model review the *masked* text for what still identifies someone
|
|
205
|
+
by context. Other dates are recognised too, but left readable unless you ask for them.
|
|
180
206
|
|
|
181
207
|
Text copied from PDFs, Word or macOS is read as a person would read it: letters written as a base
|
|
182
208
|
letter plus an accent, no-break spaces and en dashes inside numbers, and invisible zero-width
|
|
183
209
|
characters do not hide a value. The mapping keeps each value as it was first written.
|
|
184
210
|
|
|
185
|
-
On the annotated sample documents in the repository, the rules alone fully mask
|
|
186
|
-
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked.
|
|
211
|
+
On the annotated sample documents in the repository, the rules alone fully mask 86% of the
|
|
212
|
+
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked. Eleven short
|
|
187
213
|
documents are a regression check, not a research benchmark: see the
|
|
188
214
|
[benchmark notes](https://github.com/boromat/polanon/blob/main/benchmarks/README.md) for what is
|
|
189
|
-
missed and why, and for
|
|
190
|
-
|
|
215
|
+
missed and why, and for Presidio on the same documents with the same model: 66% fully masked, 76%
|
|
216
|
+
at its most lenient.
|
|
191
217
|
|
|
192
218
|
## Worth knowing
|
|
193
219
|
|
|
@@ -368,10 +394,25 @@ Masking is pseudonymisation, not anonymisation in the legal sense, and no detect
|
|
|
368
394
|
everything. The [threat model](https://github.com/boromat/polanon/blob/main/docs/THREAT_MODEL.md) says what is covered, what is
|
|
369
395
|
not, and what stays your application's job, starting with keeping the mapping safe.
|
|
370
396
|
|
|
371
|
-
polanon was built as the masking engine of
|
|
372
|
-
or GPT on real documents without sending personal data
|
|
373
|
-
|
|
374
|
-
it ever starts to.
|
|
397
|
+
polanon was built as the masking engine of [PolGate](https://github.com/boromat/polgate), a
|
|
398
|
+
self-hosted hub that lets a team use Claude or GPT on real documents without sending personal data
|
|
399
|
+
to the provider. The library knows nothing about it — no HTTP, no database, no settings — and a
|
|
400
|
+
test fails if it ever starts to.
|
|
401
|
+
|
|
402
|
+
## Used by
|
|
403
|
+
|
|
404
|
+
[PolGate](https://github.com/boromat/polgate) is a self-hosted company chat for Claude and GPT
|
|
405
|
+
built on polanon: every message and uploaded document is masked on the server before it reaches the
|
|
406
|
+
model, and the answer streams back with the originals in place. It adds what a team needs around
|
|
407
|
+
the library: an encrypted vault for the mapping, retention that deletes, an audit log of types and
|
|
408
|
+
counts, and an admin panel for the policy, including the allowlist and denylist.
|
|
409
|
+
|
|
410
|
+
[PolCV](https://github.com/boromat/polcv) writes CVs for Polish job postings and can mask the
|
|
411
|
+
candidate's name, contact details and company names with polanon before any text reaches the
|
|
412
|
+
model, then put them back into the answer. It adds a guard of its own for what the profile already
|
|
413
|
+
knows, such as a LinkedIn link with the name in it, as
|
|
414
|
+
[Adding a detector](https://github.com/boromat/polanon#adding-a-detector) describes. polanon stays optional there: the app installs it on request, talks to it through a
|
|
415
|
+
small JSON-lines bridge, and sends nothing at all while masking is on but polanon is not working.
|
|
375
416
|
|
|
376
417
|
## Contributing
|
|
377
418
|
|
|
@@ -53,6 +53,28 @@ of the box:
|
|
|
53
53
|
It also reads foreign invoices: EU, UK and Swiss VAT numbers, company register numbers, Bankgiro,
|
|
54
54
|
Plusgiro and sort codes, international phone numbers, street addresses and postcodes.
|
|
55
55
|
|
|
56
|
+
## How it compares
|
|
57
|
+
|
|
58
|
+
| | polanon | [Presidio](https://github.com/data-privacy-stack/presidio) | [pii-veil](https://pypi.org/project/pii-veil/) | [piimask](https://pypi.org/project/piimask/) |
|
|
59
|
+
|---|---|---|---|---|
|
|
60
|
+
| Restores the model's answer | Yes, from stable tokens such as `<OSOBA_1>`, also while it streams | Not built in: its deanonymizer decrypts spans at known positions; its docs include a sample that restores an LLM answer | Yes, from stable tokens and a saved mapping | Yes, from stable tokens |
|
|
61
|
+
| Polish identifiers with a checksum | PESEL, NIP, REGON, ID card, IBAN, payment cards | PESEL; IBAN and payment cards in general | PESEL, NIP, REGON, IBAN, payment cards; ID card and passport by pattern only | None; IBAN and payment cards in general |
|
|
62
|
+
| Polish names in every grammatical case | For listed first names and the surnames that agree with them, without a language model; spaCy adds the rest | With a Polish spaCy model and its `persName` label mapped | Not detected | Not detected; its README suggests adding an NER model |
|
|
63
|
+
| What the core needs | Nothing beyond the standard library | spaCy, numpy, pydantic and a few more; a language model only for names and places | pii-core and typer | Nothing beyond the standard library |
|
|
64
|
+
| On polanon's [sample documents](https://github.com/boromat/polanon/blob/main/benchmarks/README.md) | 98% fully masked with `pl_core_news_md`, 86% with rules alone | 66% with the same model (presidio-analyzer 2.2.366) | Not measured | Not measured |
|
|
65
|
+
| License | MIT | MIT | Apache-2.0 | MIT |
|
|
66
|
+
|
|
67
|
+
Compared from each project's own documentation and source on 3 November 2026. Only Presidio was
|
|
68
|
+
run on the sample documents, with the script in `benchmarks/`, and that is not neutral ground: the
|
|
69
|
+
eleven synthetic documents were written by polanon's author, who tuned its rules on them, and
|
|
70
|
+
Presidio had only the Polish model, also for the three invoices from abroad. Each has its place:
|
|
71
|
+
Presidio for many languages, structured data and its Azure integration; pii-veil for Polish
|
|
72
|
+
identifiers under Apache-2.0 when names do not matter; piimask for language-neutral identifiers
|
|
73
|
+
(e-mail, phone numbers, payment cards, IBAN, IP addresses, URLs) and US social security numbers,
|
|
74
|
+
with fake-value, hashing and partial strategies and an encrypted vault. polanon is for Polish text
|
|
75
|
+
on its way to a model, where the names in it
|
|
76
|
+
and the restored answer matter as much as the numbers.
|
|
77
|
+
|
|
56
78
|
## Install
|
|
57
79
|
|
|
58
80
|
| You want | Install |
|
|
@@ -70,6 +92,7 @@ Text comes from the arguments, from a file with `--file`, or from standard input
|
|
|
70
92
|
to stdout and the mapping to stderr, or to a file with `--mapping`:
|
|
71
93
|
|
|
72
94
|
```bash
|
|
95
|
+
polanon --version # print the installed version
|
|
73
96
|
polanon "Jan Kowalski, PESEL 50810112354"
|
|
74
97
|
polanon --file umowa.txt --ner --mapping mapping.json > masked.txt
|
|
75
98
|
cat umowa.txt | polanon --ner > masked.txt 2> mapping.json
|
|
@@ -130,24 +153,27 @@ the real SDKs, offline.
|
|
|
130
153
|
## What it detects
|
|
131
154
|
|
|
132
155
|
Checksum-validated Polish identifiers (PESEL, NIP, REGON, ID card, IBAN, payment cards), KRS numbers
|
|
133
|
-
next to their label, e-mail addresses and phone numbers, street addresses and postcodes,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
156
|
+
next to their label, e-mail addresses and phone numbers, street addresses and postcodes, links to
|
|
157
|
+
a person's profile (LinkedIn, GitHub, GitHub Pages, GitLab, social media) up to the handle, IPv4
|
|
158
|
+
and IPv6, MAC addresses, vehicle registrations after their label ("nr rej."), VINs, passport
|
|
159
|
+
numbers, birth dates, API keys, tokens and passwords, Polish first names with their surnames, and
|
|
160
|
+
company names anchored on a legal form ("Sp. z o.o.", "S.A.", "Ltd", "GmbH"). Once a person or a
|
|
161
|
+
profile link is masked, the surname or the handle alone is masked wherever it appears in the same
|
|
162
|
+
text: "Kowalski" after "Jan Kowalski", "jkowalski" in a JSON field after "github.com/jkowalski".
|
|
163
|
+
With the `ner` extra, a spaCy model adds places and the names nothing else marks. An optional
|
|
164
|
+
second stage lets a small local model review the *masked* text for what still identifies someone
|
|
165
|
+
by context. Other dates are recognised too, but left readable unless you ask for them.
|
|
140
166
|
|
|
141
167
|
Text copied from PDFs, Word or macOS is read as a person would read it: letters written as a base
|
|
142
168
|
letter plus an accent, no-break spaces and en dashes inside numbers, and invisible zero-width
|
|
143
169
|
characters do not hide a value. The mapping keeps each value as it was first written.
|
|
144
170
|
|
|
145
|
-
On the annotated sample documents in the repository, the rules alone fully mask
|
|
146
|
-
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked.
|
|
171
|
+
On the annotated sample documents in the repository, the rules alone fully mask 86% of the
|
|
172
|
+
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked. Eleven short
|
|
147
173
|
documents are a regression check, not a research benchmark: see the
|
|
148
174
|
[benchmark notes](https://github.com/boromat/polanon/blob/main/benchmarks/README.md) for what is
|
|
149
|
-
missed and why, and for
|
|
150
|
-
|
|
175
|
+
missed and why, and for Presidio on the same documents with the same model: 66% fully masked, 76%
|
|
176
|
+
at its most lenient.
|
|
151
177
|
|
|
152
178
|
## Worth knowing
|
|
153
179
|
|
|
@@ -328,10 +354,25 @@ Masking is pseudonymisation, not anonymisation in the legal sense, and no detect
|
|
|
328
354
|
everything. The [threat model](https://github.com/boromat/polanon/blob/main/docs/THREAT_MODEL.md) says what is covered, what is
|
|
329
355
|
not, and what stays your application's job, starting with keeping the mapping safe.
|
|
330
356
|
|
|
331
|
-
polanon was built as the masking engine of
|
|
332
|
-
or GPT on real documents without sending personal data
|
|
333
|
-
|
|
334
|
-
it ever starts to.
|
|
357
|
+
polanon was built as the masking engine of [PolGate](https://github.com/boromat/polgate), a
|
|
358
|
+
self-hosted hub that lets a team use Claude or GPT on real documents without sending personal data
|
|
359
|
+
to the provider. The library knows nothing about it — no HTTP, no database, no settings — and a
|
|
360
|
+
test fails if it ever starts to.
|
|
361
|
+
|
|
362
|
+
## Used by
|
|
363
|
+
|
|
364
|
+
[PolGate](https://github.com/boromat/polgate) is a self-hosted company chat for Claude and GPT
|
|
365
|
+
built on polanon: every message and uploaded document is masked on the server before it reaches the
|
|
366
|
+
model, and the answer streams back with the originals in place. It adds what a team needs around
|
|
367
|
+
the library: an encrypted vault for the mapping, retention that deletes, an audit log of types and
|
|
368
|
+
counts, and an admin panel for the policy, including the allowlist and denylist.
|
|
369
|
+
|
|
370
|
+
[PolCV](https://github.com/boromat/polcv) writes CVs for Polish job postings and can mask the
|
|
371
|
+
candidate's name, contact details and company names with polanon before any text reaches the
|
|
372
|
+
model, then put them back into the answer. It adds a guard of its own for what the profile already
|
|
373
|
+
knows, such as a LinkedIn link with the name in it, as
|
|
374
|
+
[Adding a detector](https://github.com/boromat/polanon#adding-a-detector) describes. polanon stays optional there: the app installs it on request, talks to it through a
|
|
375
|
+
small JSON-lines bridge, and sends nothing at all while masking is on but polanon is not working.
|
|
335
376
|
|
|
336
377
|
## Contributing
|
|
337
378
|
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
# How well polanon detects
|
|
2
2
|
|
|
3
|
-
[`samples/`](samples/) holds
|
|
4
|
-
customer complaint, an IT support ticket, an employment contract, an internal IT note,
|
|
5
|
-
messages typed the way people type them, in lowercase and without Polish letters
|
|
6
|
-
|
|
3
|
+
[`samples/`](samples/) holds eleven synthetic documents. Eight are Polish — a CV, a VAT invoice, a
|
|
4
|
+
customer complaint, an IT support ticket, an employment contract, an internal IT note, chat
|
|
5
|
+
messages typed the way people type them, in lowercase and without Polish letters, and a monthly
|
|
6
|
+
roster of surnames and periods — and three are
|
|
7
|
+
invoices from abroad: British, Swedish and Swiss. [`gold/`](gold/) annotates the 169 values that
|
|
7
8
|
must be masked, and [`run.py`](run.py) reports whether each one was **fully** covered, because half
|
|
8
9
|
a masked PESEL is a leak rather than half a success. It scores the guards and the merging of
|
|
9
10
|
their findings, not the pass that masks every later occurrence of a value already found: through
|
|
10
|
-
`Anonymizer
|
|
11
|
+
`Anonymizer`, which also masks every later occurrence of a value it has found, the same documents
|
|
12
|
+
can only come out the same or better.
|
|
11
13
|
|
|
12
14
|
| Configuration | Fully masked | Partially masked | Missed | Over-masked spans |
|
|
13
15
|
|---|---:|---:|---:|---:|
|
|
14
|
-
| polanon, guards only, no model |
|
|
15
|
-
| polanon, guards + `pl_core_news_md` | **
|
|
16
|
-
|
|
|
17
|
-
| Presidio, phone recognizer at leniency 0 |
|
|
16
|
+
| polanon, guards only, no model | 145 / 169 (86%) | 0 | 24 | 0 |
|
|
17
|
+
| polanon, guards + `pl_core_news_md` | **166 / 169 (98%)** | 0 | 3 | 7 |
|
|
18
|
+
| Presidio 2.2.366, set up for Polish with the same model | 112 / 169 (66%) | 25 | 32 | 47 |
|
|
19
|
+
| Presidio, phone recognizer at leniency 0 | 128 / 169 (76%) | 29 | 12 | 76 |
|
|
18
20
|
|
|
19
21
|
Presidio is the usual answer to "mask personal data before an LLM call", so it is the baseline.
|
|
20
22
|
[`compare_presidio.py`](compare_presidio.py) gives it the same Polish spaCy model, every offline recognizer it
|
|
@@ -62,7 +64,7 @@ formula. What the model adds is places and company names without a legal form.
|
|
|
62
64
|
|
|
63
65
|
</details>
|
|
64
66
|
|
|
65
|
-
**Read the number honestly.**
|
|
67
|
+
**Read the number honestly.** Eleven short documents are a regression check, not a research
|
|
66
68
|
benchmark, and the corpus was written by the same person who wrote the guards, who tuned them
|
|
67
69
|
against it; Presidio was never tuned on it. The misses are
|
|
68
70
|
instructive: the word *Kraków* is masked in one document and missed in another, and *Bristol* and
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Score
|
|
1
|
+
"""Score Presidio on the same annotated samples, set up for Polish with no own code.
|
|
2
2
|
|
|
3
3
|
Presidio is the usual answer to "how do I mask personal data before an LLM call", so it is the
|
|
4
4
|
baseline worth measuring against. It gets the same Polish spaCy model polanon uses, with the model's
|
|
@@ -17,7 +17,7 @@ up covered, so that is what is measured here:
|
|
|
17
17
|
masked spans that overlap no annotation. Some of these are genuinely wrong; others are
|
|
18
18
|
conservative masking the annotation did not ask for. Reported as a count, not as an error.
|
|
19
19
|
|
|
20
|
-
The corpus is
|
|
20
|
+
The corpus is eleven short synthetic documents (169 annotated occurrences), eight Polish and three
|
|
21
21
|
foreign invoices, which makes this a regression check with a readable output, not a research
|
|
22
22
|
benchmark. Nobody should quote these numbers as a general accuracy claim for any language.
|
|
23
23
|
|
|
@@ -13,3 +13,6 @@ would in one company's paperwork. No data about an actual person belongs in this
|
|
|
13
13
|
|
|
14
14
|
`../gold/*.json` annotates each document with the values that must be masked and their entity type.
|
|
15
15
|
`../run.py` scores the guards against those annotations; `../demo.py` just prints the masked text.
|
|
16
|
+
|
|
17
|
+
`monthly_roster.txt` keeps surname-first monthly periods and names beside ordinary numbers
|
|
18
|
+
masked without a language model. The separate name-guard tests cover punctuated date formats.
|
|
@@ -24,9 +24,10 @@ tokens reach the provider, and puts the originals back into the answer, also whi
|
|
|
24
24
|
- **Deterministic identifiers.** PESEL, NIP, REGON, ID card numbers, IBAN and payment cards are
|
|
25
25
|
matched by pattern and confirmed by checksum, so detection is near-certain and false positives are
|
|
26
26
|
rare. KRS numbers and passports are recognised next to their label.
|
|
27
|
-
- **Contact details and devices.** E-mail addresses,
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
- **Contact details and devices.** E-mail addresses, also with "[at]" written out, phone numbers,
|
|
28
|
+
street addresses and postcodes, links to a person's profile (LinkedIn, GitHub and GitHub Pages,
|
|
29
|
+
GitLab, social media) up to the handle, IPv4 and IPv6, MAC addresses, VINs, vehicle registrations
|
|
30
|
+
after their label, birth dates after theirs, in Polish or English.
|
|
30
31
|
- **Credentials.** API keys, JWTs, private key blocks and `password=` style assignments, masked whole
|
|
31
32
|
with whatever was found inside them, so pasted logs and configuration files do not leak secrets.
|
|
32
33
|
- **People and companies by rule.** Polish first names in all seven cases, in any letter case and
|
|
@@ -36,8 +37,10 @@ tokens reach the provider, and puts the originals back into the answer, also whi
|
|
|
36
37
|
- **Every later occurrence of a masked value.** Pass the mapping from the latest result to the next
|
|
37
38
|
call and a value keeps its token wherever it appears again: in capitals, across a line break or a run of
|
|
38
39
|
spaces, with a no-break space, an invisible character or a decomposed accent in it, and with an
|
|
39
|
-
identifier's groups written apart or together.
|
|
40
|
-
|
|
40
|
+
identifier's groups written apart or together. The surname of a masked person and the handle of a
|
|
41
|
+
masked profile link count as masked values of their own, so "Kowalski" after "Jan Kowalski" and
|
|
42
|
+
"jkowalski" after "github.com/jkowalski" are masked too. `mask_known_values` does the same for
|
|
43
|
+
text masked earlier, such as conversation history sent again.
|
|
41
44
|
- **Your own placeholders.** A token such as `<PESEL_1>` already in your text is never handed to real
|
|
42
45
|
data.
|
|
43
46
|
- **The answer.** `StreamRestorer` never splits a token across chunks, and `sweep` reports tokens the
|
|
@@ -52,14 +55,18 @@ tokens reach the provider, and puts the originals back into the answer, also whi
|
|
|
52
55
|
misread, goes out as written. The checksum is what keeps random digits from being masked, and
|
|
53
56
|
the price is this.
|
|
54
57
|
- **Names and places are found partly by rule, partly statistically.** A surname on its own in
|
|
55
|
-
lowercase ("napisz do kowalskiego")
|
|
56
|
-
the spaCy model, which leans on capital letters and misses what people type in lowercase. A miss
|
|
58
|
+
lowercase ("napisz do kowalskiego") or in a text where the full name never appears, a rare or
|
|
59
|
+
foreign first name and every place name depend on the spaCy model, which leans on capital letters and misses what people type in lowercase. A miss
|
|
57
60
|
is a detection gap, not a bypass, but the value still reaches the provider. The stage-2 judge
|
|
58
61
|
exists to narrow this gap, not to close it.
|
|
59
62
|
- **A one-word name later written in lowercase.** A capitalised one-word name is not matched in all
|
|
60
63
|
lowercase, because many Polish surnames are also ordinary words (Zima, Kot, Wilk): "kowalska
|
|
61
64
|
dzwoniła" after "Pani Kowalska" goes out unless a detector recognises it on its own. Once one
|
|
62
65
|
does, that spelling has a token of its own.
|
|
66
|
+
- **A handle or a personal domain on its own.** A login is recognised inside a link to a profile
|
|
67
|
+
on a known site, and from there wherever it stands. A login with no such link anywhere in the
|
|
68
|
+
text ("mój GitHub to jkowalski") and a personal domain ("jankowalski.dev") are ordinary words to
|
|
69
|
+
the rules: put them on the denylist, or report them from a guard of your own, when you know them.
|
|
63
70
|
- **A short number inside a longer one.** A PIN or another number under six digits is not masked
|
|
64
71
|
inside a date, an amount or a longer number ("15.04.2025" when the PIN is 2025), so the model does
|
|
65
72
|
not learn which numbers look like it. Where it stands alone it is masked.
|
|
@@ -71,7 +71,7 @@ __all__ = [
|
|
|
71
71
|
"token_for",
|
|
72
72
|
]
|
|
73
73
|
|
|
74
|
-
__version__ = "0.2.
|
|
74
|
+
__version__ = "0.2.2"
|
|
75
75
|
|
|
76
76
|
#: The entity types an Anonymizer masks unless told otherwise: every built-in type except DATE.
|
|
77
77
|
#: A date rarely identifies anyone on its own, and masking every deadline and invoice date leaves
|
|
@@ -19,7 +19,7 @@ from collections.abc import Mapping, Sequence
|
|
|
19
19
|
from pathlib import Path
|
|
20
20
|
from typing import TextIO
|
|
21
21
|
|
|
22
|
-
from polanon import Anonymizer, default_guards
|
|
22
|
+
from polanon import Anonymizer, __version__, default_guards
|
|
23
23
|
|
|
24
24
|
DESCRIPTION = "Mask personal data in text before it goes to an LLM; the mapping goes to stderr."
|
|
25
25
|
|
|
@@ -48,6 +48,7 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
48
48
|
mapping could not be written, 3 when --ner is given without spaCy.
|
|
49
49
|
"""
|
|
50
50
|
parser = argparse.ArgumentParser(prog="polanon", description=DESCRIPTION)
|
|
51
|
+
parser.add_argument("--version", action="version", version=f"polanon {__version__}")
|
|
51
52
|
parser.add_argument("text", nargs="*", help="text to mask; omit to read standard input")
|
|
52
53
|
parser.add_argument(
|
|
53
54
|
"--file",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""The parts of a masked value that give the same thing away on their own.
|
|
2
|
+
|
|
3
|
+
A surname is the person: once "Jan Kowalski" is masked, "Kowalski" further down the text is the
|
|
4
|
+
same man, and it went out in the clear, because no rule reads a lone surname as a name. A handle is
|
|
5
|
+
the account: once "github.com/jkowalski" is masked, "jkowalski" in a JSON field, after "@" or in
|
|
6
|
+
"jkowalski.github.io" is the same account. The pipeline treats such a part as a known value of the
|
|
7
|
+
same type, so it is masked wherever it stands, by the rules every known value follows.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from polanon.allowlist import WELL_KNOWN_NAMES
|
|
13
|
+
from polanon.guards.names_pl import fold, person_name_parts
|
|
14
|
+
from polanon.guards.recognizers_pl import profile_handle
|
|
15
|
+
|
|
16
|
+
#: A handle shorter than this is not masked on its own: "jk" or "ab" stand for nobody in prose.
|
|
17
|
+
MIN_HANDLE_LENGTH = 4
|
|
18
|
+
|
|
19
|
+
#: The platforms and brands of the allowlist as handles. "github.com/microsoft/vscode" links to a
|
|
20
|
+
#: project, and masking "Microsoft" in every sentence after it hides nobody.
|
|
21
|
+
_WELL_KNOWN_HANDLES = frozenset(fold(name).replace(" ", "") for name in WELL_KNOWN_NAMES)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def known_parts(value: str, entity_type: str, *, trusted: bool) -> list[str]:
|
|
25
|
+
"""Return the parts of a masked value to mask wherever they appear, under the value's type.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
value: the masked value, as written.
|
|
29
|
+
entity_type: its type.
|
|
30
|
+
trusted: whether the detection stands on its own, such as a rule's, a list's or the
|
|
31
|
+
caller's, rather than a language model's guess. A model that reads "Google Ads" as a
|
|
32
|
+
person would otherwise mask "Ads" in every sentence after it, so a name it found gives
|
|
33
|
+
its surname only next to a first name the name guard knows.
|
|
34
|
+
"""
|
|
35
|
+
if entity_type == "PERSON":
|
|
36
|
+
return person_name_parts(value, needs_first_name=not trusted)
|
|
37
|
+
if entity_type == "LINK":
|
|
38
|
+
handle = profile_handle(value)
|
|
39
|
+
if (
|
|
40
|
+
handle is not None
|
|
41
|
+
and len(handle) >= MIN_HANDLE_LENGTH
|
|
42
|
+
and any(char.isalpha() for char in handle)
|
|
43
|
+
and fold(handle).replace("-", "") not in _WELL_KNOWN_HANDLES
|
|
44
|
+
):
|
|
45
|
+
return [handle]
|
|
46
|
+
return []
|