All work
Revenue leak auditWorking demo · sample data

Clause

Finds billing an agency’s own contracts call for, with the clause to prove it.

Nov 2026 · Solo: spec, architecture, build

TL;DR

Clause compares a retainer agency’s signed Statements of Work with its invoice export and lists billing the contracts call for but the invoices miss. An LLM reads the contracts and must quote the exact wording and page for every term. Plain code re-checks each quote and decides every dollar, and a person approves each finding.

leak checks
6
planted leaks and decoys in the eval set
6 + 5
contract quotes verified in the sample
40/40
test functions written
1,435
Clause overview of the public sample run: missed billing in the audit window, a 12-month estimate, and leaks sorted by impact
The public sample run. The agency, clients and dollar figures are synthetic leaks I planted to test the tool.

The problem

Retainer agencies under-bill against their own contracts without noticing. A month goes uninvoiced. A fee increase written into the contract is never applied. An intro discount keeps running after it expired. An approved change order or a supplier cost never makes it onto an invoice.

The terms live in PDFs. The billing lives in QuickBooks. Nobody cross-checks the two month by month, so small gaps add up quietly.

This is a place where an AI tool can do real harm if it guesses. A wrong dollar figure in front of a client is worse than no figure at all. So the question was not just "can a model read a contract" but "how do I make sure nothing it says reaches a number unchecked".

Who it's for

Owners, finance leads and bookkeepers at small retainer agencies (marketing, creative, web) that bill monthly and invoice from QuickBooks Online. The person using it is the reviewer who approves or dismisses each finding.

What it does

  • Takes signed SOW PDFs and a QuickBooks Online "Sales by Customer Detail" CSV. Exports only, no logins to accounting tools.
  • Runs six checks: missed invoice, wrong retainer amount, unapplied annual uplift, unbilled change order, expired discount still applied, and unrebilled pass-through cost. Recurring add-on fees are checked the same way.
  • Backs every finding with the verbatim contract quote, its page number and the exact invoice rows it compared.
  • Turns anything doubtful into a "Needs review" note instead of a finding, so uncertain cases never inflate the totals.
  • Gives a review screen to approve or dismiss findings, add notes and confirm quotes the checker could not parse.
  • Produces a four-sheet XLSX leak register, a CSV copy, a one-page executive summary PDF and a zip of all of it.

How it works

  1. Upload

    Contract PDFs plus one invoice CSV, run locally on 127.0.0.1.

  2. Read invoices

    Plain Python parses rows with Decimal money and refuses ambiguous dates.

  3. Extract terms

    The LLM proposes fees, dates and clauses, each with a verbatim quote and page.

  4. Verify quotes

    Code re-checks every quote against the PDF text. Unverified terms become notes.

  5. Run rules

    Deterministic Decimal rules compare contract and invoices month by month.

  6. Human review

    A person approves or dismisses each finding before anything is exported.

  7. Export

    Leak register XLSX, CSV and a one-page summary PDF reflecting those decisions.

Key engineering decisions

The model reads. Code decides every dollar.

The LLM has one job: extract structured contract terms. The leak rules contain no model calls. Every expected, invoiced and missing amount comes from Decimal arithmetic in plain Python, so the same inputs always give the same numbers.

No quote, no finding

Each extracted term must carry a verbatim quote and page number. Code re-checks the quote character for character against the page text, requires it to be a single sentence, a short run of lines or one table row, and requires it to state the value itself. Whatever the model claims about verification is ignored. Hidden text or instruction-like wording in a PDF flags the contract for a human check, a basic guard against prompt injection.

An answer key, not a vibe check

I built a reproducible synthetic agency with 8 contracts, 6 planted leaks (one per check) and 5 decoys that look like leaks but are not. The one-command demo audits it and fails on any miss or false positive. Recorded model outputs are cached by prompt version and PDF hash, so the eval replays without calling a model.

Real client data only goes to one provider

Three contract readers exist: the paid Anthropic API, a Claude CLI subscription reader and Gemini. The last two are refused unless the folder carries the synthetic sample marker, so real contracts can only go to the paid API. Keys are read from the environment by name, and provider settings in .env files are refused.

Conservative on purpose

Part months, credit notes, export-window edges and lines that might be the missing amount under another label all become review notes. I chose to under-report rather than show an agency a gap that is not real.

Screens

Clause findings page with quotes checked against the PDF text and finding cards showing expected, invoiced and missed amounts
Each finding shows the expected amount, the invoiced amount and the contract wording behind it.
One expanded Clause finding: the quoted contract clause next to the invoice row it disagrees with, with Approve and Dismiss buttons
The evidence for one leak. Approving or dismissing it is a person's call.

Honest limits & what's next

Limits today

  • Only tested on synthetic data so far. The eval shows it finds what I planted, not how it does on real, messy contracts.
  • One invoice format out of the box: QuickBooks Online Sales by Customer Detail. PDFs need selectable text; scanned contracts are not supported.
  • Handles monthly-in-advance retainers only. No proration of part months, no CPI-linked uplifts, and credit-note months are not judged.
  • Real audits run locally for a single user. It is not a hosted multi-user product.
  • Findings are leads for a person to confirm, not legal or accounting conclusions.

Next

  • Run it on a real agency’s contracts and invoices, with their permission, and grade the results by hand.
  • Add invoice exports from Xero, FreshBooks and Harvest.
  • Rename the live sample and app from the working name "Agency Leak Audit" to Clause.

Built with

  • Python 3.13
  • FastAPI
  • Jinja2
  • Pydantic v2
  • pydantic-ai
  • Anthropic API
  • pypdf
  • openpyxl
  • reportlab
  • pytest + Playwright
  • mypy --strict
  • Vercel

Everything shown publicly is synthetic: an invented agency with 8 invented clients. The $11,670 shown in the live sample comes from leaks I planted to test the tool, not revenue anyone recovered. The live sample replays recorded model outputs, so no model runs and there is no upload. The code is private. A code walkthrough is available on request: get in touch.