Representing your API calls as S-expressions is functionally superior to JSON for several reasons:
- Homiconicity: Because code and data share the same structure in Lisp-like languages, it is trivial for a small model to manipulate and nest these expressions. A 3B model can easily construct a complex (SELECT ... (WHERE ...)) tree because the syntax is inherently hierarchical.
- Grammar Enforcement: You can implement a syntax-directed decoder. Instead of letting the model predict free-form tokens, you can constrain the decoding process to only accept valid S-expression symbols. This makes it impossible for the model to hallucinate invalid syntax.
- Recursive Nesting: LLMs struggle with linear "procedural" code because they often lose track of closing braces or depth. S-expressions force the model into a recursive paradigm that naturally maps to the way Transformers process nested attention heads.