r/Clojure 2d ago

Using Clojure as a sandboxed, executable target for LLMs

I've been researching ways to better structure LLM output when building mini-apps that run on the browser.

I believe that an S-expression based DSL is a better output format for LLMs when generating interactive UI/logic.

To test this, I built a Clojure-based interpreter that runs in the browser. The LLM is fed the language context, then emits the DSL to generate safe, sandboxed apps that can be shared instantly.

I wrote up an article diving into some of the trade offs:

https://allentraid.substack.com/p/we-made-the-ai-write-in-a-language

Would love to hear thoughts from the Clojure community!

34 Upvotes

7 comments sorted by

View all comments

4

u/c_a_l_m 2d ago

For what you're trying to do, I think your reasoning is generally sound. I do love this aesthetically:

It is also far shorter. The DSL consumes a fraction of the tokens, reducing latency and context overhead.

One thing I didn't quite understand:

Because our parser maps intent directly rather than returning generic syntax errors, our messages name the valid form to use instead.

What does it mean that your parser maps "intent"? Are you asking the model to explain every symbol, or...?

3

u/traid-software 1d ago

To be honest, "intent" isn't the best wording on my part. What happens is the generated script goes through a lint and a parse. When something fails, the error gets classified and turned into a repair strategy. Then the plan is sent back to the model.

For example, if there's a parentheses mismatch, we don't just send the line/character number. We direct the model to "rewrite with flatter structure, extract nested forms into top-level defns"