Field note / 01
Plain-code reconciliation before the LLM
If a deterministic join can close 96% of a settlement batch in ten milliseconds, sending the whole ledger through an LLM is neither faster nor safer.
Nov 2026 · 3 min read · from Keel
Keep inference proportional to ambiguity #
In payment operations, almost every row in a settlement export is boring: exact order reference, expected net amount, matching currency. Only a narrow edge produces headaches—fee deductions applied without notice, duplicate rows across cutoffs, partial refunds, or two orders with the same amount on the same afternoon.
Putting a model in front of every row couples latency, token spend, and failure surface to total store volume. Running plain code first turns the problem inside out: deterministic matchers close clear pairs immediately and emit typed exceptions for everything left behind.
settlement batch (N rows)
└─ deterministic pass ──▶ clean matches closed in SQL
└─ leftovers (K ≪ N) ──▶ agent loop + policy citations
The model proposes; keys decide #
Once an exception reaches the agent, the temptation is to let tool calls mutate balances directly. That breaks under retries, prompt variance, and flaky upstream payment providers.
- Deterministic idempotency keys: keys derive from
refund:<exception_id>plus a canonical payload hash in code—never generated by the model. Retrying an identical intent replays safely; altering the amount fails loudly. - Database caps inside the write: daily spend ceilings sit in an atomic
UPDATE ... WHERE total + amount <= capinside the same transaction as the approval state change, not inside a system prompt instruction. - Unknown beats failed: if the PSP times out after dispatch, the intent settles in
unknownuntil an executor queries the provider using its own idempotency key.
Letting plain code draw the boundary leaves the LLM with what it is actually good at: reading messy policy text and explaining why an exception matches.