Skip to content
← All workProof of concept

Invoice and Expense Audit Assistant

Engineered a hybrid LLM and deterministic-rules audit pipeline that reconciles ERP records against OCR'd invoices and requisition forms, streaming field-level pass/fail verdicts to the browser over Server-Sent Events.

Role
Lead backend engineer · validation pipeline & streaming
Year
2025
Type
RAG & search
Stack
Azure OpenAI (GPT-4.1, GPT-4o) · Document Intelligence · Node.js · Express · Server-Sent Events · React · TypeScript · Azure Blob Storage · Cosmos DB · Entra ID · MSAL
field-level audit checkpoints
17

The problem

A law firm's accounts-payable team checked invoices by hand before payment, comparing amounts, suppliers, bank details, VAT and cost coding across ERP data, supplier PDFs and internal forms. The goal was full audit coverage and better overcharge detection without adding manual review.

Architecture

  1. 01

    Intake

    Express route parses an uploaded ERP workbook and pre-screens rows, skipping excluded ledgers, missing attachments and duplicates before any model call.

  2. 02

    OCR

    Invoices reach Document Intelligence through short-lived read-only SAS URLs; layout output is cached per voucher in Blob Storage.

  3. 03

    Validate

    GPT-4.1 in JSON mode compares OCR pages with ERP values, returning invalid fields with reasons under explicit tolerance rules.

  4. 04

    Extract

    A second pass pulls requisition-form fields, then deterministic rules check GL segments, matter and ICC codes, payment terms and thresholds.

  5. 05

    Stream

    Start, result, progress and complete events flow over SSE into a live React data grid, exportable to Excel.

Engineering highlights

  • 01

    Model plus deterministic rules

    Split responsibility deliberately: fuzzy comparisons (supplier names, bank details, currency-country, VAT evidence) go to the model with tolerance guidance; exact ledger, coding and payment-term rules run deterministically in code.

  • 02

    Two-pass extraction pipeline

    Pass one validates OCR against ERP values in low-temperature JSON mode; credit notes stop there. Pass two extracts requisition fields with mutually exclusive matter and GL coding, feeding 17 field-level checkpoints.

  • 03

    Live streaming over SSE

    Moved the audit to Server-Sent Events: typed lifecycle events read by a fetch stream reader append verdicts row by row, so long audits show progress instead of blocking on one response.

  • 04

    Cost-aware OCR caching

    Per-voucher OCR output is cached as JSON in Blob Storage, so re-runs skip Document Intelligence entirely; pre-screening rules avoid spending OCR and model calls on rows that should never be audited.

  • 05

    Fault-isolated expense checks

    Expense receipts are validated concurrently with category-specific prompts per GL type, and each line's failure is captured independently so one unreadable receipt never fails the whole report.

Next projectSmart Facility IoT Monitoring Platform