# Brazil DataGuard (`laev/brazil-dataguard`) Actor

Validate and normalize Brazilian CNPJ identifiers, including alphanumeric CNPJs, with data quality reports.

- **URL**: https://apify.com/laev/brazil-dataguard.md
- **Developed by:** [Evandro Cavalcanti](https://apify.com/laev) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $50.00 / 1,000 cnpj batch processeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Brazil DataGuard — Brazilian CNPJ Validator & Data Quality Analyzer

**Validate, normalize, and analyze Brazilian CNPJ identifiers with a single API-ready workflow.**

Brazil DataGuard helps developers, data engineers, and automation builders improve the quality of Brazilian business identifiers before importing them into databases, CRM systems, ETL pipelines, and AI workflows.

### Key Features

- **CNPJ Validation:** Validate numeric and alphanumeric Brazilian CNPJ identifiers using check-digit rules.
- **Data Normalization:** Remove formatting characters and standardize identifiers.
- **Duplicate Detection:** Detect repeated CNPJ values, including differently formatted versions of the same identifier.
- **Data Quality Metrics:** Calculate total records, valid records, invalid records, duplicates, and validation success rates.
- **Error Analysis:** Count invalid records by validation error reason.
- **Flexible Reports:** Choose between summary reports and detailed record-level results.
- **Batch Processing:** Process up to 1,000 CNPJ identifiers per run.
- **Automation Ready:** Use structured JSON input and output within Apify workflows and API integrations.

### Example Input

```json
{
  "cnpjs": [
    "11.222.333/0001-81",
    "11222333000181",
    "11.222.333/0001-82",
    ""
  ],
  "modo_relatorio": "resumido"
}
```

### Example Output

```json
{
  "produto": "Brazil DataGuard",
  "sucesso": true,
  "erro": null,
  "modo_relatorio": "resumido",
  "total_registros": 4,
  "total_validos": 2,
  "total_invalidos": 2,
  "total_duplicados": 1,
  "motivos_invalidacao": {
    "Digitos verificadores invalidos": 1,
    "CNPJ nao informado": 1
  },
  "taxa_qualidade": 50.0
}
```

### Ideal Use Cases

- Validate Brazilian company identifiers during data imports.
- Check and normalize business data before ETL transformations.
- Identify duplicates and invalid records in CRM databases.
- Add Brazilian identifier validation to automated workflows.
- Prepare structured validation results for AI agents.

### Important Limitations

Brazil DataGuard performs structural and check-digit validation. It does not query Receita Federal or confirm whether a company exists, is active, or has a particular registration status.

Validation results are not official company registration certificates.

### Output Modes

**Summary (`resumido`):** Returns aggregate quality metrics and error counts without individual records.

**Detailed (`detalhado`):** Returns aggregate metrics and individual valid and invalid records, including normalized identifiers and validation reasons.

# Actor input Schema

## `modo_relatorio` (type: `string`):

Escolha entre relatório resumido ou detalhado.

## `cnpjs` (type: `array`):

List of CNPJ identifiers to validate.

## Actor input object example

```json
{
  "modo_relatorio": "detalhado",
  "cnpjs": [
    "11.222.333/0001-81",
    "11.222.333/0001-82",
    "12.ABC.345/01DE-35"
  ]
}
```

# Actor output Schema

## `results` (type: `string`):

Structured CNPJ validation report stored in the default dataset.

## `report` (type: `string`):

Complete JSON report stored under the OUTPUT key.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "cnpjs": [
        "11.222.333/0001-81",
        "11.222.333/0001-82",
        "12.ABC.345/01DE-35"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("laev/brazil-dataguard").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "cnpjs": [
        "11.222.333/0001-81",
        "11.222.333/0001-82",
        "12.ABC.345/01DE-35",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("laev/brazil-dataguard").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "cnpjs": [
    "11.222.333/0001-81",
    "11.222.333/0001-82",
    "12.ABC.345/01DE-35"
  ]
}' |
apify call laev/brazil-dataguard --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,laev/brazil-dataguard"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/v2SYFpLT4I1kRxl8k/builds/oNHPLnjL29wa1CEB2/openapi.json
