Inspiration

Invoice automation often looks complete before the work is actually complete.

While reviewing real invoice extraction results, I found a radio station and an advertising agency assigned to the wrong buyer and seller roles. In another document, a taxpayer ID appeared twice on the page and was extracted as an invoice number. The citations were real and the values looked plausible, but the business meaning was wrong.

That experience made the next problem clear: reviewers need more than a confident answer. They need the page evidence, the surrounding context, and a clear way to take responsibility for the final decision.

I built InvoiceLoop to create that handoff.

What InvoiceLoop does

InvoiceLoop turns AI-extracted invoice data into a review queue that people can understand and act on.

For each important field, it brings together:

  • the extracted value;
  • the original PDF and relevant page crop;
  • citation geometry and independent OCR;
  • arithmetic and consistency checks;
  • additional readings from vision models;
  • the complete history of human decisions.

Fields with conflicting or incomplete support rise to the top of the queue. A reviewer can inspect the evidence, correct the value, record a reason, and sign the export decision.

Approvals are tied to a specific snapshot of the document. When an approved value changes, InvoiceLoop marks the earlier approval as stale and returns the document to review. The previous decision remains in the ledger, so the history stays understandable.

How I built it

The agent workflow has three roles: a clerk assembles the evidence, a critic examines the support, and an approver agent prepares a recommendation for the human reviewer.

These roles run on Gemini 3.7 Flash through Vertex AI and are orchestrated with Google ADK. A Python control plane assigns stable IDs, runs six evidence checks, builds the review queue, records decisions, and produces the final audit bundle.

The six checks cover extraction presence, arithmetic consistency, citation binding, agreement between extraction modes, support on the page, and field-shape validation. Their results are shown directly in the workbench alongside the source material.

The unattended workflow runs as a Cloud Run Job. Each run archives its source PDFs, OCR records, model calls, raw responses, support matrix, review snapshot, and exported bundle in Cloud Storage. A separate Cloud Run service hosts the public, read-only workbench.

Human review also feeds the improvement loop. Repeated corrections become improvement candidates for prompts, field descriptions, and routing policies. Those candidates are evaluated in a new run, while the evidence and decisions from earlier runs remain unchanged.

What I learned

The biggest lesson was that evidence can agree on a value while still misunderstanding its role. A taxpayer ID can be clearly printed, correctly cited, and consistently extracted while remaining the wrong answer for the invoice_number field.

I also learned that confidence alone is a poor way to organize review work. Combining page evidence, citation geometry, arithmetic, model disagreement, and prior corrections produced a much more useful queue.

The human step became more valuable once it was treated as part of the product rather than a button at the end. A named decision, its reason, and the exact snapshot being approved give the rest of the workflow a stable reference point.

Challenges

One of the hardest engineering problems was aligning several coordinate systems: PDF pages, DWS output, independent OCR, rendered images, and browser crops. A citation is only useful when the reviewer can see the correct region of the correct page.

Another challenge was keeping the agent workflow and the approval workflow connected without blurring their roles. Agent suggestions, evidence checks, human corrections, and export decisions each needed a clear place in the system.

Deployment introduced a different set of problems. I had to make unattended Cloud Run executions reproducible, preserve every model response needed for later inspection, and carry useful failure information back to the run archive.

The result is a workflow where agents can move quickly, reviewers can see what matters, and every exported invoice has a decision trail that a person can stand behind.

Built With

Share this project:

Updates