Detectors
Postal Code
Detect and validate Czech PSČ values with context checks and region mapping.
Purpose
Use the postal_code detector for Czech postal codes (PSČ).
This detector reports accuracy above 99% and combines format validation with contextual checks to avoid random 5-digit false positives.
It also maps codes to a Czech region label, including Prague-specific district handling.
Detector Name
postal_codeSupported Formats
XXX XXXXXXX
Examples:
110 0011000
Validation Logic
The detector validates both structure and context.
Format Rules
- Remove spaces.
- Require exactly 5 digits.
- Reject values that start with
0.
Context Rules
At least one of these must be true during detection:
- A postal label such as
PSČappears within 30 characters before the code. - A known Czech city appears within 30 characters after the code.
- The code appears after a comma in an address-like pattern.
- The code uses the spaced
XXX XXform.
There is no checksum algorithm for this detector.
Python Examples
Validate a postal code
from fastpii import PrivacyGuard
guard = PrivacyGuard(regions=["cz"])
result = guard.validate("110 00", "postal_code")
print(result.is_valid)
print(result.metadata)Detect in text
from fastpii import PrivacyGuard
guard = PrivacyGuard(regions=["cz"])
result = guard.detect("PSČ: 110 00", detector_names=["postal_code"])
for finding in result.findings:
print(finding.value, finding.metadata)Expected Metadata
This detector returns:
region
Prague prefixes are mapped explicitly, and other prefixes are grouped into broader Czech regions such as Středočeský, Jihočeský, or Moravskoslezský.
Example Output
{
"region": "Praha",
}Limitations
- Region mapping is prefix-based, not exact municipality validation.
- Detection is stricter than raw validation because it requires context.
- Codes that begin with
0are always rejected.
Notes
Verified validation example from the codebase:
guard.validate("110 00", "postal_code")