FastPII Docs
Detectors

INSEE/NIR

Detect and validate French national identification numbers with Mod-97 checksum and Corsica 2A/2B handling.

Purpose

Use the insee detector for French national identification numbers (INSEE/NIR — Numéro d'Inscription au Répertoire).

Detector Name

insee

Supported Formats

  • 15 characters: S YY MM DD OOO NNN KK
  • Without spaces: 180012A00100161
  • With spaces: 1 80 01 2A 001 001 61

The INSEE/NIR structure is:

PositionMeaningValues
1Sex1 (male), 2 (female)
2-3Birth year00-99
4-5Birth month01-12, or 20-42 for Corsica
6-7Department01-95, 2A/2B for Corsica
8-10Commune001-999
11-13Order number001-999
14-15Checksum key01-97

Corsica Handling

Departments 2A (Corse-du-Sud) and 2B (Haute-Corse) replace the numeric department code. For checksum calculation, 2A becomes 19 and 2B becomes 18.

Validation Logic

  1. Normalize spaces and separators.
  2. Require 15 characters after normalization.
  3. Validate structure (sex, month, department).
  4. Handle Corsica department codes (2A/2B).
  5. Compute Mod-97 checksum.

Checksum Algorithm (Mod-97)

  1. Replace 2A with 19 and 2B with 18 in the numeric portion.
  2. Convert the 13-digit numeric prefix to an integer.
  3. Compute 97 - (prefix % 97).
  4. Compare with the 2-digit checksum key.

Python Examples

from fastpii import FastPII
from fastpii.countries.fr import FrenchPack

priority = {"insee": 100, "siren": 95, "email": 70, "name": 50}
engine = FastPII(priority=priority)
engine.register(FrenchPack())
result = engine.detect("INSEE: 180012A00100161", detector_names=["insee"])

Convenience API

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["fr"])
result = guard.validate("180012A00100161", "insee")

print(result.is_valid)
print(result.metadata)

Convenience API — Detect in free text

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["fr"])
result = guard.detect("INSEE: 180012A00100161")

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

Expected Metadata

When validation or detection succeeds, this detector can return:

  • sex: male or female
  • department: Department name or code
  • checksum_valid: True

Example Output

{
    "sex": "male",
    "department": "Corse-du-Sud",
    "checksum_valid": True,
}

Limitations

  • INSEE/NIR is specific to French national identification.
  • Corsica department codes (2A/2B) require special handling during checksum validation.
  • Context words like "INSEE", "NIR", or "sécurité sociale" improve detection accuracy.

On this page