Add in-tree PII scrub (no new parquet)

#20
by ppuzio - opened
Slayer Labs org
edited 4 days ago

Code-only. No new data shards. ParlaMint is held — it overlaps discussion #18 and PPC.

Two fetch-time passes, both already required by AGENTS.md. Neither is an LLM.

  1. src/scrub_pii.py — regex. Phones become [Telefon]; email / PESEL / NIP / REGON / IBAN become [PII]. National IDs and IBANs are checksum-gated so statute and case numbers stay.
  2. src/scrub_entities.py — PERSON-only NER (ArkadiuszPawlak/fastpdn-ner-polish-pii, ONNX). Imię Nazwisko[PII]. Streets, cities and orgs are ignored. Allowlisted web shards only (european_hplt_v3_pl, govpl, samorzad_gov_pl). Official and encyclopaedic sources are default-deny — names of public officials are the content, not PII.

Wired into:

  • src/clean_hplt_v3.py — regex, then NER.
  • src/fetch_sejm_api.py — regex only (rebuilds of the shipped speech shard).
  • src/fetch_sejm_interpellations.py — regex only. New fetcher for interpelacje / zapytania (terms 7–10, HTML bodies only). Registered in SOURCES, crawl still running locally, parquet comes in a later PR.

src/html_text.py is the shared HTML-to-text helper so the interpellation fetcher does not paste a fourth copy.

Sample — identifiers (verbatim, from test_scrub_pii.py)

Before:

Pisz na jan.kowalski@example.com dziś.
Zadzwoń 501 234 567.
PESEL 44051401458, konto PL61109010140000071219812874.
decyzja (znak: BPRM.4820.2.3.2020).

After:

Pisz na [PII] dziś.
Zadzwoń [Telefon].
PESEL [PII], konto [PII].
decyzja (znak: BPRM.4820.2.3.2020).

Sample — names (verbatim, from test_scrub_entities.py)

On an allowlisted web source (european_hplt_v3_pl):

Kontakt: Anna Nowak, ul. 3 Maja.
→ Kontakt: [PII], ul. 3 Maja.

Same spans on Sejm / ParlaMint / Wikipedia: no change. Szymon Hołownia and Donald Tusk stay.

Live checks that shaped the false-positive gates: Sejm interpellation sample (32 docs) after the znak / datetime / postal / KRS filters → 0 hits; HPLT 300-doc stride on the shipped parquet still has leftover emails, IBANs and en-dash landlines — those are why the cleaner now calls this in-tree. Shipped HPLT parquet is not rewritten here.

Tests

python3 src/test_scrub_pii.py          # 29
python3 src/test_scrub_entities.py     # 9
python3 src/test_sejm_interpellations_contract.py  # 5

Deliberately not in this PR

  • data/parlamint_pl/ and src/fetch_parlamint.py
  • Sejm interpellation parquet (crawl still on term 7)
  • FinePDFs / findings-log addenda
  • SAOS fetcher
ppuzio changed pull request status to open
Maggio33 changed pull request status to merged

Sign up or log in to comment