Shorter Is Not Cheaper: A Controlled Comparison of Declarative Animation Specifications and Free-Form Code for LLM-Generated Explanations
Abstract
Chat assistants increasingly answer conceptual questions with interactive, animated explanations, generated either as free-form HTML/JavaScript or as declarative specifications that a fixed runtime plays. The declarative route is widely expected to be cheaper, faster and more reliable, because its outputs are shorter and constrained. We test this expectation in controlled comparisons whose hypotheses and analysis plans were frozen before the runs. We designed ExplainSpec, a time-indexed declarative animation format, and an observation contract that makes every generated explanation programmatically inspectable; validated, pacing-agnostic checkers score 20 explanation requests from five domains. Three Claude models (360 jobs) and, in a follow-up, the open-weight Qwen3-14B with thinking enabled and disabled (240 jobs) answered every request in both formats. For every model the specifications were 25-48% shorter in answer tokens (output excluding reasoning), yet with reasoning enabled total output fell significantly only for the largest Claude model and no model generated significantly faster. The reasons differed. The Claude models reasoned far more before writing specifications (exploratory; for the two larger models, from 15-20% to 85-88% of generations). Qwen3-14B reasoned about as much in both formats (a pre-registered test of this shift was not supported), and its shorter answers saved little against a reasoning trace more than twice as long. Nor were specifications more reliable: free-form pages were valid after one repair round in 95-100% of jobs for every model, whereas Qwen3-14B produced valid specifications in only 33% of jobs and passed all semantic tests in 17% (HTML/JavaScript: 62%). For reasoning models, a shorter format alone therefore does not make generation cheaper, faster or more reliable, and a format learned in context can cost reliability.
Figures & tables
| Domain | Task | Parameters | Required state variables | Settings |
|---|---|---|---|---|
| Physics | Projectile motion | v0, theta | t, x, y | 3 |
| Physics | Simple pendulum | L, theta0 | t, angle | 3 |
| Physics | Damped spring-mass oscillator | k, c | t, x | 3 |
| Physics | RC circuit charging | R, C | t, v_c, i | 3 |
| Algorithms | Binary search | target | lo, hi, mid, found | 3 |
| Algorithms | Quicksort partition (Lomuto) | variant | arr, j, pivot | 3 |
| Valid (%) | All tests pass (%) | Output tokens (median) | Reasoning | Latency | Cost ($, 60 jobs) | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Model | Format | 1st | repair | 1st | repair | total | answer | reasoning | jobs | (s) | 1st | repair |
| Opus | HTML/JS | 100 | 100 | 100 | 100 | 2,806 | 2,795 | 0 | 9 | 21.1 | 4.43 | 4.43 |
| Spec | 88 | 100 | 83 | 95 | 2,472 | 2,043 | 402 | 51 | 20.7 | 3.89 | 4.63 | |
| Sonnet | HTML/JS | 100 | 100 | 95 | 95 | 2,595 | 2,558 | 0 | 12 | 13.6 | 2.13 | 2.13 |
| Spec | 95 | 100 | 85 | 90 | 2,886 | 1,822 | 933 | 53 | 18.4 | 2.16 | 2.32 | |
| Haiku | HTML/JS | 100 | 100 | 93 | 93 | 5,538 | 2,926 | 2,454 | 56 | 21.6 | 0.20 | 0.20 |
| Measure | Effect | Opus | Sonnet | Haiku |
| H1: total output tokens | median ratio Spec/HTML | 0.81 [0.76, 0.93] | 0.99 [0.89, 1.16] | 1.13 [0.96, 1.70] |
| Holm-adjusted | 0.040 | 1.000 | 1.000 | |
| H1: generation latency | median ratio Spec/HTML | 0.90 [0.80, 1.01] | 1.23 [0.96, 1.37] | 1.25 [1.04, 1.87] |
| Holm-adjusted | 0.368 | 1.000 | 1.000 | |
| H2: valid (with repair) | mean difference (pp) | +0 [+0, +0] | +0 [+0, +0] | 3 [ 8, +0] |
| Holm-adjusted | – | – | 1.000 |
| Category | HTML/JS | Spec |
|---|---|---|
| Wrong content (wrong algorithm step, early stop, wrong update) | 1 (1) | 4 (4) |
| Still invalid after the repair round | 0 (0) | 2 (2) |
| Extra leading state with index 0 (brief: index starts at 1) | 0 (0) | 8 (2) |
| Binary search: mid = null between probes (brief: only before the first) | 3 (0) | 0 (0) |
| Go-Back-N: sent grows within a round (ambiguity in the brief) | 3 (0) | 2 (2) |
| Harness asymmetry (runtime error swallowed, no repair; section 5.4 ) | 0 (0) | 3 (0) |
| Analysis | Opus | Sonnet | Haiku |
|---|---|---|---|
| Primary (frozen protocol) | 100 vs 95 | 95 vs 90 | 93 vs 83 |
| Runtime errors treated as exceptions (corrected) | 100 vs 97 | 95 vs 93 | 93 vs 83 |
| Corrected, with relaxed checkers (exploratory) | 100 vs 98 | 98 vs 97 | 100 vs 88 |
| Error raised by the runtime or validator | Artifacts |
|---|---|
| Object indexed with a dynamic key / member access on a non-object | 8 |
| Array function applied to a non-array (e.g. a null initial state) | 4 |
| = prefix inside a plain expression field ( dur , derived ) | 4 |
| Malformed expression (unbalanced brackets, unquoted text) | 3 |
| Non-terminating while loop | 2 |
| Derived variable used inside a step | 2 |
| Valid (%) | All tests pass (%) | Output tokens (median) | Latency | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Mode | Format | 1st | repair | 1st | repair | total | answer | reasoning | (s) |
| Thinking | HTML/JS | 85 | 95 | 60 | 62 | 4,655 | 1,559 | 3,370 | 103.7 |
| Spec | 13 | 33 | 8 | 17 | 4,513 | 906 | 3,686 | 95.0 | |
| No thinking | HTML/JS | 83 | 97 | 35 | 40 | 1,618 | 1,618 | 0 | 29.2 |
| Spec | 10 | 32 | 0 | 3 | 982 | 982 | 0 | 18.1 | |
| Test | Direction | Effect [95% CI] | Holm | |
| Q1 (primary): reasoning tokens | Spec HTML/JS | 1.07 [0.95, 1.33] | 0.071 | 0.286 |
| Q2a: answer tokens | Spec HTML/JS | 0.52 [0.49, 0.61] | 0.001 | 0.001 |
| Q2b (H1): total output tokens | Spec HTML/JS | 0.87 [0.76, 1.04] | 0.184 | 0.552 |
| Q2c (H1): generation latency | Spec HTML/JS | 0.89 [0.77, 1.11] | 0.324 | 0.648 |
| Q3 (H2): valid (with repair), pp | Spec HTML/JS | 62 [ 78, 43] | 1.000 | 1.000 |
| Q4 (H3): all tests pass (with repair), pp | two-sided | 45 [ 63, 27] | 0.001 | 0.004 |
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
Structured Output Generation
Structured output generation studies how language models produce machine-readable, schema-compliant responses without sacrificing task accuracy.
See all 65 papers