← Writing

Generative UI: four ways to let a model write the interface

By ·

View the generative-ui project →

Generative UI fascinates me. Every app I use ships the same screens to everyone, and a model could instead build the one screen that fits the task in front of me: a table when I compare products, a form when I need to fill one in. I keep wondering how much of UI will work that way in a few years. Early research points the same way: Google found that people prefer generated UIs to markdown replies, and a Stanford study reports up to a 72% gain in human preference over chat. The catch is control. The model can choose the layout, but the application has to decide what that UI is allowed to do.

That still leaves a practical question. What should the model send to the renderer, and how much freedom should it have? Existing tools answer different parts of that question:

  • Vercel AI SDK’s streamUI lets a model call tools that return React components. Its RSC API is experimental, and Vercel recommends AI SDK UI for production.
  • json-render’s component catalogs constrain generated JSON specs. Google’s A2UI format also describes UI with data, which the client maps to its own components.
  • v0 generates frontend code, including React components. Claude artifacts can contain websites and interactive tools beside the conversation.
  • MCP Apps delivers interactive HTML interfaces inside a host, in a sandboxed iframe. MCP-UI’s SDKs implement that standard. This defines how a tool delivers its UI, without requiring a model to generate it.

OpenAI’s Structured Outputs can constrain replies to a supported JSON schema. The application still needs a renderer and rules for what those values mean.

I wanted to measure the output formats under the same prompts. I built Generative UI Lab, a local React and Hono playground that compares JSON patches, a strict JSON schema, HTML, and a small tag format. I measured time to first render, total time, parser validity, and output tokens.

nejcm/generative-uiLocal playground comparing UI-generation approaches across models.TypeScript(opens in new tab)

The demo is a static build of the lab. It cannot call models, but it holds 677 saved runs from the latest batches, Claude and OpenAI models plus seven open-weight model and host pairs, grouped by prompt, model, and effort. You can open a group to compare the four approaches side by side and replay each run with its original timing.

Generative UI Lab demoSaved benchmark runs with replay. It makes no model calls.(opens in new tab)

Four formats for the same prompts

The three structured approaches share one component catalog and renderer. HTML uses its own elements and styles. All four receive the same design brief and fixtures, so this compares implementations as well as formats.

  • json-render streams JSONL lines of RFC 6902 patches through json-render. The system prompt comes from the catalog, and each patch passes Zod validation.
  • flat-strict asks for JSON that matches a strict schema. The reply is a flat list of elements, and children are id references, a shape close to the flat component list A2UI describes. The renderer parses the partial JSON as it arrives.
  • html asks for an HTML body. The page shell supplies the stylesheet and a chart helper, and the result runs in a sandboxed iframe with a CSP. Google’s Generative UI research also has the model emit HTML, CSS, and JavaScript, and notes that generation can take a minute or more.
  • markup is a format I added during this work. It writes catalog components as nested tags with quoted props, and it reuses the catalog validator and renderer.

A markup reply for the login prompt starts like this:

<Stack gap="lg" align="center">
	<Card title="Welcome back" description="Sign in to your account to continue.">
		<Input label="Email address" type="email" placeholder="[email protected]"/>
		<Checkbox label="Remember me" checked="false"/>
		<Button label="Sign in" size="lg"/>
	</Card>
</Stack>

The parser exposes each valid element once its opening tag is complete, so the UI fills in tag by tag.

How I measured

The latest batch used the Anthropic API for Haiku 5.5, Sonnet 5.5, and Opus 5.5, and the OpenAI API for GPT-6 Luna and GPT-6.1 Sol. A second batch ran smaller open-weight models through the Vercel AI Gateway, each pinned to one host. A headless script, scripts/bench.mts, runs the matrix of model, effort, approach, and prompt against the local API. Of the 10 presets, login is a plain form, dashboard gets a sales fixture, and comparison gets a products fixture. The other seven have no fixture or required-content checks. flat-strict used provider-enforced structured output in both batches. Anthropic’s structured outputs docs list recursive schemas as unsupported, which fits a flat list, and note extra latency the first time a schema is used. I did not separate that cost from the timings.

The 2026-10-26/27 API batch planned 360 runs, one per cell: nine model and effort configurations, four approaches, and all 10 presets. Haiku and Sonnet ran at low and medium effort, Opus and Sol at low, and Luna at low, medium, and high. Runs were sequential, with a 1 s pause. Three Sol runs hit server overload errors and were discarded and rerun. I later trimmed the states preset to one run per model and dropped one slow outlier, which leaves 328 runs. The full benchmark report includes the earlier subscription batches as appendices. The charts below use the new batch. Its tables regenerate with node scripts/bench-stats.mts bench-2026-10-26.

Across all four approaches, Anthropic reached 99% parser validity (183 runs) and OpenAI 98% (145). Only five runs were invalid, all from Haiku or Luna. The open-weight batch reached 73% (584 runs).

The baseline exposed prompt and schema bugs

The first batch made html look slow and flat-strict look unreliable. The failures gave me specific implementation problems to investigate.

The baseline report traces the flat-strict failures to Checkbox.checked. The catalog descriptions advertised $bindState bindings, which flat-strict does not support. Models wrote a binding string into a boolean prop, and the parser dropped the whole element. I removed the binding hints from the prompt. The parser now drops only an invalid optional prop, with an error that still counts against validity.

I also moved a fixed stylesheet and a chart helper into the HTML page shell and asked for the body only. The model no longer needs to repeat that code. These changes mean the batches compare different implementations, so I cannot attribute every improvement to the output format.

I take this as the main lesson of the baseline. When one approach fails much more often than the others, look at the prompt and the schema before you blame the model.

Markup finishes sooner, with a quoting problem

On the 328 Anthropic and OpenAI API runs, markup again finished sooner, but it was the least reliable approach. Its parser validity was 96%, against 99% for json-render and flat-strict, and 100% for html.

Median total time, Anthropic + OpenAI API (s)
Median total time, Anthropic + OpenAI API (s)
LabelValue
json-render15.5 s
flat-strict13.6 s
html14.1 s
markup8.1 s
Median output tokens, Anthropic + OpenAI API
Median output tokens, Anthropic + OpenAI API
LabelValue
json-render2,219
flat-strict1,753
html2,206
markup1,019

markup had the lowest median total time for every Claude and OpenAI model, with about half the output tokens of the other formats. The new batch had Table.rows string-for-array failures: three from Luna (two markup, one flat-strict) and one from Haiku (markup). Haiku also passed a number where json-render expected a string in a Stat.

In the older 2026-10-25 batch, the two Luna markup failures showed a quoting problem. Both tables used &quot; for inch marks inside JSON row values. The parser decoded those entities before it parsed the JSON. The resulting unescaped quotes broke the JSON, so rows remained a string and failed validation. I replayed both replies through the current parser in memory. Replacing those entities with escaped JSON quotes removed every error. That points to the parser’s handling of nested escaping as the first fix. In the new batch, all three markup Table.rows failures were on comparison and contain &quot; entities, which fits the same cause. I have not replayed them through the parser.

The open-weight models show a much wider validity gap between formats. HTML passed every run, while the structured formats failed on bad prop shapes, enum values, and missing elements.

Parser validity, open-weight models via AI Gateway (%)
Parser validity, open-weight models via AI Gateway (%)
LabelValue
json-render48%
flat-strict72%
html100%
markup71%

json-render was the weak point. Nemotron 3.5 Lightning passed 6% of its runs: it named a root element and never added it. MiniMax M3.1 Flash passed 32% and Qwen3.8 Flash 33%. The most common errors were Stack.gap values outside the enum, a stray closing brace, and missing root elements. In markup, models wrote unquoted or invalid checked values and gap="xs", a value the catalog does not allow. Remember that HTML only has to contain a tag to pass.

Tags avoid repeated structural JSON keys and explicit element ids, though array props still contain JSON. My guess is that models have seen far more JSON than this tag format. The benchmark does not test that explanation. I would fix the escaping problem before adding a repair step or changing which table values the schema accepts.

Higher effort did little for parser validity

Haiku went from 6.0 s at low effort to 11.3 s at medium, with validity rising from 94% to 100%. Its time to first render rose from 1.5 s to 6.9 s. Sonnet went from 9.9 s to 11.4 s, with 100% validity at both levels. Luna took 10.4 s, 15.4 s, and 19.1 s at low, medium, and high, with validity of 94%, 97%, and 100%. Those validity gains rest on two failures each for Haiku low and Luna low, out of about 36 runs per configuration, so I would not read them as a trend. This batch also does not show that higher effort produces more useful UIs.

At list prices, the 360 API-billed runs cost about $5.11 in total. Per run, Luna cost $0.0008 to $0.0014, Haiku $0.0012 to $0.0017, Sol $0.018, Sonnet $0.025 to $0.027, and Opus $0.053. Opus had 100% validity like Sonnet and Sol, but took a median 14.9 s against Sonnet’s 10.3 s and cost about twice as much per run. I see little reason to pay for Opus on this parser-validity target. The open-weight runs cost $1.75 for 584, between $0.0007 and $0.0076 per run on average by model.

The lab now defaults new lanes to low effort.

Prompt differences

On the Claude and OpenAI models, comparison took the longest at a median 19.3 s and had the lowest parser validity at 92%. Its markup runs were only 67% valid. login was fastest at 5.6 s, followed by profile at 8.0 s. The open-weight models struggled most with comparison too, at 53% validity.

Median total time by preset, Anthropic + OpenAI API (s)
Median total time by preset, Anthropic + OpenAI API (s)
LabelValue
login5.6 s
profile8 s
table11.3 s
pricing12.9 s
onboarding13.8 s
dashboard14.8 s
settings15.4 s
portfolio17.3 s
comparison19.3 s

These prompts ask for different amounts of content, so their timings are no clean measure of model ability. The table failures also show why a form alone would have been too narrow a test.

Small models, slow hosts

I expected the small and flash models to beat the frontier ones on speed. On their default hosts they mostly did not: a median 18.7 s against 10.3 s for Anthropic and 15.3 s for OpenAI. Some hosts generate only 40 to 100 tokens per second, and some models reason at length before writing (Nemotron produced about 6.5k reasoning tokens per run).

The same model on a faster host told a different story. Qwen3.8 27B dropped from 44.9 s on deepinfra to 2.0 s on cerebras, DeepSeek V4.1 Flash from 16.7 s to 5.4 s on togetherai, and GLM-5.3 Flash from 20.9 s to 5.8 s on boundless. Validity held only on togetherai (89% to 87%); Qwen3.8 27B fell from 98% to 65% and GLM from 78% to 42%. The fast-host samples are small, 12 to 31 runs, and I have not checked whether those hosts serve lower-precision weights.

Median total time, same model on two hosts (s)
Median total time, same model on two hosts (s)
LabelValue
Qwen3.8 27B deepinfra44.9 s
Qwen3.8 27B cerebras2 s
DeepSeek V4.1 Flash deepseek16.7 s
DeepSeek V4.1 Flash togetherai5.4 s
GLM-5.3 Flash zai20.9 s
GLM-5.3 Flash boundless5.8 s

What I could not measure

fidelity checks for required words. Where defined, the median was 100%, though two Luna json-render runs on comparison scored zero. Fixture coverage was 92 to 100% for every model except Nemotron, at 78%. Five presets have neither measure. Coverage searches the raw output for fixture values, so it cannot prove that the screen displays those values correctly. Human ratings and checks of the generated controls are still missing. StructEval makes a similar point: across 18 output formats, correct renderable output is harder for models than valid text structure.

Which one I would pick

For a product with an existing component library, I would start with json-render. I can validate its props and keep rendering under application control. I would consider flat-strict when I want one JSON document and can enforce its schema through the provider.

For a disposable prototype with custom layouts, or with a small open-weight model, I would pick html and keep the sandbox. Its parser-validity score gives me little confidence about behavior. I would consider markup for latency-sensitive output after fixing escaping, then measure it again with validation and repair included.

My next experiment would keep fixture data in the application and let the model refer to it. Repeating table rows costs output tokens and adds escaping problems. I have not measured that alternative yet. For now, the result I trust most is that prompt design and parser behavior changed the comparison enough to deserve as much attention as model choice.