Measuring PII Detection Quality
Engineering

Measuring PII Detection Quality

One overall score hides the identifier type the detector has never seen, and that is usually the one that leaks. How to build a reference set and a recall-by-entity test plan.

Short answer

Measure PII detection by computing recall and precision separately for each identifier type, document type and language, at the level of exact character spans, on an access-controlled reference set built from your own documents. Count partly masked identifiers as misses, test look-alike values for over-masking, and report exposed identifiers as counts. Recall usually matters more than precision, so the F2 score is a sensible summary.

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:

IdentifierWhat makes it hardDetection approach
Turkish national ID number (T.C. kimlik no)Eleven digits that can look like any other long numberPattern plus check-digit validation plus context words
IBAN and card numbersSpaces, line breaks and OCR errors split the numberPattern plus checksum validation
Phone numbersMany formats: +90, a leading 0, spaces, bracketsPattern plus context
Person namesMany Turkish names are also ordinary words, such as Deniz, Can or GülNamed entity recognition plus context, tested heavily
AddressesFree text with no fixed formatNamed entity recognition; often the weakest type
Internal customer, policy or subscriber numbersFormats exist only in your organisationYour own rules; generic detectors do not know them
Health or other special-category details in free textExpressed in ordinary language rather than as a codeCustom 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.

TypeTrue spansFully coveredPartly coveredMissedFull-span recall
National ID number1201181198.3%
Phone number2001866893.0%
Person name450378274584.0%
Internal customer number904134645.6%
All types8607233710084.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:

  1. Measure each identifier type separately for every document type and language.
  2. Run the look-alike set and count false detections per type.
  3. Test context: the same number with and without a label such as "TCKN" or "Müşteri No" next to it.
  4. Test boundaries: identifiers split across lines, written with spaces, or damaged by OCR (the letter O instead of zero).
  5. Check where the masked output goes: search indexes, exports, caches and model prompts must receive only the masked version.
  6. 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.

Key takeaways

  • Build the identifier list from your own documents and add internal ID formats that generic detectors do not know.
  • Score at character-span level and count partly masked identifiers as misses.
  • Report recall per identifier type, document type and language; an overall figure hides the weak type.
  • Keep a look-alike set of product codes, dates and order numbers to measure over-masking.
  • Treat anonymisation as a separate analysis: masked data can still identify people through the remaining fields.

Frequently asked questions

How is PII detection accuracy measured?

With precision and recall computed for each identifier type against a labelled reference set of real documents. Recall, the share of true identifiers found, usually matters most, so many teams use the F2 score, which weights recall more heavily than precision.

Why is span-level evaluation important for PII redaction?

Because a detector can find an identifier but mask only part of it. Counting a partial mask as a success hides exposed digits or names, so score whether every identifying character is covered.

Can off-the-shelf PII detection find Turkish identifiers?

Some services include them; Azure Language, for example, lists a Türkiye national identification number type and supports Turkish for text PII. Internal formats such as customer or policy numbers still need your own rules, and support differs between features, so test on your own documents.

Is masked data anonymous under KVKK?

Not necessarily. KVKK's guide defines anonymisation as data that cannot be linked to an identified or identifiable person even when matched with other data, and shows that masked records can still identify someone when their remaining values are unique.

How often should PII detection be re-tested?

Whenever the OCR engine, detector version, document templates, source systems or languages change, and periodically on sampled production output. Alert on any new complete miss of a critical identifier type even if the overall score improves.

All articles