FastPII Docs
Guides

Detection

Detect PII in text with PrivacyGuard.detect and work with DetectionResult objects.

PrivacyGuard.detect() is the main entry point for finding PII in text.

Basic detection

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])

text = "Jan Novák, email: jan.novak@email.cz, RČ: 8001011238, IČO: 25596641"
result = guard.detect(text)

print(result.text)
print(result.detector_names)
print(result.processing_time_ms)

DetectionResult fields

detect() returns a DetectionResult with these fields:

FieldTypeDescription
textstrOriginal input text
findingslist[Finding]All detected PII matches
detector_nameslist[str]Detector types that produced surviving findings
processing_time_msintTotal processing time in milliseconds

Iterate over findings

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
result = guard.detect("Jan Novák, email: jan.novak@email.cz, RČ: 8001011238")

for finding in result.findings:
    print(f"type={finding.type}")
    print(f"value={finding.value}")
    print(f"span={finding.start}:{finding.end}")
    print(f"confidence={finding.confidence}")
    print(f"region={finding.region}")
    print(f"metadata={finding.metadata}")

Example output:

type=name
value=Jan Novák
span=0:9
confidence=0.95
region=cz
metadata={'firstname': 'Jan', 'surname': 'Novák', 'gender': 'm', 'full_name': 'Jan Novák'}

Select specific detectors

Use detector_names when you only want certain detector types.

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
text = "IČO: 25596641, RČ: 8001011238, email: jan.novak@email.cz"

result = guard.detect(text, detector_names=["ico", "email"])

for finding in result.findings:
    print(finding.type, finding.value)

This only runs the ico and email detectors.

Filter by confidence

The library returns confidence scores on every Finding, so you can apply your own threshold.

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
result = guard.detect("Jan Novák, email: jan.novak@email.cz, RČ: 8001011238")

high_confidence = [finding for finding in result.findings if finding.confidence >= 0.95]

for finding in high_confidence:
    print(f"{finding.type}: {finding.value}")

Measure processing time

processing_time_ms is included directly on the result.

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
result = guard.detect("Contact jan.novak@email.cz or use IČO 25596641")

print(f"Found {len(result.findings)} items in {result.processing_time_ms}ms")

Realistic result example

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
result = guard.detect("Jan Novák, email: jan.novak@email.cz, RČ: 8001011238, IČO: 25596641")

for finding in result.findings:
    print(finding)

Typical findings include values such as:

  • name: Jan Novák
  • email: jan.novak@email.cz
  • rodne_cislo: 8001011238
  • ico: 25596641

Notes

  • detect() returns only deduplicated findings that survive overlap resolution.
  • detector_names in the result reflects the surviving finding types, not just the detectors requested.
  • Unknown detector names passed to detector_names raise KeyError.

On this page