---
title: "Spanish Identifiers (DNI, NIE, CIF)"
description: "Stop sending sensitive data to third-party APIs. Philterd ships open source PII and PHI redaction that runs inside your cloud. For HIPAA, GDPR, and CCPA work."
url: "https://philterd.ai/policies/general/spanish-identifiers/"
---

[← All policies](https://philterd.ai/policies/)

General · Philterd

# Spanish Identifiers (DNI, NIE, CIF)

Redact Spanish personal and organization identifiers (DNI, NIE, CIF), validated by their control letter or character.

[View policy →](https://philterd.ai/policies/general/spanish-identifiers/#policy-json) [Download JSON →](https://raw.githubusercontent.com/philterd/pii-redaction-policies/main/policies/philterd/general/spanish-identifiers.json) [View source on GitHub](https://github.com/philterd/pii-redaction-policies/blob/main/policies/philterd/general/spanish-identifiers.md)

**v1.0.0** Updated 2026-06-15 Philter `Requires Phileas 4.1.0+ (redaction policy schema 1.1.0 with the mod23-letter and es-cif validators)` By Philterd

Spain DNI NIE CIF national ID tax ID

## The policy

The full `spanish-identifiers.json` file. The same content you’d get by downloading. Copy any part of it, or use the buttons in the hero to grab the whole file.

```
{
  "config": {
    "splitting": {
      "enabled": false,
      "threshold": 4000
    }
  },
  "ignored": [],
  "identifiers": {
    "identifiers": [
      {
        "classification": "spanish-dni",
        "pattern": "\\b\\d{8}[A-Za-z]\\b",
        "caseSensitive": false,
        "validator": "mod23-letter",
        "identifierFilterStrategies": [
          {
            "strategy": "REDACT",
            "redactionFormat": "[REDACTED-SPANISH-DNI]"
          }
        ]
      },
      {
        "classification": "spanish-nie",
        "pattern": "\\b[XYZxyz]\\d{7}[A-Za-z]\\b",
        "caseSensitive": false,
        "validator": "mod23-letter",
        "identifierFilterStrategies": [
          {
            "strategy": "REDACT",
            "redactionFormat": "[REDACTED-SPANISH-NIE]"
          }
        ]
      },
      {
        "classification": "spanish-cif",
        "pattern": "\\b[A-HJ-NP-SUVWa-hj-np-suvw]\\d{7}[0-9A-Ja-j]\\b",
        "caseSensitive": false,
        "validator": "es-cif",
        "identifierFilterStrategies": [
          {
            "strategy": "REDACT",
            "redactionFormat": "[REDACTED-SPANISH-CIF]"
          }
        ]
      }
    ]
  }
}
```

## Example

Input

```
DNI 12345678Z, NIE X1234567L, CIF A58818501.
```

Output

```
DNI [REDACTED-SPANISH-DNI], NIE [REDACTED-SPANISH-NIE], CIF [REDACTED-SPANISH-CIF].
```

## Entities this policy acts on

SPANISH\_DNI SPANISH\_NIE SPANISH\_CIF

## What this policy does

Detects and redacts three Spanish identifiers using Phileas’s generic `identifier` filter with a control-character validator, so each match is kept only if its control is correct:

- **DNI** (Documento Nacional de Identidad): 8 digits and a control letter, validated by the `mod23-letter` validator.
- **NIE** (Numero de Identidad de Extranjero): a leading X, Y, or Z (mapped to 0, 1, 2), 7 digits, and a control letter, validated by the `mod23-letter` validator.
- **CIF** (the organization tax identifier): a leading organization-type letter, 7 digits, and a control digit or letter, validated by the `es-cif` validator.

Each is replaced with a distinct token.

## Why the validators matter

The shapes alone (eight digits plus a letter, and so on) would over-match. The validator keeps a match only if the control character is correct, so `12345678A` (a DNI shape with the wrong control letter) is left in place while `12345678Z` is redacted. Detection remains probabilistic; validate against your own documents.

## Test vectors

- DNI, valid: `12345678Z`. Invalid (wrong control letter): `12345678A`.
- NIE, valid: `X1234567L`. Invalid (wrong control letter): `X1234567A`.
- CIF, valid: `A58818501`. Invalid (wrong control character): `A58818502`.

## Contextual cues

In free text, anchor on a nearby cue (“DNI”, “NIE”, “CIF”) and capture only the identifier with `groupNumber`:

```json
{
  "classification": "spanish-dni",
  "pattern": "DNI[\\s:#-]*(\\d{8}[A-Za-z])",
  "caseSensitive": false,
  "groupNumber": 1,
  "validator": "mod23-letter",
  "identifierFilterStrategies": [
    { "strategy": "REDACT", "redactionFormat": "[REDACTED-SPANISH-DNI]" }
  ]
}
```

This trades recall for precision.

## Prerequisites

Use Phileas 4.1.0 or later, which provides redaction policy schema 1.1.0 and the `mod23-letter` and `es-cif` validators. The example input and output were verified against Phileas 4.1.0.

## References

- [Spanish DNI / NIE (Wikipedia)](https://en.wikipedia.org/wiki/Documento_Nacional_de_Identidad_%28Spain%29)

## Use this policy

Download and load into your running Philter instance:

```
# Download the policy
curl -O https://raw.githubusercontent.com/philterd/pii-redaction-policies/main/policies/philterd/general/spanish-identifiers.json

# Upload it to Philter as spanish-identifiers
curl -sk -X POST "https://localhost:8080/api/policies?name=spanish-identifiers" \
     -H "Authorization: Bearer $PHILTER_API_KEY" \
     -H "Content-Type: application/json" \
     --data @spanish-identifiers.json

# Redact text with it
curl -sk "https://localhost:8080/api/filter?p=spanish-identifiers" \
     -H "Authorization: Bearer $PHILTER_API_KEY" \
     -H "Content-Type: text/plain" \
     --data-binary "your text here"
```

For Philter 4.0. No Philter instance yet? The [quick start](https://philterd.ai/dev/start/) runs one and shows where `PHILTER_API_KEY` comes from · Want to tune this policy against your data? [Talk to the team](https://philterd.ai/policies/general/spanish-identifiers/#).

[← All policies](https://philterd.ai/policies/)
