Put the Ledger Behind a State Machine, Not an Agent
LLMs can interpret messy requests, but financial workflows need deterministic rules for what may change, when, and with whose approval
Let the model interpret ambiguous inputs and propose actions, but let deterministic code decide whether an action is legal. Persist each approved transition and its outgoing event reliably, then require human sign-off wherever policy or uncertainty demands it.
A language model can explain a suspicious invoice with impressive confidence. It can also misread a decimal, infer a missing approval, or call the same payment tool twice. That is not a contradiction in the model’s behavior. It is a reminder that fluent interpretation and safe control are different jobs.
A financial workflow should give each job to the mechanism suited to it. Let a model interpret a request and suggest the next step. Let a deterministic state machine decide whether that step is permitted, and let durable systems record what actually happened.
Separate the guess from the transition
A finite-state machine is a small, precise contract. It names the states a process may occupy, the events that may arrive, and the conditions under which one state can become another. For an invoice, the sequence might be received, validated, awaiting_approval, approved, and paid. An event such as approve is not enough by itself: the machine checks who approved, whether the amount is within their limit, and whether required evidence exists.
The model belongs upstream of that check. It can extract a supplier name from an email, classify a request, or propose that an invoice needs review. Those outputs are claims, not commands. The application validates them against a schema, fetches authoritative records, and offers only legal transitions to the state machine. If the model returns an unfamiliar status or malformed amount, the workflow rejects the proposal rather than inventing a way forward.
This resembles runtime assurance in control systems. An advanced controller may pursue flexible behavior, while a simpler safety controller keeps the system inside known boundaries. Applied to an agent, the model is the flexible proposer and the state machine is the safety boundary. The key is that the model cannot bypass the boundary by choosing a different tool or rewriting the workflow’s history.
That boundary matters most when a workflow crosses from interpretation into an irreversible side effect. If an agent decides a bill is ready to pay, the system should not let its next tool call write directly to a payment API. Instead, a checked transition records approval and creates a durable instruction for a separate executor.
Make the record and the instruction agree
Databases make this harder than a simple diagram suggests. If the workflow updates an invoice to approved and then crashes before publishing a payment instruction, the state says one thing while downstream systems know nothing. Reverse the order and a crash may publish the instruction while leaving the invoice unapproved.
The transactional outbox pattern closes this gap. In one database transaction, the application writes the state change and an outbox event, such as payment_requested. A separate worker reads the outbox and delivers the event to the payment service. If delivery fails, the worker retries. If the application crashes, both the state and instruction are still durably recorded together.
Retries introduce another familiar problem: delivery can happen more than once. Most practical systems cannot guarantee exactly-once effects across independent services, so they make repeated delivery safe. Give each instruction a stable idempotency key, have the receiver recognize duplicates, and reconcile its response against the ledger. The system should report uncertainty when it cannot confirm an outcome, not assume that a timeout means nothing happened.
| Dimension | Model-led side effect | Guarded state-machine workflow |
|---|---|---|
| Decision | Model chooses an action | Model proposes; policy checks |
| Invalid output | May reach a tool | Rejected or sent for review |
| Retry behavior | Can repeat an effect | Idempotency key and reconciliation |
| Audit record | Prompt and response may be incomplete | State transition and event are durable |
| Human role | Often added after failure | Explicit approval gate where required |
The table describes an architectural difference, not a promise that one design eliminates operational risk. A bug in a guard, a compromised credential, or a faulty payment integration can still cause harm. Deterministic controls make permitted behavior inspectable and testable. They do not make bad rules good.
Put people at the uncertain boundary
Human approval is useful when a decision is consequential and the system lacks a reliable basis to act alone. A reviewer should see the evidence, the proposed change, the policy reason for escalation, and the exact amount or account affected. Approval should attach to an immutable snapshot of that proposal. If the amount or destination changes afterward, the approval expires and the workflow returns for review.
This is more than adding a button to a dashboard. It defines which uncertainties the organization is willing to resolve with judgment, and which rules remain non-negotiable. A reviewer may clarify a supplier mismatch. They should not quietly override a statutory limit because the model sounds persuasive. Role-based permissions, separation of duties, and an auditable record of overrides turn sign-off into a control rather than a ritual.
The model also needs bounded permissions. It may read the documents needed to prepare a case, but it should not receive unrestricted credentials to modify ledger entries or initiate transfers. Tools should expose narrow operations with typed inputs, and each operation should check the caller’s identity, the workflow’s current state, and the relevant policy. This limits the damage from a bad completion without pretending every prompt can be anticipated.
Test the whole path, not the prompt
Evaluation should cover transitions and failures, not just whether the model extracts fields accurately. Test invalid state changes, duplicate events, delayed approvals, worker restarts, stale records, and payment-provider timeouts. Add cases where the same request arrives twice or where an authoritative record changes between proposal and execution. These are ordinary operating conditions, not exotic edge cases.
Production monitoring should track state age, rejection reasons, retries, approval latency, and reconciliation mismatches. A growing number of items stuck in awaiting_approval may point to unclear policy or a missing data source, not a model-quality problem. Keep the model’s proposed intent, the validated transition, and the resulting external response distinct in logs so an auditor can reconstruct what the system knew at each step.
There is a cost to this structure: more states to design, more durable records to retain, and more integrations to reconcile. It is worth paying when actions affect money, rights, or regulated records. For reversible, low-impact work, a looser automation path may be sensible. The practical rule is to put deterministic controls at the boundary where an interpretation becomes an obligation, then scale the flexibility of the model only as far as that boundary can safely contain it.
Discussion (3)
The distinction is useful, but I'm skeptical about the 'model as proposer, code as guard' model when external systems are involved. If the model proposes an action and the state machine validates it against an external API, but that API's data changes between validation and execution, who's accountable? That's a race condition the deterministic layer can't see.
That’s a real problem. The state machine must treat the validation snapshot as part of its transition guard, and the subsequent execution must be atomic with that snapshot or explicitly re-check it. Otherwise, you have a time-of-check to time-of-use vulnerability, and accountability vanishes. The ledger must record which version of external truth was used.
In 2012, a major brokerage’s low-latency trading system failed because a model-like heuristic misclassified a market event, triggering a cascade of invalid trades. The system had no deterministic state machine to gate execution, only a probabilistic agent. When the clock skew across nodes hit 12ms, the ledger split.
Recovery required manual reconciliation across 47,000 transactions. The lesson: even if a model predicts correctly 99.8% of the time, without a state machine enforcing transitions, the system can’t recover from a single invalid state. The ledger isn’t just a record, it’s the final arbiter.