Skip to content

Poland - Add recognizers for tax and business register numbers (PL_NIP first, then PL_REGON) #2575

Backlog

Description

@Sierakk

Is your feature request related to a problem? Please describe.
Presidio already ships PlPeselRecognizer under country_specific/poland/, but PESEL only covers natural persons. The two identifiers that appear on almost every Polish invoice, contract, company register extract and public procurement document are not detected:

  • NIP (Numer Identyfikacji Podatkowej), the 10-digit tax identification number. Sole traders use their NIP for their business, so in practice it often identifies a person.
  • REGON, the statistical business register number issued by Statistics Poland (GUS): 9 digits for an entity, 14 digits for a local unit.

Stock Presidio returns nothing for NIP: 123-456-32-18 or REGON 123456785.

Describe the solution you'd like
Two recognizers in the existing country_specific/poland/ folder, each with COUNTRY_CODE = "pl", a default_recognizers.yaml entry with country_code: pl, and enabled: false. Both are PatternRecognizer subclasses with a checksum in validate_result, like PlPeselRecognizer.

I would start with PL_NIP and open PL_REGON as a separate PR once the first one has been reviewed.

1. PlNipRecognizer → PL_NIP

  • Formats:

    • compact 1234563218
    • the two historical dashed groupings 123-456-32-18 (individuals) and 123-45-63-218 (companies)
    • EU VAT form with prefix PL1234563218. As in DeVatIdRecognizer, the prefix is part of the span.
  • Checksum: weights 6 5 7 2 3 4 5 6 7 on the first nine digits, sum mod 11, which must equal the tenth digit. A remainder of 10 is never issued, so it is rejected.
    Sources: pl.wikipedia: Numer identyfikacji podatkowej, which uses the worked example 123-456-32-18.

  • Proposed scores:

    • prefixed or dashed: 0.4
    • compact 10 digits: 0.1

    About 9% of random 10-digit strings pass the checksum, so a bare 10-digit run should depend on context.

  • Context: nip, numer identyfikacji podatkowej, vat, nip-ue, podatnik.

2. PlRegonRecognizer → PL_REGON (follow-up PR)

  • Formats: 9 digits, or 14 digits for a local unit. The first 9 digits of a 14-digit REGON are the parent entity's REGON.

  • Checksum:

    • 9 digits: weights 8 9 2 3 4 5 6 7, sum mod 11, with 10 → 0.
    • 14 digits: the first 9 digits must pass the 9-digit check, and the full number uses weights 2 4 8 5 0 9 7 3 6 1 2 4 8, mod 11, with 10 → 0.

    Source: pl.wikipedia: REGON, with the worked example 123456785.

  • The 9-digit form is the risky one. Polish phone numbers also have 9 digits, and about 10% of random 9-digit strings pass the checksum. So I would score a bare 9-digit REGON very low (≈0.05) and let the context words regon and gus carry it. The 14-digit form is safer: about 1% of random strings pass both checks, so 0.3 seems reasonable.

Tests (per CONTRIBUTING)

  • Exact entity boundaries and scores, with values embedded in Polish sentences and at the end of a sentence followed by punctuation.
  • Each accepted format, plus NIP:1234563218 with no space after the colon.
  • Negatives of the same shape:
    • 10-digit and 9-digit numbers that fail the checksum
    • 1234567890, for which no valid NIP check digit exists
    • a Polish mobile number in a sentence with no REGON context
  • Score changes when context words are present.
  • One test that enables each recognizer through RecognizerRegistryProvider, with supported_languages: [pl] set in the test YAML.
  • A row per entity in docs/supported_entities.md under "Poland".

All test values are synthetic numbers generated to pass or fail the checksum. No real company identifiers are used.

Describe alternatives you've considered

  • One PL_TAX_ID entity covering both NIP and REGON. They are different registers with different checksums, and users may want to redact one but keep the other (for example, keep REGON for company statistics but mask NIP because it can identify a sole trader). Separate entities follow how Germany is split (DE_TAX_ID, DE_VAT_ID).
  • A custom ad-hoc recognizer per project. That works, but it skips the country filter (load_predefined_recognizers(countries=["pl"])), and every Polish user has to rewrite the same checksums.

Additional context / questions for maintainers

  • PlPeselRecognizer is registered for pl only. NIP also appears on English-language invoices from Polish companies (VAT ID: PL...). Should these recognizers be registered for pl only, for consistency, or for both pl and en?
  • Is NIP first, REGON in a separate PR the split you would prefer, or would you rather review both in one PR?
  • I would like to work on this myself if the proposal looks reasonable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions