We are trying to implement a page generator using LLMs. We know LLMs support structured…
- User
We are trying to implement a page generator using LLMs. We know LLMs support structured output using JSON, that means we need to find a suitable output format (since input is free text), that will allow the LLM to respond in JSON with a predictable format, that still allows the user for extreme customizability, while also bridging the gap between the requirements of customizability, and structured output, since we will also provide "visual editing" in our frontend, we need to be able to interact with this format predictably and simply as well.
To help with your research, we share a bit more detail on the following:
What kind of pages are you trying to generate? (e.g., marketing pages, blogs, documentation, UI components, etc.) Do you already have a frontend technology in place (e.g., React, Vue)? Are there specific features or components that the JSON output should support (e.g., layout blocks, text, images, buttons, embedded media)? Should the format support any styling/customization options (e.g., colors, fonts, spacing), or is structure-only enough? Do you want the output format to align with any existing standards (e.g., JSON Schema, MDX, Figma JSON, etc.)?- It can be any type of page, since we are a "website builder" kind of service.
- It's irrelevant, you need to research the output format, think "data layer", which is agnostic to the "view" layer.
- it should support any kind of layout requested, any kind of text and any kind of media. It should be a format flexible enough to generate any kind of layout, while not being "pixel" position level, it should be similar to a layout kind of like grid, but flexible, and simple enough to use.
- Any kind of styling should be supported, like font, sizing, spacing, colors, etc. To make this constructive and easy to work with, we should have a layered design tokens returned as part of the output. it should be layered with primitive tokens, system tokens (which explicitly reference ONLY primitive tokens), and component tokens (per component, and reference explicitly system tokens)
- JSON / Schema to make sure we can explicitly denote some of the limitations, etc
I'll repeat to ensure this is clear. The layout schema, should be independent of the View Layer-What this means is, that it shouldn't rely on primitives related to HTML like css(flex,grid,etc), since we may be implementing in html, or css, or in WPF or in an unknown view layer, it shouldn't be coupled, but it should be simple enough so that we can implement it with whatever view layer we choose to use.
- Assistant
Below is a proposal for a view‐agnostic, JSON-based “page” format that:
• Lets your LLM emit fully structured JSON
• Supports arbitrary layouts (grid-like or stacked)
• Carries rich styling via layered design tokens
• Is validated by a JSON Schema (so you can enforce constraints)—
1. Top-level shape
{ "page": { "id": "page-123", "meta": { "title": "My Awesome Page", "description": "A hero example" }, "tokens": { /* see section 2 */ }, "layout": { /* see section 3 */ } } }—
2. Layered Design Tokens
"tokens": { "primitives": { "color-blue-500": "#007AFF", "color-gray-100": "#F5F5F5", "font-sans": "Helvetica, Arial, sans-serif", "space-1": "4px", "space-2": "8px", "size-1": "8px", "size-2": "16px" }, "system": { "primaryColor": { "ref": "primitives.color-blue-500" }, "background": { "ref": "primitives.color-gray-100" }, "bodyFont": { "ref": "primitives.font-sans" }, "smallGap": { "ref": "primitives.space-1" }, "largeGap": { "ref": "primitives.space-2" } }, "components": { "button": { "backgroundColor": { "ref": "system.primaryColor" }, "fontFamily": { "ref": "system.bodyFont" }, "padding": { "ref": "system.smallGap" } }, "card": { "bgColor": { "ref": "system.background" }, "borderRadius": "4px", "padding": { "ref": "system.largeGap" } } } }Why layers?
- Primitives are the raw values.
- System tokens name your design system’s semantics.
- Component tokens build on system tokens for each UI piece.
—
3. Layout Model
We use a tree of “containers” (for layout) and “elements” (text, image, button, etc.).
3.1 Container Types
- Stack (vertical or horizontal flow)
{ "type": "stack", "direction": "vertical", // or "horizontal" "gap": { "ref": "system.largeGap" }, "align": "center", // cross-axis alignment: start|center|end "children": [ /* containers or elements */ ] } - Grid (abstract grid, not CSS-only)
{ "type": "grid", "columns": [ "1fr", "2fr" ], // you can use fractional units or token refs "rows": [ "auto", "auto" ], "gapRow": { "ref": "system.smallGap" }, "gapCol": { "ref": "system.largeGap" }, "areas": [ ["header", "header"], ["sidebar","main"] ], "children": [ { "area": "header", "/* container or element */": { … } }, { "area": "sidebar", "…": { … } }, { "area": "main", "…": { … } } ] }
3.2 Elements
// Text { "type": "text", "content": "Welcome to our site", "style": { "fontFamily": { "ref": "system.bodyFont" }, "fontSize": "24px", "color": { "ref": "system.primaryColor" }, "marginBottom": { "ref": "system.smallGap" } } } // Image { "type": "image", "src": "https://…", "alt": "hero shot", "width": "100%", "height": "auto", "style": { "borderRadius": "8px" } } // Button { "type": "button", "text": "Get Started", "action": { "type": "link", "href": "/signup" }, "tokenStyle": { "component": "button" } }—
4. Sample Page Snippet
{ "page": { "id": "landing-1", "meta": { "title": "Landing", "description": "" }, "tokens": { /* … as above … */ }, "layout": { "type": "stack", "direction": "vertical", "gap": { "ref": "system.largeGap" }, "children": [ { "type": "stack", "direction": "horizontal", "align": "center", "gap": { "ref": "system.largeGap" }, "children": [ { "type": "text", "content": "Hello World!", "style": { "fontSize": "32px" } }, { "type": "button", "text": "Sign Up", "action": { "type": "link", "href": "/signup" }, "tokenStyle": { "component": "button" } } ] }, { "type": "grid", "columns": ["1fr", "1fr"], "rows": ["auto"], "gapCol": { "ref": "system.smallGap" }, "children": [ { "area": null, "type": "image", "src": "https://…/hero.png", "alt": "hero" }, { "area": null, "type": "text", "content": "Our product is great.", "style": { "fontSize": "18px" } } ] } ] } } }—
5. Validating with JSON Schema
You can write a companion schema (Draft-07 or later) to enforce:
- Allowed container types, required fields
- Token layers and
refsemantics - Element-type unions and style shapes
This gives you full type safety at generation-time, and a predictable structure your React/Vue/WPF/etc. front-end can render or edit visually.
—
How to prompt your LLM
- Embed your JSON Schema in the system prompt (or via
$schema). - Tell the model:
“Output only valid JSON matching this schema.”
- Give it instructions on which tokens to use, what sections you want, etc.
With this setup you get:
- High customizability in free-text prompts
- Strictly structured JSON output
- View‐agnostic layout primitives
- A token system that keeps your design consistent across pages.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.