Identifier detector
Brazilian CPF: format, validation and detection
Short answer
A Brazilian CPF has 11 digits: nine base digits and two check digits, each a weighted sum multiplied by 10 and reduced modulo 11 and modulo 10. Numbers made of one repeated digit are rejected.
What it is
The CPF is the individual taxpayer registry number in Brazil. Maskflare's Brazil pack covers it as a national ID.
In Maskflare this is the detector br_cpf, labelled "Brazil - Individual taxpayer number (CPF)", category national id number, in the Brazil pack.
Format and layout
- 11 digits printed 529.982.247-25.
- Dots and the hyphen are optional.
How the check works
For the first check digit, multiply the nine base digits by 10, 9, 8, 7, 6, 5, 4, 3, 2, add them, multiply by 10 and take the remainder modulo 11, then modulo 10. For the second, add the first check digit to the base and multiply by 11 down to 2, and repeat the same reduction.
Worked example
- Base 529982247 with weights 10 to 2 sums to 295. 295 times 10 is 2950, which leaves 2 modulo 11 and then 2 modulo 10: the first check digit is 2.
- Adding that digit gives 5299822472 with weights 11 to 2, which sums to 347. 3470 leaves 5, so the second check digit is 5.
- Together: 25, the last two digits of the example.
Valid and invalid examples
| Example | Result | Why |
|---|---|---|
529.982.247-25 | Valid | Matches the layout and passes the validator. |
529.982.247-20 | Invalid | The invalid example changes one character, the last character: 5 becomes 0. |
In running text the valid example reads, for instance, CPF 529.982.247-25. The invalid one is left alone: a value that fails the validator is treated as an ordinary string.
Regex and validation caveats
- Dots and the hyphen are optional, so an unseparated 11-digit run is masked unless a word like order or invoice sits closer to it than one of the detector's keywords (cpf, id no, id number).
- Two check digits mean about one random number in 100 passes before the context rule.
Words that confirm it
The formatted shape is masked without a keyword. For a run with no separators, these words count as the detector's own keywords when a word like order, invoice or phone is also close: cpf, id no, id number, identity number, national id, personal id, personal number. The nearer word wins.
How to detect it in LLM traffic
Brazilian CPF values reach an LLM inside ordinary work rather than as standalone data: a pasted block of HR or payroll rows, a customer-support thread, an onboarding or identity-check form, a spreadsheet someone wants summarised, or an email they want rewritten. The model needs none of the digits for any of those jobs, so the safest place to remove them is before the request leaves the company.
Maskflare reads the whole request body, including the system prompt, earlier messages and tool arguments, so a number buried in the fourth message of a long chat is found as readily as one in the latest message. Each match is replaced with a token such as mf_mask_d7e0 before the request goes out, and with response restoration turned on the real value is put back into the answer for the person who is allowed to see it.
If you build the detection yourself
- Strip spaces, dots and hyphens before running any arithmetic, but remember where they were so the original text can be replaced exactly.
- Match the shape with a pattern anchored on word boundaries, so that a long digit string is not read as several shorter Brazilian CPF candidates.
- Run the check from the section above. A failing check is almost always a typo or a made-up value; a passing one removes most look-alikes.
- Treat a run with no separators more carefully than a formatted one: reject it when a word such as order, invoice, phone or reference is nearer to it than one of the identifier's own keywords.
- Replace the value before the text is sent anywhere, and keep a mapping if the answer has to be restored afterwards.
How Maskflare handles it
- Protect now, Finance - Protect now, Healthcare and Developer: mask (a reversible token) when Brazil is a primary country.
- Monitor first: alert (counted, forwarded unchanged) when Brazil is a primary country.
The available actions are mask (reversible token), redact, partial, hash, format-preserving encryption, generalize, alert and block. Masked values are kept encrypted for 30 days so that answers can be restored, then they expire; prompts and responses are not logged. The full list of detectors is in the detector reference.
Compliance profiles that include it
None of the 6 compliance profiles (HIPAA Safe Harbor, GDPR (EU/EEA), UK GDPR, PCI DSS v4.0, US PII (CCPA/CPRA) and Swiss nDSG health data) includes the Brazil pack, so no profile turns this detector on. It runs when the pack is enabled directly, or when Brazil is chosen as a primary country.
Frequently asked questions
Why are repeated digits like 111.111.111-11 rejected?
They satisfy the arithmetic but are not issued, so the validator excludes any number made of one digit.
Is a CNPJ a CPF?
No. The CNPJ is the 14-character company number and has its own detector.
Is the Brazilian CPF detector on by default?
It depends on the organisation's primary countries. It is part of the Brazil pack, which the default Protect now template turns on with the action mask when Brazil is a primary country.
Does a valid Brazilian CPF prove the person exists?
No. A check digit shows the value is well formed. Many valid-looking numbers have never been issued, and Maskflare masks them all the same.
Rules on this page describe what Maskflare's detectors and validators check. They are read from the detection catalogue and are not the specification of the body that issues the identifier. Examples are synthetic.