5.1

DSLs Enable Reliable Use of LLMs

Domain-Driven DesignAI & LLMsArchitectureTesting

Martin Fowler and Unmesh Joshi argue that Domain-Specific Languages make LLM code generation reliably correct by constraining the space of valid outputs. The post begins from the premise that upfront specification is impossible — design is discovered iteratively through implementation, not specified in advance. DSLs address the LLM reliability problem because their narrow vocabulary responds well to a few in-context examples and almost always ships with a deterministic validator that enables self-correcting agent loops. The authors identify two distinct LLM roles: brainstorming partner during the design phase, then natural-language interface once the abstraction is established. They conclude that the DSL itself, not the prompt, is the enduring artifact worth maintaining.

DSLs make LLM generation reliable not by improving the model but by shrinking the target: a constrained vocabulary with a built-in validator leaves the LLM little room to hallucinate and lets agents self-correct, while elevating the generated DSL artifact — not the prompt — into the maintainable source of truth.
  • 5

    A specification is at best a starting hypothesis: the real constraints, trade-offs, and edge cases are discovered iteratively, as we proceed with the implementation.

  • 4

    Writing code, by contrast, forces us to think through concrete decisions—such as where a responsibility belongs or what boundaries should be exposed so the design can be extended further.

  • 6

    DSLs make LLMs more reliable because they respond so well to a few in-context examples. A general-purpose language like Java offers lots of valid ways to express the same intent. A DSL strips the variation away.

  • 4

    The errors are phrased at the level of the domain — 'you cannot select an action before choosing a client' — rather than as a stack trace buried deep in generated code.

  • 6

    Because the surface is so small — and the space of valid code it can generate is so much smaller than the space of valid Java programs — the LLM has very little room to hallucinate.

  • 4

    The grammar is enforced by the type system through progressive interfaces — you cannot declare a step before the topology, or an action before selecting a client — so whole classes of malformed scenarios simply do not compile.

  • 7

    The enduring asset is not the prompt, but the DSL and the semantic model.

technical, constructive, evidence-driven