The reason large language models hallucinate is structural, not moral. A free-running model is an open-ended next-token generator: at every step it can go anywhere, and "anywhere" includes confidently wrong. The fix that production systems converge on is not a better prompt. It is a smaller box.
The Problem With Open-Ended Generation
Ask a model to "handle the customer's request" and you have handed it an unbounded action space. It might answer correctly. It might invent a policy that does not exist, call a tool that should not be called, or wander off the task entirely. The flexibility that makes LLMs powerful is the same property that makes them unreliable in workflows where correctness matters.
The Finite-State Machine Pattern
A finite-state machine constrains the model to a defined set of states and a defined set of legal transitions between them. Instead of "generate freely," the model's job at each step becomes "given that we are in state X, choose among these specific valid next moves." Concretely:
- States encode where you are. Collecting information, awaiting confirmation, executing an action, handling an error — each is an explicit state.
- Transitions encode what is allowed. From "awaiting confirmation" the only legal moves are "confirmed" or "cancelled." The model cannot transition to "execute action" without passing through confirmation.
- The model fills the gaps, the machine holds the rails. The LLM supplies language and judgment within a state; the state machine guarantees the overall flow stays valid.
Why This Works
Three properties fall out for free:
- Bounded behavior. The model literally cannot take an action that no transition permits, so the worst hallucination is contained to a single state.
- Auditability. Every run is a path through a known graph. You can see exactly which states it visited and why — a property free-form generation never offers.
- Testability. A finite graph can be tested exhaustively. An open-ended generator cannot.
The Read
Reliability in AI workflows does not come from trusting the model more. It comes from needing to trust it less — by surrounding it with structure that makes the catastrophic moves impossible rather than merely unlikely. The finite-state machine is one of the cleanest ways to do that: it keeps the model's intelligence and removes its license to improvise where improvisation is the enemy.