Build1 publisher3 min readPublished
A typed internal DSL trades first-try compile rate for fewer invented keywords
An InfoQ article argues that model hallucination on a home-grown notation is a corpus-frequency problem, and its fix puts the domain inside a host language's type system so an invalid domain state fails to compile.
The Engineer · Build desk
What happened
- An InfoQ article argues that model hallucination on a domain-specific language is a training-data-frequency problem, since models write mainstream languages reliably and invent syntax for sparse or newly designed ones.
- The proposed alternative, Typed Domain Grounding, embeds the domain as a typed internal DSL inside a training-data-rich host language and shapes the API so domain errors surface as compiler type errors.
- The same pattern appeared with GPT-4o but not with every model tested, and the article limits its conclusion to what a strict rejecting oracle can do, without claiming it always does so.
Compiled by The EngineerSomething wrong?How this is made
Why it matters
- cost The fidelity gain is paid for in compile-and-retry cycles, so the token spend and latency of the generation loop absorb the lower first-try compile rate.
- constraint Adopting the approach bounds your notation by what a host language's type system can express, and ties the DSL's future to that language's toolchain.
- decision A team designing a new DSL now has to settle internal-versus-external before any grammar work, while a team with a working external DSL is advised to leave it alone.
- precedent Because the result did not reproduce across every model tested, any team leaning on the compiler as its guard rail owes itself a per-model check before trusting the pattern.
Interpolation is what makes this hard to catch. A model handed a notation it has never seen does not stop. It borrows from grammars, APIs and notations it has seen, and the article names that transfer as the failure route [8]. It smuggles in arrow syntax from Mermaid or PlantUML. It calls an `addRelation` or `withLabel` your API would plausibly have but does not, and hands three arguments to a construct that takes two because a syntactic cousin takes three [9]. Each of those is the corpus's most probable completion applied to a language the corpus never contained, and the article describes the result as "fluent, well-indented, and wrong" [9][10].
Leniency compounds it. Diagram tools and config parsers are built to skip the line they cannot parse, render a best guess, and never punish a typo. That is hospitality for a human author and, in the article's phrase, a trap door for a machine one [11]. The worked example is a ten-class diagram with one invented relationship keyword: the parser skips that line, and what lands in the design document is a professional-looking diagram missing exactly one association [12]. A human who mistyped would have noticed, because a human intended the association. The model intended nothing, and the engineer reading nine correct classes in clean typography has no reason to suspect the tenth [13].
The proposal moves the rejection point from the parser to the type checker [3]. The surface syntax becomes a language the model already writes well, because it appears millions of times in training data. That is the same frequency relationship the article ties to code-LLM benchmarks that classify languages by popularity and find low-resource languages degrading [15][7]. Retrieval does not reach this failure. It grounds the facts in a response and leaves the notation alone, so a model with accurate domain knowledge can still emit an invented statement [2].
The benchmark is where I would be careful. Fifty tasks, Claude Sonnet 5, measured against two lenient external DSLs, with higher Structural Fidelity and a lower hallucination rate for the typed internal DSL and a lower first-try compile rate [4]. The published takeaways give the direction of each gap without sizing it [16]. At fifty tasks, one task is two percentage points of any rate reported over the set [14]. A first-try compile rate below the lenient baselines means the fidelity arrives after rejection, so the compiler's error has to get back to the model. In a one-shot pipeline that writes straight into a build artifact, you get a failed build instead of a quietly incomplete diagram. That is a better failure than silence, and it is not the fidelity the benchmark reports.
For the number to transfer, your tasks would have to resemble those fifty. Your host language would have to be one the model writes as reliably as Kotlin or TypeScript. And your generation loop would have to contain the compiler. The article holds its own conclusion narrowly. The same pattern appeared for GPT-4o but not for every model tested, and the evidence shows that a strict, rejecting oracle "can converge to more reliable output than a forgiving one, not that it always does" [5].
The costs are stated in the source. It closes syntax gaps and leaves understanding gaps open [6]. It also trades away notational freedom and demands a commitment to a host language. The source presents the recommendation as a default consideration for new DSLs, and says it is no reason to rewrite a DSL that already works [6].
What to watch
- Which models the pattern failed for; the article says it did not hold for every model tested, and the names would set the scope of the claim.
- Publication of the per-condition percentages and the fifty-task list, so the fidelity and hallucination gaps can be sized against the two-point-per-task resolution.
- Results for a host language the model writes less reliably than Kotlin or TypeScript, which is the case the frequency argument predicts will erode.