Skip to main content
All use cases
Fiscal complianceSaaS

Every transaction issues the right fiscal doc.

The agent watches the transaction stream and, on each settled sale, validates the buyer's tax ID, emits the correct fiscal document for the country — NF-e in Brazil, CFDI in Mexico, Factura in Argentina — and stores the PDF + XML. No end-of-month fiscal panic, no rejected invoices.

BeforeMonth-end batch → chase rejections
AfterIssued per sale → zero backlog
100%
auto-issued on transaction
Try it in the Sandbox
NF-e · CFDI · Factura
Documents
Right doc picked by destination
Per sale
Real-time
Issued the moment payment clears
Tax ID
Pre-validated
CNPJ / RFC / CUIT before emission
PDF + XML
Stored & sealed
Bound to the originating transaction
What gets issued

Every settled sale, a valid fiscal doc.

The agent validates the buyer's CNPJ before it cuts anything, then emits the NF-e through NFe.io, stores the PDF and XML, and hash-seals both to the originating transaction. A SEFAZ rejection comes back as a structured code the agent retries against — not a portal screenshot.

  • Tax ID validated up front — bad CNPJ / RFC / CUIT never reaches SEFAZ
  • Destination picks the document: NF-e in BR, CFDI in MX, Factura in AR
  • PDF + XML sealed to the transaction for a reconstructable audit trail

Issue the NF-e for sale #883 and archive the PDF + XML.

Found sale #883 — validating the buyer's CNPJ first, then emitting the NF-e and sealing the docs to the transaction.

NF-e · Nota Fiscal Eletrônica
Nº 00421 · série 1
Authorized
EmitenteLoja Aurora LTDA
DestinatárioCNPJ 12.345.678/0001-90
NaturezaVenda · CFOP 5102
Valor totalR$ 240,00
Protocolo SEFAZ135240000842193
nfe-00421.pdfnfe-00421.xml
authorized · stored · sealedrcp_nf0421
The pain

The conversation is the easy part.

Fiscal compliance is where carts die. A missed NF-e blocks a shipment; a wrong CFOP triggers a SEFAZ rejection; a bad RFC bounces a CFDI. Every country has its own document, its own validation, its own 50-odd rejection codes — and most teams discover them one failed invoice at a time.

Batch invoices at month-end and chase the rejections by hand

codespar_invoice issues on every settled transaction, in real time

Validate CNPJ / RFC / CUIT manually before each emission

codespar_kyc validates the buyer's tax ID before the doc is cut

Re-map CFOP and tax presets for every new country you enter

The right document — NF-e / CFDI / Factura — picked by destination

Store PDFs in a shared drive and hope you can find them at audit

PDF + XML stored and sealed to the transaction in the audit ledger

How the agent does it

Pan-LATAM fiscal, on autopilot.

One meta-tool covers the region. codespar_invoice resolves the destination to the correct fiscal rail — NFe.io for Brazilian NF-e, and the CFDI / Factura providers for Mexico and Argentina — validates the buyer's tax ID through codespar_kyc first, emits the document, and stores PDF + XML against the transaction. Rejections come back as structured codes the agent can retry against, not portal screenshots.

01
Settle
Stream

Transaction confirmed paid

02
Validate
codespar_kyc

CNPJ / RFC / CUIT verified

KYC rail
03
Issue
codespar_invoice

NF-e / CFDI / Factura

NFe.io
04
Store
Document store

PDF + XML archived

05
Seal
Audit ledger

Bound to transaction

Architecture

The agent subscribes to the settled-transaction stream. For each event it runs codespar_kyc to validate the counterparty's tax ID, then codespar_invoice, which the router resolves to the country's fiscal provider. The emitted PDF + XML are stored and hash-sealed against the originating transaction so the audit trail reconstructs every fiscal obligation end to end.

In code

A few lines. The whole loop.

fiscal-autopilot.ts
const session = await codespar.sessions.create();

for await (const tx of settledTransactions) {
  // validate the buyer's tax ID first — bad ID, no document
  await session.execute("codespar_kyc", { taxId: tx.buyer.taxId });

  // right document for the country, picked by destination
  const doc = await session.execute("codespar_invoice", {
    rail: tx.country === "BR" ? "nfe" : "cfdi", // NF-e · CFDI · Factura
    buyer: tx.buyer,
    items: tx.items,
    companyId: tx.companyId,
  });

  await session.verificationStatus(doc.toolCallId); // PDF + XML sealed
}
100% · sealedreceipt · rcp_fiscal
Featured tools
codespar_invoice

Emits NF-e (NFe.io), CFDI, or Factura by destination; stores PDF + XML.

codespar_kyc

Validates CNPJ / RFC / CUIT before the document is cut to avoid rejections.

Audit ledger

Hash-seals every fiscal doc to its transaction for a reconstructable trail.

See the meta-tool reference

Ship it this afternoon.

Open the sandbox, point a session at your providers, and run the whole loop against real rails in minutes — not the quarter it takes to build it by hand.

Fiscal compliance autopilot — CodeSpar | CodeSpar