InfoQIrakli Betchvaia18 min readintermediate
Article: Your Next DSL Author Is a Language Model
Summary
Typed Domain Grounding (TDG) embeds a DSL inside a mainstream language the LLM already knows (e.g., Kotlin) and uses the host compiler as an oracle. The author describes five building blocks—embedding, choosing a host language with high training‑data frequency, compiler‑driven type safety, a generate‑compile‑repair loop, and an on‑demand teaching tool—and shows measured results from kUML, a Kotli…
- LLMs hallucinate DSL syntax because the language has zero training‑data frequency; they interpolate from similar grammars.
- Embedding the DSL in a host language with abundant LLM exposure (Kotlin, TypeScript, Python) eliminates the syntax‑hallucination problem.
- Typed APIs (named parameters, enums, sealed hierarchies) turn domain errors into compile‑time type errors that the model can see and repair.
- A Generate‑Compile‑Repair (GCR) loop feeds compiler diagnostics back to the model, limiting regeneration to three attempts; failures after that indicate missing concepts.
If engineers rely on LLMs to author DSLs for modeling, infrastructure, or config, silent syntax hallucinations can propagate incorrect artifacts. TDG provides a pragmatic, tool‑leveraging path to safe LLM‑generated code without building new parsers or sacrificing expressiveness.
7/10


