FastPII Docs
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_code

Supported Formats

  • XXX XX
  • XXXXX

Examples:

  • 110 00
  • 11000

Validation Logic

The detector validates both structure and context.

Format Rules

  1. Remove spaces.
  2. Require exactly 5 digits.
  3. 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 XX form.

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 0 are always rejected.

Notes

Verified validation example from the codebase:

guard.validate("110 00", "postal_code")

On this page