AI Accountant
The review layer for Xero books that AI has already categorised. Every transaction gets a proposed category with written reasoning, a confidence tier and a risk flag. A person decides, and every decision is recorded. Deployed, open source, with a demo that runs in your browser.
Launch the demo → (runs in your browser, no account) · Watch the 2-minute video →
https://github.com/user-attachments/assets/431b5bd4-40b8-466a-8d86-a41dfa1e11d9
The launch video (2:14; 1080p with chapters on YouTube), rendered from a Remotion composition in video/.
At a glance
| Built for | UK sole traders, small businesses and the bookkeepers who sign off their books on Xero, now quarterly under Making Tax Digital. |
| What it does | proposes and explains a category for every transaction, matches bank transactions to invoices and payments, drafts the quarter's management letter, and keeps an audit trail of every AI proposal and every human decision. |
| AI | Claude Haiku 5.5, escalating to Sonnet 5.5 when unsure · structured output validated by Pydantic, through one gateway on the Anthropic SDK · LangGraph workflows · pgvector retrieval of the firm's own past decisions · risk flags from eight readable fuzzy-logic rules. |
| Stack | Python 3.12, FastAPI, SQLAlchemy 2.0 async, PostgreSQL 16 with pgvector, Redis, Alembic · Next.js 14, TypeScript, Tailwind · Docker, GitHub Actions, Vercel, Railway. |
| Size | 34 API routes, 8 tables, 6 migrations, 244 backend tests run in CI. |
| Status | deployed and open source (MIT); designed and built by Rajarshi Nandi, March to October 2026. |
Who it is for and why it exists
Quarter-end review now falls on people who never wanted it. The person I had in mind is a self-employed electrician at the kitchen table on a Sunday evening, two days before a quarterly update is due, scrolling through three months of bank lines that Xero's AI has already categorised and trying to work out which of the hundred green ticks not to trust. And the accountant with forty of those clients, who signs each quarter knowing that whatever the software got wrong is now their professional problem.
Since 6 April 2026, sole traders and landlords with qualifying income of £50,000 or more report to HMRC every quarter under Making Tax Digital for Income Tax; the threshold falls to £30,000 in April 2027 and £20,000 in April 2028. VAT-registered businesses have reported quarterly for years.
Xero's own AI, JAX, now categorises and reconciles bank transactions automatically; Xero says it reconciles with 97% accuracy. That changes the job: the books are written by a model, and what is left for the human is finding the three lines in a hundred that are wrong, and being able to show later who decided what. A green tick with no reasoning is not evidence.
AI Accountant sits after Xero's AI and before the sign-off, and makes the review short, evidenced and recorded:
- Confidence tiers say where to look, so attention goes to the uncertain cases.
- Every proposal arrives with its reasoning, and the reviewer's question becomes "do I agree?".
- A correction is stored as a precedent: each new transaction retrieves the five most similar decided transactions from the same firm as examples, and no model is trained on them. On bookbench's held-out test, taking the precedents away cut agreement on transactions only history can settle from 98.9% to 50.2% (report).
- Before anyone asks for it, the audit row (model, confidence, reasoning, human decision) already exists.
What it does
A quarter's review, start to finish. Everything here runs against a connected Xero organisation; nothing is a mock-up.
-
Sync. Connects to Xero with OAuth2 and pulls the chart of accounts, bank transactions, invoices and payments, incrementally after the first pull.
-
Categorise. Proposes a category for every uncategorised transaction, using the firm's own previously categorised transactions as precedents, with a confidence score, written reasoning and a tier: auto-accept, suggested or needs review.
-
Review. Each proposal shows its reasoning, which model made the call, and a risk flag from eight plain-language rules such as unusual amount, unseen vendor and odd timing. Approve, correct or reject; a correction becomes a precedent that later similar transactions can retrieve.

-
Reconcile. Matches unreconciled bank transactions to invoice and payment records on amount, date and description, with scored candidates; ambiguous matches go to review.

-
Report. Drafts a management letter from the actual figures, plus a profit and loss and a VAT summary, rendered as PDFs. The figures are computed in code; the model writes only the narrative.
-
Sign off. The audit trail answers "who decided what, and why", for every AI proposal and every human approval, correction and rejection.
Also: a small team per practice with owner and member roles, and GDPR export and erasure of everything held about an organisation.
Try it

The demo at agentic-ai-accounting.vercel.app/demo opens the console on "Harlow & Finch Ltd", with fifty transactions and a quarter's statement lines. It runs entirely in your browser: match scores are computed by a browser port of the reconciler, the PDFs come from the real templates, and nothing reaches the API or Xero. Add ?skip_onboarding=1 to start with the quarter already imported.
The video is a two-minute product and engineering walkthrough, playable at the top of this page or on YouTube with chapters; video/README.md says how it was made.
The live app at agentic-ai-accounting.vercel.app is the deployed build behind the demo: the same console, talking to the FastAPI service and to Xero through OAuth2 instead of to an in-browser fake. To connect your own books, run it locally with your own Xero app and Anthropic key. The consent screen asks for read-only access to bank transactions, invoices, contacts, payments and settings; transaction details, which can include payee names, are sent to Anthropic for categorisation; tokens are stored encrypted; and an organisation's data can be exported or erased. The privacy policy lists every processor.
Architecture
A Next.js console talks to a FastAPI service; a LangGraph categoriser and the document service call Claude through one structured-output path, and a second LangGraph workflow reconciles without a model; Postgres holds the books, the vector precedents and the audit log; Xero sits behind a single adapter that only reads.
| Layer | What runs there |
|---|---|
| Frontend | Next.js 14 (App Router), TypeScript, Tailwind, Base UI primitives, on Vercel. Landing page, review console and the browser-only demo, all calling the API through one apiFetch function (plus one direct call that downloads generated PDFs) |
| API | FastAPI, Pydantic v2, SQLAlchemy 2.0 async, Alembic, on Railway (Docker). 34 routes: 31 under /api/v1, two OAuth, one health |
| Workflows | Two LangGraph state machines in backend/app/agents/: the categoriser and the reconciler |
| Models | Claude Haiku 5.5 first, Claude Sonnet 5.5 on low confidence and for document narratives, all through one gateway (llm_client.py) on the Anthropic SDK; one setting (LLM_PROFILE=claude-4) rolls back to Haiku 4.5 and Sonnet 4.6 |
| Retrieval | pgvector in the same Postgres; all-MiniLM-L6-v2 embeddings (384 dimensions) computed in-process |
| Data | PostgreSQL 16, eight tables, six migrations, NUMERIC(12,2) and Decimal for money; Redis for cache and webhook debounce, optional |
| Documents | Figures in Python, narrative from Claude as structured output, Jinja2 templates rendered to PDF by WeasyPrint |
| Operations | GitHub Actions (pgvector service container, migrations, 244 tests, type check, lint), per-organisation rate limits, background jobs tracked in Postgres, optional Sentry |
Boundaries the code keeps. Model calls live in services/ and agents/; no route makes one. The single path to Xero is integrations/xero_adapter.py, and it only reads. Every AI decision and every human review decision (approve, correct, reject, confirm, match, unmatch) writes an audit row. Model output arrives as a schema, so nothing is parsed from free text, and the organisation comes from the session rather than from anything the model returns.
docs/ARCHITECTURE.md holds the current design and the reconciliation path on live Xero data.
How the AI works
The model proposes, code validates and a person decides. One fixed workflow calls Claude at defined points, and no model answer is accepted without passing a schema, a chart-of-accounts check and a confidence tier; an answer that fails goes to a person.
One categorisation run (POST /api/v1/categorise/async):
- Context. Load the chart of accounts and the five nearest previously categorised transactions of the same organisation (cosine distance on pgvector).
- Classify. Send the transaction, chart and precedents to Haiku with a JSON schema as the required output format (structured outputs, effort low); receive a
CategoryPrediction(code, name, confidence, reasoning) validated by Pydantic. Invalid or cut-off output raises, and the transaction stays uncategorised for the next run. - Escalate. Below 0.85 confidence, or if Haiku declines, the same prompt goes to Sonnet. If Sonnet fails after Haiku answered, Haiku's answer stands and the error is recorded; if both decline, the row goes to review. The audit row records both models, the model that actually served the answer, and both confidences.
- Validate. The proposed category must exist in the chart and the confidence must be in range; a failure zeroes the confidence so the row goes to a person.
- Decide. Auto-accept above 0.85, suggested from 0.5, needs review below.
- Explain and record. The fuzzy risk rules run, and the payload is attached to the audit row.
A batch runs as a background job under asyncio.Semaphore(5). Reconciliation uses no model: candidates are scored on amount (0.5), date (0.2) and description similarity (0.3), with near-ties sent to review. Document narratives are the only other model call, and they never compute a figure.
Design decisions and trade-offs
Each row is a choice, the alternative it was chosen over, and the trade-off accepted.
| Decision | Instead of | Why | Trade-off accepted |
|---|---|---|---|
| Fixed LangGraph workflows | An autonomous agent with tools | Known task shape; each node is a typed async function, testable alone, and a run ends in one audit row | Less flexible on odd cases; agentic review is a later roadmap phase with its own evals |
| Structured output validated by Pydantic, through one gateway | Parsing model text | A rule in the first commit, before any model call existed: parsed text can yield a wrong category without an error, while a schema makes invalid output fail | The gateway is code to keep current as the API changes per model |
| Haiku first, Sonnet below 0.85 confidence | Haiku only, or Sonnet only | The stronger model runs only where a person would otherwise look, at 20× Haiku's list price per token (Sonnet 5.5 $2 / $10 against Haiku 5.5 $0.10 / $0.50 per million input / output tokens, checked 2026-10-28). On bookbench's held-out test split, tiered agreed with its draft labels on 93.7% at $4.00 per 1,000 transactions. As an exploratory comparison (reported beside the pre-registered result, with no decision attached and no interval on the differences): 86.1% ($0.39) for Haiku only and 94.3% ($7.59) for Sonnet only (report) | Within a point of Sonnet only at about half its cost, but 46% of transactions escalate, so they make two model calls |
| A pre-registered A/B before changing models, with a one-setting rollback | Upgrading on the release notes | Read against the code, the migration guide showed Sonnet 5.5 rejects the forced tool call the app sent, which would have quietly turned escalation off; the gate was committed before any result existed | $6.86 of API calls, and a verdict that holds only on a draft benchmark |
| The firm's own past decisions as few-shot precedents | Fine-tuning, or a global classifier | A correction is re-embedded and joins the precedents that later similar transactions retrieve (the five nearest by embedding); categorisation trains no model on client data. Measured: +48.7 points of agreement on history-dependent items, and fewer Sonnet escalations (report) | Precedents come only from the same organisation, so a new firm starts with none: without them, 9% of history-dependent rows were auto-posted to a category the label disagrees with |
| Local MiniLM embeddings in the same Postgres | An embeddings API and a vector database | Anthropic has no embeddings endpoint; no extra vendor or database | PyTorch makes the backend image large |
| Risk flags from eight readable fuzzy rules | Learned per-feature contributions | An accountant can read and challenge "amount deviation is high AND vendor is rare" | Coarser than a learned model |
Decimal money, figures computed in code |
Floats; model-written figures | Penny errors are trust failures; the model never touches a number | The model writes only the narrative around the figures |
| An audit table row per AI and per human decision | Log lines | "Who decided what, and why" has to be queryable | A database write on every decision |
Raw httpx Xero adapter behind one interface |
The Xero SDK | Control over token refresh, 429 backoff and If-Modified-Since sync, in one file |
More code to own |
Browser-only demo behind apiFetch |
A hosted demo backend | No running cost, no data risk; every endpoint the console calls is simulated, and reconciler scoring is ported and checked against RapidFuzz to four decimal places | Demo reasoning is replayed from the seed, not generated live |
Behind these choices are specific problems, with commits, in the engineering record.
Evaluation
The categoriser the app runs today, Haiku 5.5 escalating to Sonnet 5.5 below 0.85, agrees with bookbench's draft labels on 93.7% of 285 held-out UK test transactions (95% bootstrap interval 90.9% to 96.3%; three repetitions; labels at commit f57f0d4). It auto-accepts 45.3% of them, and 98.4% of those agree with the label (Wilson 95% lower bound 96.7%); 45.7% escalate to Sonnet; cost is $4.00 per 1,000 transactions at standard prices. The data, scoring rule, headline and threshold test were committed before the first call, and the report keeps them above the results, with per-stratum and threshold-sweep tables and the AUROC and calibration error of the confidence score. Every published number sits next to a provenance file (app commit, dataset commit and checksums, prompt hash, model ids, request parameters, date), and the raw responses and exact request bodies of every run are public as bookbench-runs, so each figure can be re-scored offline without calling a model.
Precedents were measured the same way. The same requests (300 test transactions, three repetitions) were sent again with the precedent block empty ("(none yet)", what a firm with no categorised history gets), with the rules committed before the first call. On the 93 transactions that only history can settle, agreement with the draft labels fell from 98.9% to 50.2% (+48.7 points, 95% interval +38.4 to +58.8); on the 160 the bank line settles there was no measurable change (+1.9, interval -1.5 to +5.4). Without history, 9% of the history-dependent rows were auto-posted to a category the label disagrees with, against none with precedents, so a new firm's first categorisations are where the app most often auto-posts a wrong answer on this data. Precedents also cut escalation to Sonnet from 64.4% to 45.7% of transactions, so they lower cost too. The precedents in this run are the dataset's simulated retrieval (the same MiniLM model, top 5), not the app's pgvector query, and the run measures what precedents in the prompt do, not the correction loop that creates them (report).
A lower threshold was tested and not adopted. At 0.80 the app would auto-accept 57.5% at 94.7% precision for $2.43 per 1,000, and the pre-registered condition for the change was met; it stays at 0.85, because in a review layer a row sent to a person is the cheaper error.
What the figure does not show. bookbench's labels are generated by rules and not yet reviewed by a person, the transactions are synthetic, precedents are simulated rather than retrieved by pgvector, and n is 285; a figure on reviewed labels waits for bookbench to be frozen. Fifteen instruction-like attack items are scored apart: 9% of those answers were auto-posted and 38% took the injected label, which is the input handling planned in phase 6 of the roadmap.
bookbench is built to this categoriser's input contract (the Xero record fields it reads, the firm's chart and the top 5 retrieved precedents): 1,000 UK and US small-business transactions with precedent history, NEEDS_REVIEW as a gold answer and a separately scored stratum of instruction-like text, public as a draft (data on Hugging Face). The move from Claude 4.x to 5.5 was gated on its dev split: a [pre-registered A/B](https://github.com/rajo69/agentic-ai-acco

