How do you measure the quality of PII detection?
Measure recall and precision separately for each type of identifier, each document type and each language, at the level of exact character spans, on a protected reference set built from your own documents. Report misses as a count of exposed identifiers, not only as a percentage. A single overall score hides the one identifier type the detector does not know, and that is usually the one that leaks.
No detector finds everything. The open-source Presidio project states on its evaluation page that no de-identification system is perfect and that performance has to be evaluated for each specific use case. It defines precision as TP ÷ (TP + FP) and recall as TP ÷ (TP + FN), notes that in PII detection recall is often more important than precision because the aim is to avoid missing any personal data, and recommends the F2 score, which weights recall more heavily. That is a sensible default, with one refinement: compute it per identifier type, not across all types at once.
Which identifiers belong on the list?
Build the list from your actual documents, not from a vendor's entity catalogue. Read a sample of invoices, call transcripts, forms and emails and record every piece of information that identifies a person, directly or in combination. In Turkish business documents the list typically includes the following:
| Identifier | What makes it hard | Detection approach |
|---|---|---|
| Turkish national ID number (T.C. kimlik no) | Eleven digits that can look like any other long number | Pattern plus check-digit validation plus context words |
| IBAN and card numbers | Spaces, line breaks and OCR errors split the number | Pattern plus checksum validation |
| Phone numbers | Many formats: +90, a leading 0, spaces, brackets | Pattern plus context |
| Person names | Many Turkish names are also ordinary words, such as Deniz, Can or Gül | Named entity recognition plus context, tested heavily |
| Addresses | Free text with no fixed format | Named entity recognition; often the weakest type |
| Internal customer, policy or subscriber numbers | Formats exist only in your organisation | Your own rules; generic detectors do not know them |
| Health or other special-category details in free text | Expressed in ordinary language rather than as a code | Custom classifiers or rules, plus human review |
The last two rows matter most. Microsoft's PII entity categories for Azure Language include a Türkiye national identification number type alongside person, phone number, email and IBAN, but no off-the-shelf catalogue contains your internal account format. Those identifiers need your own patterns, and they need their own line in every test report.
How do you build a safe reference set?
Use an authorised sample of real documents, label every identifier as a character span with its type, and keep the whole set in a restricted environment. The reference set is itself personal data, often concentrated: it has been selected precisely because it contains identifiers.
- Coverage: every document type and language the system will process, including OCR-heavy scans, forms filled in by hand and long call transcripts.
- Span labels: start and end offsets plus type for each identifier; two annotators for ambiguous text, with an adjudicator.
- Look-alikes: a separate set of harmless values that resemble identifiers, such as product codes, order numbers, dates and serial numbers, so over-masking can be measured.
- Access and retention: named users only, no copies in logs, notebooks or analytics tools, and a deletion date.
Synthetic documents are useful for early development and for sharing test cases safely, and Presidio's research tooling includes notebooks for generating such datasets. They rarely reproduce real OCR noise, local naming patterns or the way people actually write addresses, so the acceptance decision should rest on real documents.
How should detections be scored?
Score at the span level and separate full coverage from partial coverage. For redaction, the question is not whether the detector "found" an identifier but whether every character that identifies the person is covered. A mask over the first eight digits of an eleven-digit national ID number still leaves three digits visible, and a name masked in one place but not in the signature line is still exposed.
For each identifier type and document type, count:
- True spans in the reference set.
- Spans fully covered by a detection of any sensitive type.
- Spans only partly covered.
- Spans missed completely.
- False detections, especially on the look-alike set.
Decide in advance whether a correct span with the wrong type counts as a success. For masking it usually does; for routing documents to different retention rules it may not.
A recall-by-entity test plan
The table shows how results should be reported. The figures are a hypothetical example for one document type.
| Type | True spans | Fully covered | Partly covered | Missed | Full-span recall |
|---|---|---|---|---|---|
| National ID number | 120 | 118 | 1 | 1 | 98.3% |
| Phone number | 200 | 186 | 6 | 8 | 93.0% |
| Person name | 450 | 378 | 27 | 45 | 84.0% |
| Internal customer number | 90 | 41 | 3 | 46 | 45.6% |
| All types | 860 | 723 | 37 | 100 | 84.1% |
An overall 84% sounds workable. The breakdown shows that more than half of the internal customer numbers stay exposed, because the detector has never seen their format. The fix is a custom rule, not a better general model, and only a per-type report reveals it.
Run the plan in this order:
- Measure each identifier type separately for every document type and language.
- Run the look-alike set and count false detections per type.
- Test context: the same number with and without a label such as "TCKN" or "Müşteri No" next to it.
- Test boundaries: identifiers split across lines, written with spaces, or damaged by OCR (the letter O instead of zero).
- Check where the masked output goes: search indexes, exports, caches and model prompts must receive only the masked version.
- Record each result with the detector version, configuration and date, so later runs can be compared.
What should happen when a detection is uncertain?
Set a policy per identifier type: mask, block or send for review. Detection services return a confidence score per entity; Microsoft's PII detection overview describes structured output with entity categories, confidence scores and redacted results. Lowering the threshold raises recall and also raises over-masking.
Over-masking has a cost too. Masking every date breaks a timeline that downstream analysis or a retrieval system needs; masking every number makes an invoice useless. So the policy differs by type: for national ID numbers, mask when in doubt; for dates, mask birth dates but keep transaction dates; for names in a document that will be exported outside the organisation, stop the export and ask a reviewer. Write down who approved each trade-off.
Is masking the same as anonymisation?
No, and PII detection quality only measures the first. Türkiye's Personal Data Protection Authority (KVKK) guide on deleting, destroying or anonymising personal data defines masking as deleting, striking through, painting over or starring certain fields of personal data so that they cannot be associated with an identified or identifiable person. Anonymisation is a stronger condition: the data must not be associable with an identified or identifiable person even when it is matched with other data.
The same guide works through an example in which names and postal codes are masked, yet a record whose remaining values are unique can still point to the right person. A detector can cover every direct identifier perfectly and still leave a dataset that is not anonymous, because birth year, gender and district together single someone out. Treat whether the output is anonymous as a separate analysis, not as a by-product of good detection scores.
Which product limits should be checked first?
Check language and feature support for the exact feature you plan to use, and check it again at each version change. At the time of writing, Microsoft's PII language support page lists Turkish for text and document PII, while conversation PII, designed for transcripts and chat, lists only English, French, German and Spanish. A contact-centre project with Turkish call transcripts therefore cannot assume the conversation feature will work. The same overview notes that analysis is performed as-is, with no customisation to the model on your data, which is another reason internal identifier formats need your own rules.
When should detection quality be re-tested?
Re-run the full reference set whenever anything upstream or inside the detector changes: a new OCR engine, a new detector or model version, a new document template, a new source system or a new language. Alert on any new full-span miss of a critical type, even if the overall score improves. Sample production output under controlled access as well, because the reference set ages as documents change.
Name an owner for reported leaks. When an identifier escapes, the response includes finding every downstream copy, including search indexes, caches, exports and logs, and removing or re-masking them, then adding the case to the reference set so it is tested from then on.
Common mistakes
- Reporting one overall score instead of recall per identifier type, document type and language.
- Counting a partly masked identifier as detected.
- Relying on a generic entity list and never adding internal ID formats.
- Testing only on synthetic or clean digital text when production is scanned.
- Treating masked output as anonymous without checking combinations of remaining fields.
- Leaving the reference set in shared folders, notebooks or logs.
The engineering consequences of KVKK's generative AI guidance are covered in our article on KVKK's generative AI guide. How the need to mask sensitive fields before data reaches its target system shapes a pipeline is covered on our big data and data engineering service page.