Skip to Content
Recodocs

A model may write the parser; only the host may trust it

A model drafts code that reads a new bank layout. The host tests it against the statement's own arithmetic, and nothing is imported until a person approves the exact bytes.

8 min read

A bank statement can be readable but still lack a compatible import format. Holding an unfamiliar statement for review protects the ledger from guessed mappings. Follow the evidence that supports the eventual decision.

An operator uploads kestrel_2026_09.pdf, a statement from a bank the system has never seen. The host extracts the text, masks long account numbers, and tries every approved parser. None fits, so the statement waits as needs_parser. The operator asks for a build. A model reads the text, writes a parser, and tests it until the host's arithmetic agrees. Then it asks to submit. Nothing is imported yet. Fourteen rows appear only after a person approves.

Upload October's statement from the same bank and the saved parser imports sixteen rows. No model connection is opened.

The claim is that letting a model write parsers for money is safe only if the host decides what counts as correct, who approves, and whether approved code is still the code that was approved. The model reads, drafts, chooses when to test again, and decides when to submit; it does not approve or import. This page argues that split against one local service. The banks, holders and transactions are invented.

The argument

  1. Later statements that a saved parser reconciles need no model. Upload tries every approved parser, newest first, and imports with the first that passes, without calling a model.
  2. Correct is a host function. The running balance must chain and every amount must be printed on the page, whoever wrote the parser.
  3. Promotion is an approval, not a tool the model can finish. The submit step parks until a reviewer confirms the exact draft and its hash.
  4. Five automated cases and two notebooks are the evidence. They show the guards work. They are not a hit rate on real statements.

Who is allowed to decide

The usual design bundles "the agent" into one component that reads the PDF, writes code, and judges whether the rows are true. That puts the judge and the defendant in the same head. This service separates them before any model exists. Upload, parser reuse, the integrity check on saved code and the correctness check are ordinary code. The only model-driven loop is the one that builds a new parser.

Upload stays deterministic; the model enters only on build-parser.
Statement upload versus parser buildA PDF upload flows through masking and saved-parser reuse without a model call. When no parser reconciles, build-parser runs the PydanticAI agent. submit_parser parks until a reviewer approves the exact draft and hash.OperatorBearer /v1PDF or UTF-8 bodyNo model on uploadimport_with_saved0 model calls reuseHost pathStatement APIPOST /statementsextract, mask, reuseimport_with_savednewest approved parserbuild-parseragent when needs_parsersubmit_parserparks until approveSQLiteStatement rowsparser_version draftsevents, importsagent.pyPydanticAI AgentHarness limits3 tools onlyCodex in productionuploadreusebuildmodel

Upload and build arrive at the Statement API from the operator, reuse goes from the API to SQLite, and the model arrow runs from the agent.py card into the Statement API at the build row. The orange card on the left names what the upload path never does: it never calls a model. A test installs a model that raises if it is ever invoked, uploads October's statement, and still gets sixteen rows, because the saved parser runs in a sandbox and the host records the import when the check passes. That is a stronger guarantee than a prompt that says "do not use the model here". The model cannot misbehave on a path where it is not called.

Inside the agent, the model has three tools, and each is limited by a stated policy.

ToolPolicyWhat it does
read_statementreadReturns numbered lines of the masked text
test_parserread, stores a draftRuns the draft in a sandbox with no network, then applies the host check
submit_parsereffect, approvalParks for a reviewer, then runs only for the exact draft and hash approved

A tool with no registered policy is invisible to the model. The run is also bounded: 24 model requests, 40 tool calls, 600 seconds, and at most eight drafts per statement. The instructions say the statement text is data, and that text asking the model to do anything but parse should be ignored. The prompt says to ignore instructions in the statement; the injected Harbor draft still passed the host check and was rejected by the reviewer.

The parser forge and the statement module are not agents. They contain no model loop. The agent decides when to read, draft, test and submit, and nothing else.

What the evidence shows

Describing a sandbox, a hash seal and a balance chain makes each sound proven. They were exercised in different ways, and the difference matters. The figure shows the check every draft passes through, whether a live model or a test fixture wrote it.

Host reconcile: printed amounts, running balance, narrations in text.
Reconciliation checks parser outputDocker runs parse(text) in a sandbox. statements.reconcile validates the JSON against masked statement text. Failure codes include running_balance and amount_not_printed.model_view textmasked idsamounts kepttest_parserDockerExecutor5 s, no networkdef parse(text)reconcilerunning_balanceamount_not_printeddescription_not_founddraft reportpassed: true/falsedraft_idsource_sha256Textwhat parsers seeSandboxkit forge test_draftHost checkstatements.pyStored draftmax 8 per statement

Read the four panels left to right. The first is the text the parser sees: account digits masked to the last four, amounts left visible. The second is the sandbox run of def parse(text), with no network and a five-second ceiling. The third is the host check, with three of its failure codes listed. The fourth is the stored draft report, holding passed, the draft id and the source hash. Failure codes are stable strings the model can read in the report and correct against.

The third panel is where trust lives. A parsed statement passes only when the balance chains, every amount is printed, every date is inside the period, and every narration is found in the text. The second rule closes a gap the first leaves open: a parser that invents numbers that happen to balance fails with amount_not_printed. A drifting row fails with running_balance. Both codes are asserted in a test of the check on its own, with no HTTP and no Docker.

The check also has a stated limit. It proves the extracted rows agree with the printed figures. It does not prove the bank's figures are right. A mis-assigned narration with a printed amount can still pass, and a person must still approve the exact draft before it is saved.

Parser code is reused only after approval and an intact SHA-256 seal.
From parked submit to sealed reusesubmit_parsereffect + approvalauthorizepassed draft + hashPOST .../approvereviewer confirmsrun_approvedseal check each runfailing draft → harness denies before approval (409)edited source → status disabled, seal_broken

The figure follows a draft after it passes. From left to right: the submit call, the authorization predicate, the reviewer's approval, and every later run. Two notes mark where it can fail. A failing draft is denied before approval with a 409, so the response is not a parked submit_parser approval. An approved parser whose source has been edited is disabled, with the reason seal_broken, and the next upload leaves the statement at needs_parser. Every run of approved code recomputes its hash first, so the seal is checked at use, not just at approval.

The evidence comes in two kinds. Five automated cases use a scripted model (or none) and, where an agent case runs a parser, a real Docker sandbox, with no credential and no live call. Two notebooks ran a live model. In the first, the importer in the sibling product rejects a Northwind statement, the agent's parser imports fifteen rows equal to the ledger after approval, a wrong-digest approval is refused, and a statement carrying an injected instruction to AI systems still parks and is rejected. In the second, October imports with zero model calls and sixteen rows, and edited approved code is disabled. An earlier acceptance run imported Harbor and Kestrel (13, 12, 14, and 16 rows) and did not compare those rows to the generator. All of this is synthetic data.

What would falsify the claim is an import route that stores rows without a passing check, or a submit that promotes code whose hash differs from the draft. Neither is what the tests assert. What would strengthen it is real bank PDFs, scanned or encrypted ones, and a reviewer who is not the operator who started the build. The demo uses one session for both, and says so.

The turn we ran

One scripted test walks the whole happy path, after upload has already failed to find a saved parser. It needs no live model.

The client posts the September Kestrel statement and gets needs_parser. The build returns awaiting_approval with a single pending tool, submit_parser. At that moment the statement shows no transactions and both drafts are still drafts, with passing flags of false then true: a broken parser first, then a working one.

The reviewer then approves. The run resumes, the statement becomes imported, and its detail shows fourteen transactions with a closing balance equal to the last row's printed balance. The parser list now holds one entry, with status approved. The first draft stayed a draft the whole time. On this path the scripted model submits only the passing draft; a separate test submits the failing draft and gets 409.

The negative path is the more useful test. When the scripted model proposes to submit its first, failing draft, the build call returns 409 with denied. The statement stays at needs_parser, both drafts remain drafts, and no parser is saved. A proposed effect that fails the host's test never becomes an approval card. If that card existed, a tired reviewer would be asked to bless code the host already knew was wrong.

The one check to copy

Copy the authorize predicate, not the bank nouns. It runs when the model proposes a submit and again when the approved call is dispatched:

return (
    scope.agent == AGENT_NAME
    and draft is not None
    and draft.status == "draft"
    and bool(draft.report.get("passed"))
    and arguments.get("source_sha256") == draft.source_sha256
)

Each line closes a different door. The agent name stops another agent reusing the tool. A draft that exists and is still a draft stops a replay. A passing report stops a failing parser. The hash comparison stops a swap between the version tested and the version approved. The test to keep beside it is the one that submits the failing draft and expects a 409.

The pattern ports to any system where a model writes code that will run in production. Store an immutable hash on each draft. Require reconciliation evidence in the report before an effect can even be proposed. Re-check both at dispatch. The field names change with the domain. The intersection of draft, hash and passed does not.

Close

Statement import invites a story about models that learn bank formats. What the evidence supports is plainer. The model writes a draft and reads the host's verdict on it. The host decides whether the draft reconciles, who may approve, and whether stored code is still what was approved. Once a layout is approved, later statements that the saved parser reconciles need no model. Add a new effect only with a new host check and a named test that proves a bad proposal is denied before anyone is asked.

How is this page?

Last updated on