Skip to main content
Back to projects

Compliance-grade tax-filing agent — Brazilian IRPF

A typed-tool LLM agent for Brazilian tax filings. One hallucinated number is a compliance failure. So: schema-validated steps, forced citation, a hard turn ceiling.

PythonTyped-tool agent loopForced citation + span validationAppend-only audit ledgerLGPD · 5-year replay
My role
extraction + validation, on a 6-engineer team
Agent ceiling
≤40 typed-tool turns / filing
Output attestation
every number re-validated against its source span
Audit
LGPD · append-only decision ledger

The problem

A regulated tax-filing agent cannot hallucinate one numerical field. Every output has to replay for a five-year audit window under LGPD, on-premise, no data egress. General-purpose RAG fails this twice: it can't prove where a number came from, and it can't bound how long the agent thinks.

The solution

The loop caps at ≤40 turns per filing. The router rejects any cross-year retrieval hit. Forced citation plus post-hoc span validation: the model's arithmetic is never trusted blind. A deterministic anomaly-rule layer catches out-of-policy values before they land, and the audit ledger is append-only, anchored to a transparency log. Per-field retry avoids re-running the whole filing. Rejected: one big-context prompt (no provenance) and an open-ended loop (no audit ceiling).

fig. 01decision record
Constraint
LGPD plus a five-year audit-replay mandate, on-premise, zero data egress. One hallucinated numerical field is a regulatory failure.
Decision
Bound the agent at ≤40 typed-tool turns per filing. Scope retrieval to the filing year, reject cross-year hits at the router. Force every number to cite, then re-validate it against its source span before it lands. Rejected: a single large-context prompt (no provenance), an unbounded loop (no audit ceiling).
Outcome
By construction the agent has no path to emit an unsourced number. Every figure re-validates against its source span; a deterministic rule layer gates out-of-policy values. This is a design property. It holds on day one and it holds the same at year five.

Overview

A Brazilian income-tax (IRPF) filing agent built by a six-engineer team. The loop is bounded at ≤40 turns per filing; each step is a schema-validated tool call; retrieval is scoped to the filing year. Every emitted number cites its source span and gets re-validated against that span before it lands in the return. My part: field extraction and structured-output validation for the individual filing sections. The decision log is append-only, so any filing can be replayed.