Skip to content
CodelessOps

Projects · Case study

Grounded, a finance document analyst I built.

It answers a question from the documents you give it, cites the file and the place in it, and has code check the figure before you see it. It is not for sale, and not a licence. This page is the account of the build.

The problem

Finance cannot trust an answer it cannot check.

The tools finance teams were being handed would always answer. The answer sounded sure. Sometimes it was last quarter's figure, restated and now wrong, with the same confidence as the right one. Finding the document is the easy half. Trusting the number, once you have found it, is the hard half. A wrong figure is the one that goes into the board pack.

They would guess. They would blend two versions of the same report. They would not show the work. A chat upload of one spreadsheet is fine for one question, once. It flattens the grid into text, forgets the session, and cannot say which version a number came from. A number's identity is its position: the column, the period, the scenario. The label is not enough.

What it does

An answer, the source, and a check.

Grounded reads the finance documents you give it: board packs, budgets, forecasts, management accounts, contracts, invoices, bank statements, general-ledger extracts, policies, the delegation of authority, the close calendar, and notes. A workbook stays a grid. A PDF keeps its page. A deck keeps its slide.

You ask in plain English. The answer cites the file and the place in it: the cell range in a workbook, the page in a PDF, the slide in a deck. Open the citation and the document opens there, with the cell highlighted. When the documents cannot support an answer, it says it cannot confirm that, instead of guessing. Arithmetic runs in a calculator, not in the model. Under the answer, a trust chain shows the inputs, the computation and the result. Every figure is checked by code after the answer is written. A figure that cannot be traced is held back, and the answer says so.

The same answer is there in the browser, in Slack, and for an agent over MCP. The agent receives the citations and the checks with the text. It does not receive a bare number.

An answer citing May 2026 revenue to a workbook, with the consolidated profit and loss open on the cited cells.
Real app, fictional company, captured 12 October 2026. The company is Caldergate, which I invented for the test below. It is not a client.
A trust chain on a journal total: each input figure marked verified, and the sum shown as a calculation.
The same capture set. The sum is a calculation over cited inputs, each one marked verified.

How it is built

A scaffold, then the part a controller would ask about.

I did not start from an empty repository. Grounded began as a fork of a retrieval application from a paid course. That scaffold already had a chat loop, search, document ingestion and a front end, and it was a serious piece of software. The course licence forbids me publishing the application code. What I built on it is verification, cell-level spreadsheets, evals, tenancy, audit, and the running of it. The decisions, the measurements and the incidents are in the field notes.

Files stay files

The decision everything else follows is that the files are the source of truth. Nothing is extracted into a table of figures that then has to be trusted on its own. Every answer reads the file. When a document is deleted, its chunks, citations and retrieval rows go with it. An audit package can still record that an answer was given, and which source it named, without keeping the document's content.

Ingestion keeps the structure. A workbook stays a grid, with an A1 reference on every cell. Each chunk is stored twice: an enriched text to embed, and a verbatim text to cite. Unchanged files are skipped on a re-upload, because every ingest costs embeddings and a model pass. The parser is fenced: size and pixel limits, process isolation, and OCR only when a page needs it. Charts and images are not read. That was a choice.

Retrieval

Search is hybrid: vector and keyword, fused by rank, then a reranker. The organisation is applied inside the search, not filtered on afterwards. Drafts, legacy copies and superseded versions are ranked down, never hidden, and the answer names the version it used.

A retrieval-only test, which took an afternoon, found that the reranker had never been running. Turning it on moved the rate at which the right document ranked first from 0.42 to 0.75 on one corpus, and from 0.44 to 0.72 on another.

Verification and citations

A citation shows where a number claims to come from. A verification checks the claim. The model can only cite a passage retrieval actually returned. A citation resolves to a cell, or to a page with a bounding box, not merely to a file. Refusal is enforced after the model, in code, not requested in the prompt. The numeral guard reads every figure in the finished answer. The citation check is a separate pass, and it runs on demand on the thread. Evals grade the answer a person sees, after the guard, not the raw model output. Beside the model judge, the citation assertions are deterministic.

Personal data is replaced before the model sees the text. Names, emails and the like become consistent stand-ins for the thread, and the answer is restored before you read it. Card numbers, national identifiers and the like become type markers and are not restored. Figures are never touched. A date stand-in once turned "December FY26" into a random date and broke every date-bearing question on the estate I was testing, so a test now pins every numeral through that round trip. A salary is a number, and a number is evidence. Who may see it is access control.

The shape of the system

The browser is a client of one API. There is no second, smaller API for scripts. Uploading a document, reading a thread, re-checking citations, downloading an audit package and running golden questions are all on it. Posting a message returns a server-sent event stream: the text as it is written, then the citations once the answer is grounded. The MCP tool that asks a question is that same client, forty lines. It returns the answer, the citations, each citation's check, and a link to the thread, which stays in the app so a person can look at what the agent did. Slack is the same server with a Slack front. Three tools are exposed: ask a question, search the corpus, and list the documents. It is not a connector into a ledger. Live figures from Xero, NetSuite or Anaplan were still on the backlog.

Each organisation is a tenant. Content tables carry an organisation id, and the retrieval functions apply that organisation inside the database. A citation can only point at a chunk the search was allowed to return, so an answer cannot leak a document through a footnote. Row-level security mirrors the scope rules, and a drift test fails the build if the two diverge. Public sign-up is off. An administrator creates the users. The default is one shared database for small tenants. A dedicated database, with that customer's own model keys, is the other tier. The shared pool is cheaper by a factor of four. I started from one instance per customer, because that felt like the honest security answer, and reversed it eleven days later.

Model keys are held per organisation and envelope-encrypted. A model is chosen from an allow-list, and the instance calls whichever provider it is configured with, through that provider's API. I do not repeat a provider's promise about training. Chat uses the strongest model. Judging, extraction and the citation checks use a smaller class of model. Web results, when an administrator allows them, are labelled external and are never blended with the company's own figures. A documents-only setting declines a question the corpus cannot answer, rather than answering from the model's general knowledge.

An agent connected over MCP runs as one user and sees what that person would see. Instructions planted inside a document do not become tool calls. Eight tests pin that. Where the sandbox is on, code the model wrote can call back through a bridge of seventeen read-only tools, and it fails closed on anything else.

How it is tested

Four tiers. The fast tier is 925 unit tests, about 20 seconds, and it runs on a pre-commit hook for backend changes. Then an API tier, a smoke tier of six stable golden questions that all have to pass, and a gate: the full golden suites, three runs each. The golden questions do not run automatically in continuous integration. If a release drops the score, a person running the gate catches it. I set it up that way on purpose. Every run is traced. There is a daily cost budget, and an alert when the hallucination judge drifts.

Cost per answered question$0.18 median, $0.31 at the 90th percentile
Input tokens served from cacheAbout 77%
Time to answer a lookup12 to 20 seconds
Security and isolation tests95

The 95 cover a user not being able to read or cite another user's private content, cross-organisation access as a wall, row-level security being on, injection through names and query strings, and errors that do not leak another tenant's identifiers. Writing them found two gaps, which were then closed. One retrieval function was executable by the anonymous role, and the notes table had no pin. I have not commissioned a penetration test. Those tests are mine.

The Board Pack Test

81 of 81 on Claude. On GPT, 81, 79 and 81.

On 7 August 2026 I built a company that does not exist, so I would have something to grade. Caldergate Distribution Group: a £260m UK distributor with three segments, a term loan with covenants, and eighteen months of finance reporting. Thirty-four files, kept the way a real team keeps them. Thirteen Excel workbooks, seventeen PDFs, two board decks, two CSV extracts. I buried three problems on purpose. An April report was reissued four days later with £620k of spot revenue restated. A legacy tracker carried a stale plan-basis footnote. A department export disagreed with the issued pack by £285k, and only one file explained the gap.

I wrote 25 questions, each worth four points, 100 in total. Eighty-one of those points can be checked by a script, with no human judgement: the right figure, a citation down to the sheet and cell, and a refusal of the five questions whose answers are not in the pack, with no numbers smuggled into the refusal. The other 19 need a person, because they are about reasoning: shown working, why the reissued report supersedes the original, the reason for a refusal. The 81 is what you can trust with no one in the loop. The 19 is what you would have to check anyway.

I ran the raw models first, through their own APIs, with their own file tools. Claude Opus 5 and GPT-5.5, the same 25 questions, three independent runs each, the same prompt and the same citation format. Claude cost about $22.50 for its three passes. GPT cost $6.50. The answers were mostly right. All three traps were caught on every run. The machine-checkable score was the gap. Raw Claude banked 66 of the 81. Raw GPT banked 71. The missing points were not wrong answers. They were right answers a script could not prove: a refusal that mentioned a figure from a neighbouring period, a citation that named a whole sheet or a range, and in one case the correct number on the wrong sheet.

My own first pass banked 66 on Claude and 68 on GPT. About the same territory. Over one day I made three changes. Refusals carry no figures at all. When two files carry the same figure, the authoritative one wins: the reissued final over the superseded original, the current pack over the legacy tracker. Citations name the exact cell, not a range that happens to contain it.

Machine-checkable points, out of 81ClaudeGPT
Raw model, median of three runs6671
My first pass, median of three runs6668
After the changes, the three runs81, 81, 8181, 79, 81

Of 60 cited answers, Claude confirmed 60 of 60 after the changes, and GPT 59 of 60. The first pass had been 60 of 60 on Claude and 57 of 60 on GPT. The raw models, counted with a prose rescue a person had to interpret, were 59 of 60 and 53 of 60.

If a person grades everything and reads every refusal charitably, raw Claude scores 100 and my own setup scores 99. With a marker, every frontier tool I ran lands between 95 and 100, and the questions stop separating them. That is the finding. The models are equally capable. What separates a setup is whether the correctness survives with no marker, because at a desk there is no marker.

The raw models sat this with the whole corpus attached to every question. At 34 files that was already creaking. One vendor's code sandbox caps at 16 file uploads, so the harness pasted a headcount CSV into the prompt as text, for every vendor, to keep the comparison fair. A real finance drive is hundreds of files and grows every month-end. Attaching everything stops at the lab. The moment you add retrieval so a raw model can cope, you have started building the thing this test is about. The write-up of the test is the essay.

What was hard

The feature that was off, the version, and the refusal.

The reranker was the first one. The feature was in the build. A retrieval test said it had never run.

Then version. Two files can carry the same label and different numbers. The system has to prefer the reissued final, say which one it used, and still not hide the old file.

Then the refusal. A helpful refusal that quotes a neighbouring figure looks honest to a person and looks like a smuggled answer to a script. Teaching it to say the number is not in the documents, and to stop there, took the day that moved the first pass to the ceiling.

The guard has a run I keep. It drafted an answer, found three figures it could not trace to a document or to a calculation it could show, and held the whole answer back. That cost points. I would rather have that than a higher score built on figures nobody can check.

Tenancy took a wrong turn, the one I reversed after eleven days. A blank setting once reported success for 26 days of deployments that had not done what I thought. That is one of eight incidents in the record. Each one left a rule. And redaction nearly ate the evidence, when a stand-in for a date changed a period label and every question that depended on a date failed.

What I learned

The check is the product. The model was already good.

Provenance and an honest refusal have to be the constraint you start from. Added at the end, they are a footnote on something a controller cannot defend. A citation is not a verification. The check has to run after the model has finished writing, in code, on the answer a person will actually read.

The models were already good at the finance. The gap was proof. Eighty-one points measure what you can trust with nobody checking. Nineteen measure what you would check anyway. Quality moved once a test was cheap enough to run all the time. A score you can re-run is a different object from a feeling about a demo.

What I would do differently

The test first, and cheap enough to run.

More about me is on the about page. You can reach me at codelessops.com/karim.