Keptcash
An AI collections agent that works out why an invoice is unpaid
Hover to spread the screens, click one to look closer, orSwipe through the screens, tap one to look closer, or flip through all 6.
Keptcash watches QuickBooks for overdue invoices, diagnoses why each one is stuck, drafts a follow-up aimed at that reason, and tracks replies, promises and disputes until the cash lands. The AI drafts; a person sends.
- RoleCo-lead and top committer on the build
- Contribution103 of 185 commits
- Statusv1 delivered
- WhenSep – Oct 2026 · Ledgercross
In numbers
- diagnosis eval cases passed in the CI gate
- 42 / 42
- prompt-injection cases produced a forbidden output
- 0 / 30
- Playwright specs against the real UI, API, database and worker
- 28
- case states, guarded by a database trigger
- 9
The problem
Accounts-receivable teams chase overdue invoices with the same reminder every time, but invoices go unpaid for different reasons: a missing PO number, an email to someone who left, a disputed line, or plain forgetfulness. A generic nudge fixes only the last one.
Keptcash diagnoses the blocker first and writes to that. Because a wrong amount in a collections email destroys trust, the model is never allowed to put a number in a draft that isn't in the case facts.
How it works
step through it · each step is a noteThe recovery loop
- 01QuickBooks syncs every 5 minutes, re-reading a lookback window because QBO is eventually consistent. Invoices 3+ days overdue open a case.
- 02Diagnosis asks why it's unpaid. Rules go first; Gemini picks from a fixed list only when no rule fires.
- 03Gemini drafts a follow-up aimed at that specific blocker.
- 04The fact guard pulls every amount, date, invoice ref and percentage out of the draft and checks each against the case facts.
- 05One unknown number fails it: regenerate once, then hand the case to a person.
- 06A person reviews, edits if needed, and sends from the team's own mailbox.
- 07Replies are polled every 2 minutes and classified, with customer text treated as untrusted data.
- 08Promises are recorded and watched daily; disputes go to a manager's queue.
My part
Built with a second lead engineer at Ledgercross.
- Built the QuickBooks sync, re-reading a lookback window because QBO is eventually consistent, and fixed PO references being read from a field that doesn't exist.
- Built the Gmail integration end to end: OAuth connect, a send handler with per-domain throttling, reply ingestion threaded onto cases, and bounce detection that flags dead contacts.
- Wrote reply classification and routing, the promise-to-pay recorder with a daily watcher and break-count ladder, the dispute flow, and the collection cadence scheduler.
- Stored inbound email bodies as documents so diagnosis and retrieval can read them.
- Enforced MFA through Clerk, carrying deep links through sign-in, and built the dashboard API (totals, aging buckets, DSO) and its screens.
- Built the invoices, customer, communications, disputes and integrations screens, plus in-app notifications.
Decisions
A fact guard on every draft
Every amount, date, invoice reference and percentage in a draft is extracted and checked against the case facts. One unknown value fails it: regenerate once, then escalate. The same check runs live in the browser while a person edits.
Rules first, the model second
Diagnosis runs cheap deterministic rules first: missing PO, bounced billing contact, a prior dispute, a customer's usual delay. Gemini only chooses from a fixed six-value list when no rule fires, and below a confidence floor the case goes to a person.
Human-send by design
The original spec allowed autonomous low-risk sends. v1 narrowed that to See and Draft: the AI diagnoses and writes, a person sends, and the edit rate between draft and sent text is the metric that has to earn autonomy.
Invariants the database enforces
Money is integer cents. State changes only through transition(), and a trigger rejects any other write. The audit log is append-only at the role level. Row-level security means a missing WHERE clause still can't leak another tenant's rows.
Nine case states, one way to change them
- 01Every overdue invoice becomes a case. transition() is the only way to change state; a database trigger rejects any other write.
- 02A grounded draft waits for a person. Rejecting it with a reason sends it back for another attempt.
- 03A person sends it and the case moves to CONTACTED.
- 04The customer promises a date. Kept, the case closes and the recovery is attributed when the payment matches.
- 05A broken promise goes back for a firmer follow-up, until the break count says otherwise.
- 06A dispute pauses collection until a manager resolves it.
- 07Low confidence, repeated breaks or unresolved disputes escalate to a person. Nothing is auto-closed by the model.
Stack
- BackendPython 3.12, FastAPI, psycopg 3 (plain SQL), Postgres job queue
- Data & AIPostgreSQL 16, pgvector, pgai vectorizer, Gemini, Hybrid retrieval
- IntegrationsQuickBooks Online, Gmail API, Nylas, Clerk (MFA, orgs)
- Web & qualityNext.js 15, React 19, TypeScript, Playwright, Eval gate in CI






