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
inseeSupported 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:
| Position | Meaning | Values |
|---|---|---|
| 1 | Sex | 1 (male), 2 (female) |
| 2-3 | Birth year | 00-99 |
| 4-5 | Birth month | 01-12, or 20-42 for Corsica |
| 6-7 | Department | 01-95, 2A/2B for Corsica |
| 8-10 | Commune | 001-999 |
| 11-13 | Order number | 001-999 |
| 14-15 | Checksum key | 01-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
- Normalize spaces and separators.
- Require 15 characters after normalization.
- Validate structure (sex, month, department).
- Handle Corsica department codes (2A/2B).
- Compute Mod-97 checksum.
Checksum Algorithm (Mod-97)
- Replace
2Awith19and2Bwith18in the numeric portion. - Convert the 13-digit numeric prefix to an integer.
- Compute
97 - (prefix % 97). - Compare with the 2-digit checksum key.
Python Examples
Explicit Engine (Recommended)
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:maleorfemaledepartment: Department name or codechecksum_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.