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:
| Field | Type | Description |
|---|---|---|
text | str | Original input text |
findings | list[Finding] | All detected PII matches |
detector_names | list[str] | Detector types that produced surviving findings |
processing_time_ms | int | Total 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ákemail: jan.novak@email.czrodne_cislo: 8001011238ico: 25596641
Notes
detect()returns only deduplicated findings that survive overlap resolution.detector_namesin the result reflects the surviving finding types, not just the detectors requested.- Unknown detector names passed to
detector_namesraiseKeyError.