Technical Deep-Dive

Brazil LGPD: detecting CPF and other identifiers before they reach AI

LGPD, the ANPD, PL 2338/2023 and Brazilian identifiers: how to detect and anonymise CPF, CNPJ or CNS numbers before they reach generative AI tools.

·5 min
Software engineers working together in an office on Avenida Paulista in Sao Paulo

In Brazil, the CPF number is everywhere: on invoices, contracts, customer records and support tickets. It is also one of the data points that most often ends up in prompts sent to ChatGPT, Gemini or Copilot, pasted along with the rest of a spreadsheet or an email. For a company subject to the LGPD, that simple copy and paste is processing of personal data.

This article first sums up the Brazilian legal framework, then gets technical: which identifiers to look for, how to recognise them reliably and how to anonymise them without making AI useless.

The framework: LGPD, ANPD and the sanctions regulation

The Lei Geral de Proteção de Dados Pessoais (Law No. 13,709/2018) applies to any processing of data about people in Brazil. It distinguishes personal data, sensitive data (health, racial or ethnic origin, religious beliefs, political opinions, union membership, genetic or biometric data, sex life) and anonymised data. Its Article 46 requires appropriate technical and administrative security measures.

The ANPD, Brazil's national data protection authority, enforces it. Its regulation on the calculation and application of sanctions (Resolução CD/ANPD No. 4 of 24 February 2023) explains how fines are set. The LGPD provides for warnings, publication of the infringement, blocking or deletion of data, and a simple fine of up to 2% of revenue in Brazil, capped at 50 million reais per infringement.

The ANPD is already looking at AI

The authority did not wait for a dedicated law to take an interest in AI. On 2 July 2024, it imposed a preventive measure on Meta, suspending the use of its Brazilian users' personal data to train its AI systems, with a daily fine of 50,000 reais for non-compliance.

On the legislative side, bill PL 2338/2023, which would create a risk-based framework for AI, was passed by the Federal Senate on 10 December 2024. It has since been under review by a special committee of the Chamber of Deputies, with no final vote so far. Until then, the LGPD is enough to govern prompts.

Brazilian identifiers to detect

In Brazil, an effective detection engine has to cover far more than names and email addresses. Here are the main formats:

  • CPF: 11 digits, often written 000.000.000-00, including two check digits computed with modulo 11.

  • CNPJ: 14 positions, formatted 00.000.000/0000-00. Since 1 July 2026, new CNPJs may contain letters in the first 12 positions, while the last two remain numeric check digits.

  • Cartão Nacional de Saúde (CNS): 15 digits, linked to health data and therefore sensitive.

  • PIS/PASEP/NIT: 11 digits, found in HR and payroll documents.

  • Voter ID, CNH and RG, bearing in mind that the RG format varies from state to state.

  • Pix keys: a CPF, an email, a phone number or a random key, to be handled as financial data.

Detecting without drowning teams in false positives

A simple regular expression looking for 11 digits fires on order numbers, phone numbers and internal references. A reliable method combines several signals:

  1. Recognise the format, with or without punctuation (000.000.000-00 or 00000000000).

  2. Validate the check digits of the CPF, CNPJ or CNS. A random 11-digit number has only about a one in a hundred chance of passing CPF validation.

  3. Exclude invalid sequences such as 111.111.111-11, which pass the calculation but are never issued.

  4. Analyse the context: words such as "CPF", "inscrição" or "titular" nearby increase confidence.

The alphanumeric CNPJ means rules must be updated: a detector that accepts only digits will miss companies registered since July 2026.

Customer service agents with headsets working in a call center in Rio de Janeiro

Anonymising without breaking AI use

Under Article 12 of the LGPD, anonymised data is no longer personal data, provided the process cannot be reversed by reasonable means. Replacing a CPF with asterisks protects it, but often makes the AI's answer useless: the model no longer knows it is an identifier, or which one belongs to which row of a table.

Format preserving anonymization replaces each CPF with a fictitious but valid CPF, consistent across the whole document. The model keeps the structure and the user gets a usable answer. If the mapping is kept locally to restore the real values, the LGPD would rather call it pseudonymisation, which is still a strong security measure under Article 46.

Putting the control in the right place

Traditional network DLP tools struggle to see what happens inside an encrypted ChatGPT session, as we explain in why email and network DLP fails on ChatGPT. The control has to sit as close to the user as possible, in the browser and on the device, before encryption. The same goes for developers using command line AI agents, which can send configuration files or database extracts full of CPFs.

That is the ZeusLock approach. It spots sensitive data in prompts and files, including national identifiers such as the CPF or CNPJ, then, according to your rules, anonymises it while keeping its format, warns the user or blocks the upload. Every incident is logged, which documents the security measures the LGPD expects.

Key takeaways

  • The LGPD (Law 13,709/2018) applies to every prompt containing personal data.

  • The ANPD has had a sanctions regulation since 2023 and already acted on AI in 2024.

  • PL 2338/2023 was passed by the Senate and is still being debated in the Chamber of Deputies.

  • Good detection combines format, check digits and context, and must handle the alphanumeric CNPJ.

Want to test Brazilian data detection on your own use cases? Book a ZeusLock demo.

Protect your data from AI leaks

See ZeusLock stop sensitive data before it reaches ChatGPT, Claude, Gemini and more, in a 30-minute demo.

Book a demo