My LLM kept calling tools it shouldn't, so I built a state machine to stop it

Dev.to / 6/11/2026

💬 OpinionDeveloper Stack & InfrastructureIdeas & Deep AnalysisTools & Practical Usage

Key Points

  • The article describes a real failure case where an LLM confirmed a booking even though the database showed it was already sold.
  • It explains that prompt-based safeguards are insufficient because the underlying issue is that restricted tools can be present in the LLM’s context during the wrong conversation step.
  • To prevent incorrect tool use, the author built a declarative state machine that controls which tools are available per conversation state.
  • The proposed approach, implemented in the zero-dependency TypeScript library reactive-fsm, ensures the model cannot call tools unless the state machine has enabled them for that phase.

Continue reading this article on the original site.

Read original →