LLMs frequently emit malformed S-expressions (unbalanced ()[]{}) when generating Clojure/EDN/Lisp code. Post-hoc “repair” is surprisingly difficult. Saving source code files with balancing errors, or streaming them to nREPL/compilers, wastes time and relies on imbalance detection after the tokens are generated.
What if we could prevent these types of error by creating a tool (stateless, stack-based, cursor-aware) for LLMs to use to help them write perfectly balanced S-expression. Ideally while minimizing latency, round-trips, total time required to generate code, and without any MCP server-side state.
Current LLMs are inherently auto-regressive auto-completers, which makes them inherently bad at the problem of closing S-expressions -- they don’t have anything resemblig a “stack” for them to store state (e.g., I just emitted an open parenthesis, and here’s an open bracket. I want to close the form — now what?). Nor does it have an equivalent of a “find