matriks-mask 0.4.0__py3-none-any.whl

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 (65) hide show
  1. matriks_mask-0.4.0.dist-info/METADATA +576 -0
  2. matriks_mask-0.4.0.dist-info/RECORD +65 -0
  3. matriks_mask-0.4.0.dist-info/WHEEL +5 -0
  4. matriks_mask-0.4.0.dist-info/entry_points.txt +3 -0
  5. matriks_mask-0.4.0.dist-info/licenses/LICENSE +202 -0
  6. matriks_mask-0.4.0.dist-info/licenses/NOTICE +18 -0
  7. matriks_mask-0.4.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +96 -0
  8. matriks_mask-0.4.0.dist-info/top_level.txt +1 -0
  9. matriks_pii/__init__.py +36 -0
  10. matriks_pii/audit.py +88 -0
  11. matriks_pii/cli.py +117 -0
  12. matriks_pii/config.py +676 -0
  13. matriks_pii/data/LICENSES.md +18 -0
  14. matriks_pii/data/__init__.py +198 -0
  15. matriks_pii/data/common_words_tr.txt +260 -0
  16. matriks_pii/data/first_names_tr.txt +6979 -0
  17. matriks_pii/data/frequent_first_names_tr.txt +1035 -0
  18. matriks_pii/data/frequent_last_names_tr.txt +3103 -0
  19. matriks_pii/data/honorifics_tr.txt +82 -0
  20. matriks_pii/data/il_ilce_tr.json +1 -0
  21. matriks_pii/data/last_names_tr.txt +26382 -0
  22. matriks_pii/data/org_names_tr.txt +183 -0
  23. matriks_pii/data/org_suffixes_tr.txt +147 -0
  24. matriks_pii/data/popular_first_names_tr.txt +553 -0
  25. matriks_pii/data/special_category/README.txt +4 -0
  26. matriks_pii/data/special_category/biyometrik.txt +21 -0
  27. matriks_pii/data/special_category/ceza.txt +33 -0
  28. matriks_pii/data/special_category/ceza_genis.txt +10 -0
  29. matriks_pii/data/special_category/cinsel.txt +22 -0
  30. matriks_pii/data/special_category/din.txt +52 -0
  31. matriks_pii/data/special_category/etnik.txt +40 -0
  32. matriks_pii/data/special_category/felsefi.txt +10 -0
  33. matriks_pii/data/special_category/genetik.txt +20 -0
  34. matriks_pii/data/special_category/kiyafet.txt +20 -0
  35. matriks_pii/data/special_category/saglik.txt +163 -0
  36. matriks_pii/data/special_category/siyasi.txt +35 -0
  37. matriks_pii/data/special_category/uyelik.txt +28 -0
  38. matriks_pii/data/tr_words.txt +48397 -0
  39. matriks_pii/engine.py +272 -0
  40. matriks_pii/guardrail.py +993 -0
  41. matriks_pii/keys.py +38 -0
  42. matriks_pii/metrics.py +112 -0
  43. matriks_pii/py.typed +0 -0
  44. matriks_pii/recognizers/__init__.py +54 -0
  45. matriks_pii/recognizers/address.py +194 -0
  46. matriks_pii/recognizers/base.py +118 -0
  47. matriks_pii/recognizers/checksums.py +113 -0
  48. matriks_pii/recognizers/contextual.py +401 -0
  49. matriks_pii/recognizers/location.py +77 -0
  50. matriks_pii/recognizers/ner_hf.py +175 -0
  51. matriks_pii/recognizers/number_words.py +84 -0
  52. matriks_pii/recognizers/numeric.py +207 -0
  53. matriks_pii/recognizers/person.py +463 -0
  54. matriks_pii/recognizers/phone.py +122 -0
  55. matriks_pii/recognizers/secrets.py +73 -0
  56. matriks_pii/recognizers/simple.py +143 -0
  57. matriks_pii/recognizers/special_category.py +293 -0
  58. matriks_pii/revert.py +291 -0
  59. matriks_pii/selftest.py +275 -0
  60. matriks_pii/session.py +138 -0
  61. matriks_pii/store.py +207 -0
  62. matriks_pii/streaming.py +506 -0
  63. matriks_pii/text_utils.py +310 -0
  64. matriks_pii/tr_morphology.py +245 -0
  65. matriks_pii/traverse.py +562 -0
@@ -0,0 +1,576 @@
1
+ Metadata-Version: 2.4
2
+ Name: matriks-mask
3
+ Version: 0.4.0
4
+ Summary: KVKK uyum süreçlerini destekleyen, Türkçe ve geri çevrilebilir PII maskeleme guardrail'i (LiteLLM) / Turkish reversible PII masking guardrail for LiteLLM
5
+ Author: Matriks Finansal Teknolojiler A.Ş.
6
+ License-Expression: Apache-2.0 AND MIT AND CC-BY-SA-4.0
7
+ Project-URL: Homepage, https://github.com/MatriksData/matriks-pii
8
+ Project-URL: Repository, https://github.com/MatriksData/matriks-pii
9
+ Project-URL: Issues, https://github.com/MatriksData/matriks-pii/issues
10
+ Project-URL: Changelog, https://github.com/MatriksData/matriks-pii/blob/main/CHANGELOG.md
11
+ Project-URL: Turkish docs, https://github.com/MatriksData/matriks-pii/blob/main/README.tr.md
12
+ Project-URL: Security, https://github.com/MatriksData/matriks-pii/blob/main/SECURITY.md
13
+ Keywords: pii,kvkk,gdpr,litellm,guardrail,turkish,masking,pseudonymization,llm,redaction
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Natural Language :: Turkish
24
+ Classifier: Topic :: Security
25
+ Classifier: Topic :: Text Processing :: Linguistic
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ License-File: NOTICE
31
+ License-File: THIRD_PARTY_NOTICES.md
32
+ Requires-Dist: pydantic>=2
33
+ Requires-Dist: pyyaml>=6
34
+ Provides-Extra: dev
35
+ Requires-Dist: litellm[proxy]<2,>=1.106.1; extra == "dev"
36
+ Requires-Dist: pytest>=8; extra == "dev"
37
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
38
+ Requires-Dist: httpx; extra == "dev"
39
+ Requires-Dist: hypothesis; extra == "dev"
40
+ Requires-Dist: ruff; extra == "dev"
41
+ Requires-Dist: mypy; extra == "dev"
42
+ Requires-Dist: uvicorn; extra == "dev"
43
+ Provides-Extra: proxy
44
+ Requires-Dist: litellm[proxy]<2,>=1.106.1; extra == "proxy"
45
+ Provides-Extra: metrics
46
+ Requires-Dist: prometheus_client>=0.17; extra == "metrics"
47
+ Provides-Extra: ner
48
+ Requires-Dist: transformers; extra == "ner"
49
+ Requires-Dist: torch; extra == "ner"
50
+ Provides-Extra: redis
51
+ Requires-Dist: redis>=5; extra == "redis"
52
+ Requires-Dist: cryptography; extra == "redis"
53
+ Provides-Extra: fast
54
+ Requires-Dist: pyahocorasick; extra == "fast"
55
+ Dynamic: license-file
56
+
57
+ # matriks-pii
58
+
59
+ [![PyPI](https://img.shields.io/pypi/v/matriks-mask.svg)](https://pypi.org/project/matriks-mask/)
60
+ [![Python](https://img.shields.io/pypi/pyversions/matriks-mask.svg)](https://pypi.org/project/matriks-mask/)
61
+ [![ci](https://github.com/MatriksData/matriks-pii/actions/workflows/ci.yml/badge.svg)](https://github.com/MatriksData/matriks-pii/actions/workflows/ci.yml)
62
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/MatriksData/matriks-pii/blob/main/LICENSE)
63
+
64
+ **English** | [Türkçe](https://github.com/MatriksData/matriks-pii/blob/main/README.tr.md)
65
+
66
+ Reversible personal data (PII) masking for Turkish text, built as a [LiteLLM](https://github.com/BerriAI/litellm)
67
+ guardrail. It supports KVKK (Turkey's personal data protection law) compliance processes.
68
+
69
+ > This plugin is a technical measure that supports KVKK compliance processes; it is not legal advice and does not by
70
+ > itself ensure compliance (see [KVKK and sector regulation](#kvkk-and-sector-regulation-not-legal-advice)). **It is not
71
+ > guaranteed that every piece of personal data in a text will be detected** (see [Known limitations](#known-limitations));
72
+ > organisations should test the masking results for their own use case.
73
+ >
74
+ > **Data controllership:** Organisations that use the plugin in their own systems are the data controllers of the
75
+ > personal data they process; Matriks is not the data controller of that data. The plugin sends no data, telemetry or
76
+ > usage information to Matriks; all processing happens in the organisation's own environment.
77
+
78
+ Before a request reaches the LLM provider, values such as Turkish ID numbers (TCKN), tax numbers (VKN), IBANs, cards,
79
+ phone numbers, names, addresses, API keys and the special categories of personal data in KVKK art. 6 are replaced with
80
+ placeholders such as `<KISI_1>` ("person") and `<TCKN_1>`. When the response comes back (streaming included), the
81
+ placeholders are restored to the original values. Original values do not reach the provider, proxy logs, spend logs,
82
+ metrics or the audit trail. Everything runs in-process: no text is sent to an external detection service.
83
+
84
+ ```
85
+ User ──"Ben Ayşe Demir, TCKN 17291716060"──▶ LiteLLM proxy ──"Ben <KISI_1>, TCKN <TCKN_1>"──▶ LLM
86
+ User ◀──"Merhaba Ayşe Demir'e ilettim"────── matriks-pii ◀──"Merhaba <KISI_1>'e ilettim"───── LLM
87
+ (suffix repair: 'e → 'e/'ye by vowel harmony)
88
+ ```
89
+
90
+ ## Highlights
91
+
92
+ - **Turkish identifiers:** TCKN, VKN, TR IBAN, Troy cards, TR licence plates, MERSİS, MKK registry numbers; validated by
93
+ check digits and context.
94
+ - **Turkish names and inflected forms** (`Ahmet'in`, `Ayşeye`, `Ahmet YILMAZ`): name lexicon + morphology + context
95
+ (+ optional Turkish NER).
96
+ - **Restoration in responses, streaming included,** with Turkish suffix repair by vowel harmony
97
+ (`<KISI_1>'e` → `Kemal'e` / `Ayşe'ye`).
98
+ - **KVKK art. 6 special categories of personal data:** 12 categories, masked only when linked to a person.
99
+ - **In-process:** no text is sent to an external service for detection.
100
+ - **Low latency:** 2 KB text p50 ≈ 2.9 ms (measured on a development machine; varies with hardware;
101
+ `pytest -m benchmark`, `python scripts/bench.py`).
102
+
103
+ ## Installation
104
+
105
+ The PyPI package is [**`matriks-mask`**](https://pypi.org/project/matriks-mask/); the Python module is `matriks_pii` and the command is `matriks-pii`
106
+ (`matriks-mask` is an alias). Upgrading from a git install of `matriks-pii` ≤ 0.3.3: run `pip uninstall matriks-pii`
107
+ first.
108
+
109
+ ```bash
110
+ pip install "matriks-mask[fast]" # fast: pyahocorasick (optional, faster lexicon lookup)
111
+ pip install "matriks-mask[redis,fast,metrics]" # production: encrypted Redis session store + Prometheus
112
+ pip install "matriks-mask[ner]" # optional Turkish NER (transformers + torch)
113
+ pip install "git+https://github.com/MatriksData/matriks-pii" # latest version on main
114
+ pipx install matriks-mask # CLI only (`matriks-pii mask`), isolated environment
115
+ ```
116
+
117
+ For pinned production versions use [`constraints/prod.txt`](https://github.com/MatriksData/matriks-pii/blob/main/constraints/prod.txt) from the repository
118
+ (`pip install "matriks-mask[redis,fast,metrics]" -c constraints/prod.txt`).
119
+
120
+ ### Try it without LiteLLM
121
+
122
+ ```bash
123
+ $ matriks-pii mask "Ben Ayşe Demir, TCKN 17291716060"
124
+ Ben <KISI_1>, TCKN <TCKN_1>
125
+ $ echo "Ahmet Yılmaz'ın telefonu 0532 234 56 78" | matriks-pii mask --profile strict --json # type + position, no values
126
+ ```
127
+
128
+ From Python (mask → restore):
129
+
130
+ ```python
131
+ from matriks_pii import MaskSession, PIIEngine, Reverter, TurkishPIIConfig
132
+
133
+ cfg = TurkishPIIConfig.build({"profile": "balanced"})
134
+ engine, session = PIIEngine(cfg), MaskSession(cfg)
135
+ masked, spans, blocked, logged = engine.mask_text("Ben Ayşe Demir, TCKN 17291716060", session)
136
+ print(masked) # Ben <KISI_1>, TCKN <TCKN_1>
137
+ reverter = Reverter(session.map, session.entities, cfg)
138
+ print(reverter.revert("<KISI_1>'e ilettim", final=True)) # Ayşe Demir'e ilettim
139
+ ```
140
+
141
+ `session.map` (placeholder → original value) contains personal data; do not log it or store it persistently. If
142
+ `blocked` is not empty (an entity with the BLOCK action was found), do not send the text.
143
+
144
+ ### With LiteLLM
145
+
146
+ Minimum LiteLLM version is **1.106.1** (tested with 1.106.1, 1.106.5 and 1.110.2). LiteLLM `config.yaml`:
147
+
148
+ ```yaml
149
+ guardrails:
150
+ - guardrail_name: matriks-pii
151
+ litellm_params:
152
+ guardrail: matriks_pii.guardrail.TurkishPIIGuardrail
153
+ mode: [pre_call, post_call] # both REQUIRED (post_call = restoration)
154
+ default_on: true
155
+ profile: balanced
156
+ ```
157
+
158
+ Verify the installation (prints no values; can also be used in CI and as a Kubernetes `startupProbe`):
159
+
160
+ ```bash
161
+ matriks-pii selftest --config config.yaml # config, store, 12 canonical probes, latency
162
+ matriks-pii selftest --config config.yaml --quick # < 2 s
163
+ ```
164
+
165
+ Step-by-step installation, multiple workers/replicas, verification and troubleshooting:
166
+ [`docs/LITELLM_KURULUM.md`](https://github.com/MatriksData/matriks-pii/blob/main/docs/LITELLM_KURULUM.md). Operations runbook (error codes, metrics, secret rotation,
167
+ rollback): [`docs/RUNBOOK.md`](https://github.com/MatriksData/matriks-pii/blob/main/docs/RUNBOOK.md). KVKK data category mapping (VERBİS/DPIA):
168
+ [`docs/KVKK_VERI_KATEGORILERI.md`](https://github.com/MatriksData/matriks-pii/blob/main/docs/KVKK_VERI_KATEGORILERI.md). These documents are in Turkish.
169
+
170
+ Full examples: [`examples/config.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/config.yaml), [`config.strict.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/config.strict.yaml),
171
+ [`config.redis.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/config.redis.yaml), [`config.placeholder_formats.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/config.placeholder_formats.yaml),
172
+ [`Dockerfile`](https://github.com/MatriksData/matriks-pii/blob/main/examples/Dockerfile).
173
+
174
+ With `default_on: false`, the guardrail is enabled per request with `"guardrails": ["matriks-pii"]` in the request body.
175
+ Clients cannot disable it: `disable_global_guardrails` / `opted_out_global_guardrails` are read only from admin
176
+ (key/team) metadata.
177
+
178
+ **`stream_scope` warning:** `stream_scope: non_streaming` in the LiteLLM guardrail settings skips the `post_call` hook
179
+ for streaming responses, so placeholders reach the client unrestored. Do not use it (selftest warns about it).
180
+
181
+ ## Detected entities
182
+
183
+ Labels are Turkish (`KISI` = person, `TELEFON` = phone, `EPOSTA` = e-mail, `ADRES` = address …); they can be changed
184
+ per entity with `labels` (e.g. `labels: {KISI: PERSON}` → `<PERSON_1>`) and the format with `placeholder_format`.
185
+
186
+ | Label | What | How it is validated | Default |
187
+ |---|---|---|---|
188
+ | `TCKN` | Turkish ID number (incl. foreigner IDs starting with 98/99) | 11 digits + official checksum; `17.291.716.060`, spaced digits, full-width digits | MASK |
189
+ | `VKN` | Tax ID number | 10 digits + checksum **and** tax context | MASK |
190
+ | `IBAN` | TR and foreign IBAN (spaces/dashes/lower case; without `TR` if labelled) | ISO 7064 mod-97 | MASK |
191
+ | `KART` | Visa/MC/Amex/Discover/JCB/Diners/**Troy** | Luhn + BIN | MASK, only the last 4 digits restored |
192
+ | `KART_CVV`, `KART_SKT` | CVV, expiry date | context | MASK (CVV is never restored) |
193
+ | `TELEFON` | mobile, landline (real area codes), 0850, 0812 | numbering plan; record-number contexts excluded | MASK (444/0800 optional) |
194
+ | `EPOSTA`, `IP`, `MAC` | incl. e-mails obfuscated with `[at]`/`(at)` | IPv4/IPv6 validation, version numbers excluded | MASK (MAC: IGNORE) |
195
+ | `PLAKA` | licence plates `34 ABC 123`, `06-A-1234` | province code 01–81, letter/digit length rules | MASK |
196
+ | `PASAPORT`, `KIMLIK_SERI`, `EHLIYET`, `SGK`, `NUFUS_KAYIT` | identity documents (incl. old ID cards) | context required | MASK |
197
+ | `HESAP_NO`, `MUSTERI_NO`, `MKK_SICIL`, `POLICE_NO`, `MERSIS`, `ETTN`, `IMEI`, `SASI_NO`, `ADRES_KODU` | financial/corporate identifiers | context (+Luhn/VKN) | MASK |
198
+ | `TICARET_SICIL` | trade registry number | context | IGNORE (legal entity; can be enabled for sole proprietorships) |
199
+ | `KRIPTO_CUZDAN` | BTC/ETH/TRON address | format | IGNORE |
200
+ | `SIFRE` | `şifre: …`, `password=…` (value must contain digits/symbols) | context | MASK, never restored (`****` in the response); strict: **BLOCK** |
201
+ | `GIZLI_ANAHTAR` | OpenAI/Anthropic/AWS/GitHub/Slack/Google/Stripe keys, JWT, private keys, connection-string passwords, Bearer | provider prefixes | MASK, `****` in the response (strict: BLOCK) |
202
+ | `KONUM` | coordinates linked to a person or personal record | context + link to a person | MASK |
203
+ | `DOGUM_TARIHI`, `DOGUM_YERI` | date/place of birth | birth context | MASK |
204
+ | `ADRES` | neighbourhood/street/avenue/no/flat, village/locality… | ≥2 anchors or `No`/number + province/district | MASK |
205
+ | `KISI` | first name, full name, `Ahmet YILMAZ`, titled names, `Ahmetin`, `AHMET'in` | 7k first-name + 23.9k surname lexicon, context, morphology, organisation-name exclusion | MASK |
206
+ | `OZEL_SAGLIK`, `OZEL_GENETIK`, `OZEL_BIYOMETRIK`, `OZEL_CINSEL`, `OZEL_CEZA` | KVKK art. 6: health, genetic, biometric, sex life, criminal conviction | term + **link to a person** (person/ID or 1st/2nd person in the same sentence) | MASK |
207
+ | `OZEL_DIN`, `OZEL_ETNIK`, `OZEL_SIYASI`, `OZEL_FELSEFI`, `OZEL_KIYAFET`, `OZEL_UYELIK`, `OZEL_CEZA_GENIS` | KVKK art. 6: religion, ethnicity, political opinion, philosophical belief, attire, membership, broader criminal data | same | LOG (counted only) |
208
+
209
+ Actions: `MASK` (placeholder, restored in the response), `BLOCK` (HTTP 400, error without values), `LOG` (counted in
210
+ the audit trail only), `IGNORE`.
211
+
212
+ ## Organisation-specific definitions
213
+
214
+ Built-in rules cover formats that are the same everywhere (TCKN, IBAN, phone, e-mail, URL encoding…). Formats that
215
+ differ between organisations (an account number in a log field, PNR, user name, order number) are added **through
216
+ configuration**; no code change is needed. `entity: KULLANICI_ADI` creates a `<KULLANICI_ADI_1>` placeholder that is
217
+ restored in the response.
218
+
219
+ | Field | When | Example |
220
+ |---|---|---|
221
+ | `extra_regex` | Organisation-specific identifiers with a known format | account no, PNR, user name |
222
+ | `deny_list` | Fixed phrases that must always be masked | project name, customer code |
223
+ | `allow_list` | Phrases that must never be masked | person names that look like product names (not applied to TCKN, VKN, IBAN, card, CVV, key, password) |
224
+
225
+ `extra_regex` fields:
226
+
227
+ | Field | Default | Description |
228
+ |---|---|---|
229
+ | `entity` | required | A new name (ASCII upper case, `_`) or an existing label (e.g. `TELEFON`; that entity's action then applies) |
230
+ | `pattern` | required | Python regex |
231
+ | `group` | — | Only this capture group (number or name) is masked: `'AccountId=([0-9]+)'` + `group: 1` → the number only |
232
+ | `score` | 0.8 | Priority when spans overlap |
233
+ | `context` | — | Regex; matches only if this phrase is within `context_window` characters of the value. Case- and Turkish-letter-insensitive (`reçete` = `RECETE`) |
234
+ | `context_window` | 60 | Distance searched for the context; if too wide, neighbouring numbers are caught too |
235
+ | `ignore_case` | `true` | For `pattern`; set `false` for upper-case codes (PNR) |
236
+ | `action` | `MASK` | `MASK`, `BLOCK`, `LOG`, `IGNORE` (new entity types only) |
237
+ | `restore` | `true` | `false`: not restored in the response (`****`) |
238
+
239
+ ```yaml
240
+ extra_regex:
241
+ - {entity: HESAP_NO, pattern: '(?:AccountId=|\|1=)([0-9]{6,12})', group: 1, score: 0.9}
242
+ - {entity: PNR, pattern: '(?<![0-9A-Za-z])[A-Z0-9]{6}(?![0-9A-Za-z])', context: 'pnr|booking ref', context_window: 25, ignore_case: false}
243
+ deny_list:
244
+ - {phrase: "Proje Kartal", entity: PROJE} # → <PROJE_1>, restored in the response
245
+ allow_list: ["Can Bey"]
246
+ ```
247
+
248
+ **Ready-made sector examples** ([`examples/sektor/`](https://github.com/MatriksData/matriks-pii/blob/main/examples/sektor)): finance/brokerage, airline, healthcare, insurance,
249
+ manufacturing, e-commerce/shipping, telecom and foreign formats (international phone numbers, US SSN, UK NINO). Each
250
+ file is tested in CI against its own evaluation set ([`tests/fixtures/sektor/`](https://github.com/MatriksData/matriks-pii/blob/main/tests/fixtures/sektor)). They are
251
+ starting points; narrow them to your real formats. To contribute a new sector file: [`CONTRIBUTING.md`](https://github.com/MatriksData/matriks-pii/blob/main/CONTRIBUTING.md).
252
+
253
+ **Built-in sector types:** `HESAP_NO`, `MUSTERI_NO`, `MKK_SICIL`, `POLICE_NO` are finance/insurance specific but fire
254
+ only in their own context ("hesap no", "MKK sicil", "poliçe no"), so they do not cause false positives in other sectors.
255
+
256
+ ### Writing and validating rules
257
+
258
+ ```bash
259
+ # 1) add the rule to the config and try a single text (no values printed; --show-values only for local debugging)
260
+ matriks-pii selftest --config config.yaml --probe "PNR: TX4K9Q yolcu Ayşe Demir"
261
+ # probe: entity=PNR start=5 end=11 score=0.8 recognizer=extra_regex
262
+ matriks-pii mask --config config.yaml "PNR: TX4K9Q yolcu Ayşe Demir"
263
+ # PNR: <PNR_1> yolcu <KISI_1>
264
+
265
+ # 2) measure on your own labelled set (one JSON per line; rows that must not be masked have "entities": [])
266
+ matriks-pii selftest --config config.yaml --corpus set.jsonl
267
+ ```
268
+
269
+ ```json
270
+ {"text": "PNR: TX4K9Q yolcu Ayşe Demir", "entities": [{"entity": "PNR", "value": "TX4K9Q"}, {"entity": "KISI", "value": "Ayşe Demir"}]}
271
+ {"text": "TK1984 seferi 14:30 kalkış, kapı B12", "entities": []}
272
+ ```
273
+
274
+ > **When evaluating the product:** define your organisation-specific formats before measuring and leave out-of-scope
275
+ > types (e.g. user names, if you did not define them) out of the denominator; otherwise the result measures missing
276
+ > configuration, not the product. Measure on a separate labelled set the rules have not seen.
277
+
278
+ ### Domestic / foreign coverage
279
+
280
+ The core is written for Turkey. **Outside Turkey, personal data in your own country's formats is largely not covered
281
+ out of the box.**
282
+
283
+ | Data | Turkey | Other countries |
284
+ |---|---|---|
285
+ | National ID number | TCKN, VKN | not built in (SSN, NINO: [`yurtdisi.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/sektor/yurtdisi.yaml)) |
286
+ | Phone number | detected | not built in ([`yurtdisi.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/sektor/yurtdisi.yaml)) |
287
+ | IBAN, card | detected | detected |
288
+ | Passport | with context | with context |
289
+ | E-mail, IP | detected | detected |
290
+ | Full name | lexicon + morphology | NER mode only (`ner_backend: hf`) |
291
+ | Address | detected | not detected |
292
+
293
+ ## Profiles
294
+
295
+ | Profile | What it does |
296
+ |---|---|
297
+ | `balanced` (default) | The table above |
298
+ | `strict` | All `OZEL_*`, crypto, MAC, trade registry MASK; `GIZLI_ANAHTAR` BLOCK; 444 lines MASK; placeholder instruction to the LLM; scanning responses for new PII; labelled values with invalid checksums are masked too |
299
+ | `minimal` | Only TCKN, VKN, IBAN, KART, TELEFON, EPOSTA, KISI, GIZLI_ANAHTAR; `OZEL_*` LOG |
300
+
301
+ Explicit keys override the profile: `entities: {OZEL_DIN: MASK, PLAKA: IGNORE}`. Unknown entity names fail at startup.
302
+
303
+ ## Key settings
304
+
305
+ | Setting | Default | Description |
306
+ |---|---|---|
307
+ | `placeholder_format` | `<{label}_{n}>` | `__{label}_{n}__`, `[{label}_{n}]`, `PII_{label}_{n}` … |
308
+ | `placeholder_id` | `sequence` | `hmac` + `hash_secret`: the same value gets the same placeholder across turns/replicas (prompt-cache friendly; numbering does not shift in a sliding window) |
309
+ | `fail_mode` | `closed` | If the guardrail fails, the request does **not** reach the LLM (HTTP 500) |
310
+ | `revert_fail_mode` | `closed` | If restoration fails **or the session is not found**, the response does not reach the client with placeholders (HTTP 500) |
311
+ | `dry_run` | `false` | Shadow mode: nothing is masked/blocked, only "would mask" counts are logged (gradual rollout) |
312
+ | `mask_logs` | `true` | Re-masks the (restored) response and the request that the proxy logs |
313
+ | `session_store` | `memory`, TTL 3600 s, 10,000 sessions | `redis`: AES-GCM encrypted; `redis_timeout_seconds` (2 s), circuit breaker, `require_tls`, `encryption_key_previous` (rotation) |
314
+ | `session_secret` | — (`MATRIKS_PII_SESSION_SECRET`) | HMAC secret for session tokens, ≥32 characters; **required** with the `redis` store, identical on all instances; `session_secret_previous` (rotation) |
315
+ | `max_text_chars`, `max_request_chars` | 2 MB, 4 MB | If exceeded, the request is cleared, HTTP 413 |
316
+ | `analysis_threads` | 4 | Dedicated thread pool for analysis/log masking (does not starve LiteLLM's executor) |
317
+ | `analysis_cache` | 2048 entries, 300 s, 200k spans | In-memory span list (with original values); `max_entries: 0` disables it; texts over 64 KB are not cached |
318
+ | `unsupported_call_types` | `mask` | For rerank/image/audio/MCP calls: `mask` (no restoration), `pass`, `block` |
319
+ | `gemini_native` | `true` | Full mask/restore on Gemini `/v1beta/models/...:generateContent` (+ stream) |
320
+ | `audit_log` | off | Value-free JSONL audit trail (who, when, how many of which entity type, score buckets) |
321
+ | `metrics_enabled` | `true` | `matriks_pii_*` counters if `prometheus_client` is installed (value-free labels) |
322
+ | `placeholder_instruction` | `none` | `system_suffix` (recommended): appends an instruction to the system message: use placeholders as if they were real values, do not mention masking, do not abbreviate |
323
+ | `label_aliases` | `PERSON→KISI, PHONE→TELEFON…` | Labels translated by the LLM (`<PERSON_1>`) are restored only in bracketed form; `{}` disables |
324
+ | `scan_response` | `false` (`strict`: on) | Masks NEW personal data generated by the LLM in the response (not restored; not applied to streams) |
325
+ | `response_json_preserve_format` | `true` | JSON text in response content is restored with its formatting (indentation, order) preserved |
326
+ | `suffix_repair` / `suffix_repair_attached` | `true` / `false` | Turkish suffix repair; suffixes attached without an apostrophe (`<KISI_1>lar` → `Demirler`) behind a flag |
327
+ | `tool_restore_policy` | `all` | `none`: tool call arguments keep placeholders |
328
+ | `mask_system_messages`, `mask_assistant_messages`, `mask_tool_messages`, `mask_embeddings` | `true` | |
329
+ | `name_detection.ner_backend` | `none` | `hf`: Turkish NER; `ner_max_chars` (sentence-based chunking), `ner_timeout_seconds`, `ner_fail_mode` (`closed`/`lexicon`), `ner_preload` |
330
+ | `checksum_policy` | `strict` (`strict` profile: `context`) | `context`: explicitly labelled values are masked even if the check digit is wrong |
331
+
332
+ Environment variables can be referenced as `os.environ/NAME` (`hash_secret: os.environ/MATRIKS_PII_HASH_SECRET`). A
333
+ warning is printed at startup if secrets are given in plain text (`MATRIKS_PII_STRICT_SECRETS=1` → error). Secrets
334
+ never enter `config_hash`, error messages or logs.
335
+
336
+ ### Errors
337
+
338
+ | Situation | HTTP | `detail.error` | What happens |
339
+ |---|---|---|---|
340
+ | Blocked by policy (`BLOCK`) | 400 | `matriks_pii_blocked` | has an `entity` field, no value; the request is masked before it is logged |
341
+ | Text/request too large | 413 | `matriks_pii_text_too_large` | request cleared; independent of `fail_mode` |
342
+ | Guardrail internal error | 500 | `matriks_pii_guardrail_failure` | `fail_mode: closed` → request cleared, never reaches the provider |
343
+ | Session not found (TTL, secret mismatch, store) | 500 | `matriks_pii_session_missing` | `revert_fail_mode: closed` → response is not sent with placeholders |
344
+ | Session store unreachable | 503 | `matriks_pii_store_unavailable` | only requests containing PII are affected (no session is written for PII-free requests) |
345
+ | Restoration error | 500 | `matriks_pii_revert_failure` | `revert_fail_mode: open` → response returned with placeholders |
346
+
347
+ If an error occurs in a stream before the first chunk, LiteLLM turns it into an SSE error frame (HTTP status may
348
+ already have been sent as 200); in no case are raw values or placeholders emitted.
349
+
350
+ ### Multiple workers / replicas
351
+
352
+ The pre-call and post-call hooks of a request run in the same process; a `memory` store is enough for a single pod.
353
+ Redis is recommended for Admin UI "guardrail test" (`apply_guardrail`) pairs behind many pods/replicas, for keeping
354
+ sessions across restarts and for moving the memory limit out of the process.
355
+
356
+ 1. Generate secrets **once** and put them in a secret manager: `matriks-pii keys` (`--k8s` for a kubectl command).
357
+ 2. `pip install "matriks-mask[redis,fast]"`.
358
+ 3. [`examples/config.redis.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/config.redis.yaml):
359
+
360
+ ```yaml
361
+ guardrails:
362
+ - guardrail_name: matriks-pii
363
+ litellm_params:
364
+ guardrail: matriks_pii.guardrail.TurkishPIIGuardrail
365
+ mode: [pre_call, post_call]
366
+ default_on: true
367
+ session_secret: os.environ/MATRIKS_PII_SESSION_SECRET
368
+ session_store:
369
+ backend: redis
370
+ redis_url: os.environ/MATRIKS_PII_REDIS_URL # rediss://:password@redis:6380/0 (TLS recommended)
371
+ encryption_key: os.environ/MATRIKS_PII_STORE_KEY
372
+ ttl_seconds: 3600 # ≥ LiteLLM request_timeout
373
+ redis_timeout_seconds: 2
374
+ require_tls: true
375
+ ```
376
+
377
+ `*_PREVIOUS` variables for zero-downtime secret/key rotation: [`docs/RUNBOOK.md`](https://github.com/MatriksData/matriks-pii/blob/main/docs/RUNBOOK.md#sır-ve-anahtar-rotasyonu-kesintisiz).
378
+
379
+ ### Per-tenant (key/team) policy
380
+
381
+ Define several guardrail instances for different policies (`matriks-pii`, `matriks-pii-strict` …, `default_on: false`)
382
+ and add them to the key/team `guardrails` list. Session tokens are separated by guardrail name; two instances can run
383
+ together on the same request.
384
+
385
+ ## Supported calls
386
+
387
+ | Endpoint | Request | Response | Streaming |
388
+ |---|---|---|---|
389
+ | `/chat/completions` | text, multi-part content, `tool_calls` JSON arguments, `name`, `reasoning_content` | content, tool calls, `reasoning_content`, `n>1` | content, reasoning, tool arguments (JSON-escaped) |
390
+ | `/completions`, `/embeddings` | `prompt`, `input` (str/list) | `choices[].text` | `/completions`: `choices[].text` chunks |
391
+ | `/responses` | `input`, `instructions`, `function_call(_output)`, `prompt.variables` | `output` | `response.*.delta/done/completed` events |
392
+ | `/v1/messages` (Anthropic) | `system`, `tool_use`, `tool_result`, `document` | `content` | raw SSE (`text_delta`, `input_json_delta`), byte-level UTF-8 safe |
393
+ | `/v1beta/models/...:generateContent` (Gemini) | `contents[].parts[]`, `systemInstruction`, `functionCall/Response` | `candidates[].content.parts[]` | raw SSE frames, per-candidate buffer |
394
+ | rerank, image, audio, MCP | text fields masked (`unsupported_call_types`) | not restored | — |
395
+
396
+ Cross-format parity is verified by the `tests/test_parity.py` matrix (5 formats × 15 features); cells that do not
397
+ apply are listed there with a reason.
398
+
399
+ Texts with JSON content (tool arguments, JSON messages, numbers and keys included) are parsed and masked leaf by leaf;
400
+ JSON content in responses is restored with its formatting preserved.
401
+
402
+ ## Quality and performance
403
+
404
+ All tests: `pytest -q` (≈2.3k tests + hypothesis property tests), `pytest -m benchmark`, `pytest -m e2e` (real LiteLLM
405
+ proxy + OpenAI-compatible and Gemini echo servers), `pytest -m external`, `pytest -m ner`, `pytest -m redis_live`.
406
+
407
+ - Positive/mixed fixtures (733 detection + 76 restoration + 37 streaming + 94 hook scenarios + 52 sector-example rows) and **596 false-positive
408
+ traps** (stock tickers, ISINs, VIOP contracts, numbers with invalid checksums, organisation names, currency pairs,
409
+ secret-key prefixes, news sentences about special categories…): `python scripts/corpus_report.py`. In the default
410
+ lexicon mode the false-positive count is 0.
411
+ - Two synthetic evaluation sets written by separate LLM agents (AI models) that had no access to the implementation:
412
+ `tests/fixtures/holdout/` (results below).
413
+
414
+ | Set | Rows (PII / traps) | Measurement | P | R | F2 |
415
+ |---|---|---|---|---|---|
416
+ | holdout-1 (`holdout.jsonl`), KISI | 269 (162 / 107) | blind, before fixes | 0.947 | 0.831 | 0.852 |
417
+ | holdout-1, KISI | | after general fixes | 0.977 | 0.977 | 0.977 |
418
+ | holdout-2 (`holdout2.jsonl`), all entities, `balanced` | 345 (226 / 119) | blind, before fixes | 0.954 | 0.934 | 0.938 |
419
+ | holdout-2, all entities, `balanced` | | after general fixes | 0.991 | 0.994 | 0.993 |
420
+ | holdout-2, all entities, `strict` | | after general fixes | 0.974 | 0.994 | 0.990 |
421
+
422
+ Holdout-2 also covers the newer entities (`GIZLI_ANAHTAR`, `KONUM`, `MKK_SICIL`, `POLICE_NO`). After the blind
423
+ measurement only fixes that are not specific to the set were made; the remaining 3 rows are differences of
424
+ interpretation. Since the sets are no longer blind, `tests/test_holdout.py` only catches regressions (FP = FN = 0 for
425
+ deterministic entities; KISI R ≥ 0.95, F2 ≥ 0.95; OZEL_* recall ≥ 0.90 on holdout-2).
426
+
427
+ NER mode (`ner_backend: hf`, `akdeniz27/bert-base-turkish-cased-ner`; `python scripts/corpus_report.py --ner`):
428
+ `KISI` F2 ≈ 0.99 on the fixtures; the 512-token limit is handled by sentence-based chunking. In NER mode the negative
429
+ set is informational (the model also catches real foreign names).
430
+
431
+ **Third-party Turkish datasets** (`python scripts/external_bench.py --download`; no rows were copied into fixtures
432
+ during development, only general rules were fixed). Out-of-scope labels (nationality, salary, user name, credit
433
+ score…) are not counted:
434
+
435
+ | Dataset | Profile | P | R | F2 | Note |
436
+ |---|---|---|---|---|---|
437
+ | [cagrigungor/turkish-pii-masking-benchmark](https://huggingface.co/datasets/cagrigungor/turkish-pii-masking-benchmark) (1,000 rows, CC0) | `strict` | 0.978 | 0.944 | **0.950** | |
438
+ | same | `balanced` | 0.985 | 0.749 | 0.787 | most of the gap is special categories that are only LOGged (religion, ethnicity, union) |
439
+ | [Werea-co/Werea-KVKK-Bench](https://huggingface.co/datasets/Werea-co/Werea-KVKK-Bench) `pii_synthetic` (2,400 rows, Apache-2.0) | `strict` | **1.000** | 0.627 | 0.677 | most misses are general special-category sentences not linked to a person — intentional under KVKK art. 3/1-d |
440
+
441
+ Latency (single core, NER off, cache off; `python scripts/bench.py`):
442
+
443
+ | Input | p50 (ms) | p99 (ms) |
444
+ |---|---|---|
445
+ | 256 characters | 0.51 | 0.96 |
446
+ | 2048 characters | 2.8–3.0 | 3.3–3.5 |
447
+ | 10000 characters | 14.0 | 21.9 |
448
+ | 50000 characters | 79.9 | 93.6 |
449
+ | stream chunk (5 characters) | 0.012 | — |
450
+
451
+ Total text over 8 KB (every text when NER is on) is analysed in the dedicated thread pool; the event loop is not
452
+ blocked. Pathological inputs (100 KB digit runs, thousands of invalid IBAN candidates, long whitespace runs) are
453
+ processed in linear time.
454
+
455
+ ## Operations
456
+
457
+ - **Metrics** (`pip install "matriks-mask[metrics]"`, `callbacks: ["prometheus"]` in LiteLLM): `matriks_pii_entities_total`,
458
+ `matriks_pii_hook_seconds`, `matriks_pii_hook_total`, `matriks_pii_events_total` (session_missing, store_unavailable,
459
+ blocked, unresolved_placeholder, ner_failed, audit_write_failed, dry_run_would_mask), `matriks_pii_scores_total`,
460
+ `matriks_pii_sessions_open`, `matriks_pii_cache_entries`. Safe in multi-worker mode.
461
+ - **Gradual rollout:** first `dry_run: true` (staging 5 business days, production 1 week), then a per-key canary, then `default_on`.
462
+ - **Rollback:** wheel + config as a pair; in an emergency `MATRIKS_PII_IGNORE_UNKNOWN_KEYS=1`. Details: [`docs/RUNBOOK.md`](https://github.com/MatriksData/matriks-pii/blob/main/docs/RUNBOOK.md).
463
+
464
+ ## KVKK and sector regulation (not legal advice)
465
+
466
+ - **Terminology:** As long as the mapping is kept in memory, this processing is not anonymisation but the use of
467
+ codes/pseudonyms (KVKK Guide on Deletion, Destruction or Anonymisation of Personal Data; Guide on Generative AI and
468
+ the Protection of Personal Data (in 15 Questions), 24.11.2025). For the data controller the data remains personal
469
+ data; the exemption in art. 28/1-b cannot be relied upon.
470
+ - **Transfers abroad (art. 9, Regulation of 10.07.2024):** A request to an LLM abroad is a transfer; masking reduces
471
+ the risk but does not remove the obligation. Standard Contract 2 must be signed and notified to the Authority within
472
+ 5 business days. Continuous API traffic is not "incidental".
473
+ - **Special categories (art. 6):** health/genetic/biometric/sex life/criminal data are MASKed by default;
474
+ `profile: strict` masks all of them, and `BLOCK` ensures they are never sent. A criminal conviction is a final
475
+ judgment; suspect/defendant/custody are separate (`OZEL_CEZA_GENIS`).
476
+ - **Data security (art. 12):** fail-closed defaults, value-free audit trail and metrics, masking in logs, AES-GCM in
477
+ Redis; the mapping is never written to metadata (`store_map_in_metadata` only with `MATRIKS_PII_ALLOW_DEBUG_MAP=1`);
478
+ API keys are masked.
479
+ - **Capital markets and banking regulation:** Organisations in these sectors are also subject to regulations such as
480
+ the Capital Markets Board (SPK) Communiqué on Information Systems Management (VII-128.10), Banking Law No. 5411
481
+ art. 73 (confidentiality) and the BDDK Regulation on the Sharing of Confidential Information; the plugin does not
482
+ fulfil these obligations. Banks should assess for themselves whether the tool is suitable for de-identification
483
+ purposes under the Confidentiality Regulation.
484
+ - **Test data:** All test fixtures in the repository are synthetic; they contain no data belonging to real persons.
485
+
486
+ Category mapping and audit trail fields: [`docs/KVKK_VERI_KATEGORILERI.md`](https://github.com/MatriksData/matriks-pii/blob/main/docs/KVKK_VERI_KATEGORILERI.md).
487
+
488
+ **Obligations outside the plugin:** SCC-2 + notification, a data processing agreement with the provider
489
+ (sub-processors, no training use, retention period), DPIA, privacy notice, VERBİS/inventory, breach response plan
490
+ (72 hours), employee training, red-team testing.
491
+
492
+ ## Known limitations
493
+
494
+ - Free-text names written entirely in lower case (`ahmet yılmaz dün geldi`) are caught only in form/field context;
495
+ NER mode is recommended. Names inside company names (`Ahmet Yılmaz Holding`) are not masked; sole-proprietorship
496
+ names (`Mehmet Kaya Kuyumculuk`) are treated as personal data and masked.
497
+ - Foreign names (not in the lexicon) are caught in lexicon mode only with context; NER mode is recommended. Single
498
+ names that are also common words are caught mid-sentence (`Dün Deniz aradı`), but not at the start of a sentence
499
+ without context (`Deniz kenarında`).
500
+ - Numbers split by zero-width characters (`1729​1716060`) are not detected. Full-width digits (`1729…`) are detected.
501
+ - URL-encoded (`%40`, `%20`; only inside URLs/forms, Turkish percent notation such as "%40" excluded) and HTML-entity
502
+ (`&#64;`) values are decoded for scanning and the original encoded range is masked. Not decoded: form `+` for
503
+ spaces (`tel=0532+123+45+67`), a run containing an invalid byte (`%40%FF`), triple encoding (`%252540`), a single
504
+ `%XX` run outside a URL/form, and other encodings such as Base64.
505
+ - A value written directly inside angle brackets (`Ayşe Demir <ayse.demir@example.com>`) is restored without the
506
+ brackets in the response (`<<EPOSTA_1>>` is read as a double-bracket placeholder).
507
+ - Foreign phone numbers and foreign national ID numbers are not built in; see [`yurtdisi.yaml`](https://github.com/MatriksData/matriks-pii/blob/main/examples/sektor/yurtdisi.yaml).
508
+ - Personal data inside images/files (PDFs, ID card photos) is not scanned; such content reaches the provider as is.
509
+ - History kept server-side via Responses API `previous_response_id` cannot be masked.
510
+ - In Anthropic `/anthropic/*` **passthrough** streaming, LiteLLM does not call the post-call guardrail (LiteLLM #42476);
511
+ use `/v1/messages`.
512
+ - Signed Anthropic `thinking` blocks and signed Gemini thought parts are not modified (the signature would break).
513
+ - In multi-turn conversations `sequence` numbering can shift in a sliding window; `placeholder_id: hmac` is
514
+ recommended. A literal `<KISI_1>` sent back by the client is reserved (a new value gets `<KISI_2>`).
515
+ - With `response_json_preserve_format` on, `scan_response` also works on JSON content, but the JSON is rewritten if
516
+ anything changes.
517
+ - Analysis is CPU-bound and runs under the Python GIL; increase the number of workers for very high concurrency.
518
+ - LiteLLM's own `--detailed_debug` prints the raw body before the guardrail runs; turn it off in production.
519
+
520
+ ## Roadmap
521
+
522
+ - **Surrogate (fake value) mode — deferred to v2.** In Turkish, suffixes of a fake name (`Elif'e` ↔ `Ayşe'ye`) must be
523
+ repaired in both directions and restoration must be proven unambiguous; the current placeholder + suffix repair
524
+ approach does not carry these risks.
525
+ - Scanning text inside images/PDFs (OCR); Anthropic passthrough streaming (awaiting a fix in LiteLLM).
526
+
527
+ ## Development
528
+
529
+ ```bash
530
+ python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
531
+ pip install -e ".[dev,fast,metrics]"
532
+ export MATRIKS_PII_HASH_SECRET=0123456789abcdef0123456789abcdef # for the strict example config's selftest
533
+ # Windows: set PYTHONUTF8=1 && set MATRIKS_PII_HASH_SECRET=...
534
+ pytest -q && pytest -q -m benchmark && pytest -q -m e2e
535
+ python scripts/external_bench.py --download && pytest -q -m external
536
+ ruff check matriks_pii scripts tests && mypy matriks_pii --ignore-missing-imports
537
+ python scripts/corpus_report.py
538
+ matriks-pii selftest --config examples/config.yaml
539
+ # to rebuild the lexicons:
540
+ python scripts/fetch_raw.py && python scripts/build_name_lists.py && python scripts/build_common_words.py && python scripts/build_geo.py
541
+ python scripts/build_org_names.py # optional KAP company-name list: scripts/_raw/kap_companies.txt
542
+ ```
543
+
544
+ `scripts/build_fixtures.py` rewrites the generated files under `detect/revert/streaming`; hand-written files
545
+ (`*_ek.yaml`, `*_x.yaml`, `yeni_varliklar.yaml`, `sayisal_ek.yaml`) are not affected.
546
+
547
+ Data sources and licences: [`matriks_pii/data/LICENSES.md`](https://github.com/MatriksData/matriks-pii/blob/main/matriks_pii/data/LICENSES.md).
548
+
549
+ ## Contributing and security
550
+
551
+ - Contribution guidelines (setup, tests, synthetic data only): [`CONTRIBUTING.md`](https://github.com/MatriksData/matriks-pii/blob/main/CONTRIBUTING.md). Issues and pull
552
+ requests may be written in English or Turkish.
553
+ - Code of conduct: [`CODE_OF_CONDUCT.md`](https://github.com/MatriksData/matriks-pii/blob/main/CODE_OF_CONDUCT.md).
554
+ - Reporting a vulnerability (do not open a public issue): [`SECURITY.md`](https://github.com/MatriksData/matriks-pii/blob/main/SECURITY.md).
555
+
556
+ ## License
557
+
558
+ The source code is licensed under the [Apache License 2.0](https://github.com/MatriksData/matriks-pii/blob/main/LICENSE), © 2026 Matriks Finansal Teknolojiler A.Ş.
559
+ (see [`NOTICE`](https://github.com/MatriksData/matriks-pii/blob/main/NOTICE)).
560
+
561
+ The package includes data files derived from third-party sources. The first-name/surname lists come from
562
+ [mkozturk/trnames](https://github.com/mkozturk/trnames) (MIT) and the province/district data from
563
+ [ubeydeozdmr/turkiye-api](https://github.com/ubeydeozdmr/turkiye-api) (MIT).
564
+ `matriks_pii/data/tr_words.txt` is derived from the OpenSubtitles 2018 Turkish word list in Hermit Dave's
565
+ [FrequencyWords](https://github.com/hermitdave/FrequencyWords) project and is licensed under
566
+ [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/); this file is not covered by the Apache-2.0 licence.
567
+ Details and licence texts: [`THIRD_PARTY_NOTICES.md`](https://github.com/MatriksData/matriks-pii/blob/main/THIRD_PARTY_NOTICES.md).
568
+
569
+ **Trademark.** The licence does not grant the right to use the "Matriks" name or logos (Apache-2.0 section 6).
570
+ Modified versions of the software must be distributed under a different name; the "Matriks" name may be used only to
571
+ indicate the origin of the software.
572
+
573
+ **Disclaimer of warranty.** The software is provided "AS IS" under sections 7 and 8 of the licence; detection of every
574
+ piece of personal data is not guaranteed.
575
+
576
+ This README is a translation of [README.tr.md](https://github.com/MatriksData/matriks-pii/blob/main/README.tr.md); in case of discrepancy the Turkish version prevails.
@@ -0,0 +1,65 @@
1
+ matriks_mask-0.4.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
2
+ matriks_mask-0.4.0.dist-info/licenses/NOTICE,sha256=O6XP76gVdI1X2buuxaR5xMTU8n1iIT1vcA2LSqAARVs,909
3
+ matriks_mask-0.4.0.dist-info/licenses/THIRD_PARTY_NOTICES.md,sha256=FS61IMaT5Z6zTKu88erThtuOrCHX3S59D7Hxf8PA1vA,5603
4
+ matriks_pii/__init__.py,sha256=8ETtRS0i_CxTIfI2fD8foJPIdRx1d719-eJmL45M9fo,1165
5
+ matriks_pii/audit.py,sha256=HUMash49AvfKGOYqolTJoMlZ92vB5v0XOt7NAh6a0go,2985
6
+ matriks_pii/cli.py,sha256=9ytFLo9l_-R6kZsCsrQ0jDFqgyH8ne5VeXe0ui6bhAE,4982
7
+ matriks_pii/config.py,sha256=8qJZ3P_O1gstxIw8AT7jq-30eUIG9URkp_bitvQqQRU,28424
8
+ matriks_pii/engine.py,sha256=coqMolGtGfGYc6L3irMUACFWzL-JJ-O59TvcD1y6Z5g,11884
9
+ matriks_pii/guardrail.py,sha256=QC_SfYgzvc3khFf5TV5sD4CAUOroFi2YeEPb1ItgjgE,53267
10
+ matriks_pii/keys.py,sha256=6wNlACic9TTgxYvDjomrmubdlV_sx0VMUsLZPTVjR1A,1347
11
+ matriks_pii/metrics.py,sha256=T7OlefoSVJ8XRbXe4WSF97gny3_New2Yzqp-xihmb3s,4451
12
+ matriks_pii/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ matriks_pii/revert.py,sha256=p1CNePd1Y6za_Wr9DnYwx5qYlIvjWgpoaml1S2mcqQM,13231
14
+ matriks_pii/selftest.py,sha256=_yZDsCAL5p956RRdDs7dbLN0xVOwwjNubuNm78Ad284,12114
15
+ matriks_pii/session.py,sha256=GopwmWz6zqWfB5qpKlYDhFt0f9Det8IuV_9Txy8fYT0,6308
16
+ matriks_pii/store.py,sha256=ND1IoQFLKzbuKrpXA14TwrNyrfHaRIOJm2aXElVuics,7849
17
+ matriks_pii/streaming.py,sha256=vHroCrDdZU0pEXObhPOmdrLrnNE72D6sUM6quDinXgQ,24017
18
+ matriks_pii/text_utils.py,sha256=lCzICx1Kz5HQQGck-ugAjSC0eAdje8JxW3Eiq1yEP5M,10850
19
+ matriks_pii/tr_morphology.py,sha256=iACJVITB-SUHNzDpUID76y5EfAGmiu8FHoS4FE9vEjw,8932
20
+ matriks_pii/traverse.py,sha256=VqJxKr4UHPdW45tWXNw4SmIjS8MUrzkJ7f3kYtqSx28,26352
21
+ matriks_pii/data/LICENSES.md,sha256=XE6sBo_sjvzN9_E7EVxnVuQE9YNekNKYmEWnJ3XAztk,2359
22
+ matriks_pii/data/__init__.py,sha256=Y7gB7qijfq_KOYyINxs5i1r5fs7drhcJAgEl0BNlfhM,6740
23
+ matriks_pii/data/common_words_tr.txt,sha256=CBslWg44Bi8Ujz01To2Lzdir4VkH2WOlFCvk-hgrZuc,3418
24
+ matriks_pii/data/first_names_tr.txt,sha256=p-FciFUzwAI-oU0QVIqwmvOLBLxUI2e8S6rj61u7FsI,49202
25
+ matriks_pii/data/frequent_first_names_tr.txt,sha256=BuEVWAWOukmIviJpPPdgFtwb2TeLwRC5FdV0OIlCO0c,7023
26
+ matriks_pii/data/frequent_last_names_tr.txt,sha256=L6QjMaSyzXWpqxqztZ4mSkMHwImOte3SlYR36wtnGXA,21451
27
+ matriks_pii/data/honorifics_tr.txt,sha256=BUIcP43QdfXP-ITuRvDcEuFJJwNuCzgblPL9trK_K1M,964
28
+ matriks_pii/data/il_ilce_tr.json,sha256=XLS5wKBS69nEAYQuH_2hND5IFxAZ5-xKgCyYXerC9yw,220949
29
+ matriks_pii/data/last_names_tr.txt,sha256=7CABOVUmrSn0WEDz4YrtQigzWUHqd0XjUPkSn_yvMnw,201123
30
+ matriks_pii/data/org_names_tr.txt,sha256=MaqsU7gTcP5vTwZhTrlsQCtydw3XFjFk_8GzUeq20DQ,2907
31
+ matriks_pii/data/org_suffixes_tr.txt,sha256=8sP9Huu4POKmjhg0G3cbd6aOX-Zq9tb7rBJhBMIXGvs,1360
32
+ matriks_pii/data/popular_first_names_tr.txt,sha256=OIsgaAqaRyVVlSWxwOsToz611QzjlHORVr2H8HWujew,3746
33
+ matriks_pii/data/tr_words.txt,sha256=Y7HzcYry6Xg3nV9-ap5HefhymN1vV7okW1tMQesxUq8,434247
34
+ matriks_pii/data/special_category/README.txt,sha256=SVahnKpyCKdK5eopxmDxwR8jmtpyCVL0MEYM6UFEhjA,333
35
+ matriks_pii/data/special_category/biyometrik.txt,sha256=XxJRy6z7nSWbngqlDio1k2ae55SytR4StBFA4UXjpZA,303
36
+ matriks_pii/data/special_category/ceza.txt,sha256=bR7j2XzowIn1JWir7T2rxSehmeXhv6B-skdGePVbToU,482
37
+ matriks_pii/data/special_category/ceza_genis.txt,sha256=9BmTcIOcT2PA71RhpRSd3QgXmAwZnJ-VeiptF7eZRwA,136
38
+ matriks_pii/data/special_category/cinsel.txt,sha256=mc4AquNYvJbOckJay9ubpXTxnvSM-BivjpmLdc98omw,242
39
+ matriks_pii/data/special_category/din.txt,sha256=3mD8K5mv3LOb3r4SahshaZFtNOpEjHvyOXERcsosKbY,577
40
+ matriks_pii/data/special_category/etnik.txt,sha256=1tjB05-UIIBJ0SutSr1ICqVMt6v9Z75U1YTWeh8hia8,319
41
+ matriks_pii/data/special_category/felsefi.txt,sha256=opTjdXpWiMxJdkPQMm_ogSRfhQ1agJ4aqKsLEUsMYP4,130
42
+ matriks_pii/data/special_category/genetik.txt,sha256=6iZ5-KQBrjG0Mavx4waV5fVMXthbfnQGfJChQmHy7nM,264
43
+ matriks_pii/data/special_category/kiyafet.txt,sha256=GXrFLWhpP15otEXVyeo24xmUt6PNv-OYrZwDq8v0dRc,221
44
+ matriks_pii/data/special_category/saglik.txt,sha256=Nep4_ccJVpru5GKTeiU7Iw5eAqTs79yhmtRn24l0ryk,1933
45
+ matriks_pii/data/special_category/siyasi.txt,sha256=zWMxkqHfN3M6Uo4pOYs6wz-NbdffxDrLsUjqRpOMYa0,408
46
+ matriks_pii/data/special_category/uyelik.txt,sha256=HpxPAFBQSPOTaAY00bo94C1EqQv_CqnvIMTVnb07Zcc,410
47
+ matriks_pii/recognizers/__init__.py,sha256=kzZdgH-dZO7UCBtWOQzXNmtR4lyUiLb8afnghZ4yjvk,1937
48
+ matriks_pii/recognizers/address.py,sha256=Btldi5RIPL4RfzWD8b_DgYTiORPH5cot_JZ7D7R2KbU,8616
49
+ matriks_pii/recognizers/base.py,sha256=6VMUFLz-KUcDxKeTB7rbLMFr49617Sz5AYP5y6qcM3Q,4462
50
+ matriks_pii/recognizers/checksums.py,sha256=_npw41JOeL8ycrvMlhy5Zv0cdrg3T70SVAihG1xwoek,3577
51
+ matriks_pii/recognizers/contextual.py,sha256=KXOZseWrXChyUyF70IUdzrMpNY62nSmVxQLpz9gD5wY,19943
52
+ matriks_pii/recognizers/location.py,sha256=EUfaBpKLb5q28Ukdp9Z4fYnmlXU7qrl5FG6L1X96eRc,4167
53
+ matriks_pii/recognizers/ner_hf.py,sha256=Kh_YzXYF9CwCfHlxdGmLW6ipyZ4M68XCVnpV8IYcESs,7933
54
+ matriks_pii/recognizers/number_words.py,sha256=XdV8Rj3_fzwu8mQSn9jA1N8K0O5BR7T7NHXx2DUDi_A,4205
55
+ matriks_pii/recognizers/numeric.py,sha256=zv0KGeBoGZ9dovZCXCq5RFhmE6o9bgOMbjlvlL58yH8,10406
56
+ matriks_pii/recognizers/person.py,sha256=FH_plWeE7W0PrHC4QaVOPHb0tbtPGxXP-U_vNfG9iI0,24506
57
+ matriks_pii/recognizers/phone.py,sha256=j3POx5UWBrpGPXfWbpsbiDm-bVBSqSEwunzLC3BmcGg,5762
58
+ matriks_pii/recognizers/secrets.py,sha256=WLDClopFpTm9-NNSbhYCdN_8RpCWTGffPa5enwcwCUU,3545
59
+ matriks_pii/recognizers/simple.py,sha256=9sG31nR994uorfgP0ZiGGUrweJcuWWbdEmalfrC8tIE,6308
60
+ matriks_pii/recognizers/special_category.py,sha256=VgkrVeE1MhVNRR_9UcVMZz0eRvXJB7nM1nlcgNWAvhk,16020
61
+ matriks_mask-0.4.0.dist-info/METADATA,sha256=kFBRGSsLY51M7HnKM-bDBY8V_RSXQLxP33fMA0tg7gc,39740
62
+ matriks_mask-0.4.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
63
+ matriks_mask-0.4.0.dist-info/entry_points.txt,sha256=uWSqBSilkt7biRkKlawPYpxBtonoOwdspXAZabhNKm0,89
64
+ matriks_mask-0.4.0.dist-info/top_level.txt,sha256=N9QwEfTjRF46vObkXLg0rEC2xU0EBbFUw3mK2TiedvY,12
65
+ matriks_mask-0.4.0.dist-info/RECORD,,