AI responses
Let the model in your product answer with interface instead of a wall of text: numbers as stats, results as tables and charts, next steps as buttons, questions as forms. All of it in your theme, and safe to draw while it streams.
What the model writes
Sales were **$48,210** last week, up 12% on the week before.
```ui
{"type": "grid", "children": [{"type": "stat", "label": "Revenue", "value": "$48,210", "delta": "+12%", "trend": "up"}, {"type": "stat", "label": "Orders", "value": "1,284", "delta": "+8%", "trend": "up"}, {"type": "stat", "label": "Refunds", "value": "1.9%", "delta": "+0.2%", "trend": "down"}]}
```
Most of the growth came from two countries:
```ui
{"type": "chart", "kind": "bar", "label": "Added revenue by country", "labels": ["Germany", "Brazil", "France", "Japan"], "values": [2140, 1310, 620, 410], "valuePrefix": "$", "height": 200}
```
```ui
{"type": "table", "label": "Top products", "columns": [{"key": "product", "label": "Product"}, {"key": "sold", "label": "Sold", "type": "number", "align": "end"}, {"key": "status", "label": "Stock", "type": "badge", "tones": {"Low": "warning", "OK": "success"}}], "rows": [{"product": "Field backpack", "sold": 412, "status": "Low"}, {"product": "Travel pouch set", "sold": 388, "status": "OK"}, {"product": "Leather luggage tag", "sold": 251, "status": "OK"}]}
```
```ui
{"type": "suggestions", "items": ["Compare the plans", "Book a demo"]}
```What the reader sees
How did sales go last week?
Use a button, a suggestion or the form in an answer: the event it fires shows here.
How it works
- The model learns the components.
uiPrompt()returns instructions for your system prompt: how to add components to an answer, and the list of components with their props (about 2,300 tokens). - It answers in Markdown, and where a component is clearer than prose it adds a fenced block with the language
uithat holds JSON. <pm-ai-response>draws it. Text becomes headings, lists, tables and code blocks; eachuiblock becomes Prismora elements. What the model wrote is checked first, and nothing in it ever becomes HTML.
One typed list of components (UI_CATALOG) is the source of the prompt, the JSON Schema, the check and the
renderer, so they cannot disagree. This is the same idea as other typed-component formats for model output, built on
the Prismora elements you already use: there is nothing to map and no second design to maintain.
Quick start
On the server, add the prompt to your system prompt and stream the model's text. This example uses the Claude API:
In the browser, write the text into the element as it arrives:
The prompt is plain text. With OpenAI, Gemini or a model you host, put uiPrompt() into the system (or
developer) instruction the same way, and write the text you receive into the element. Nothing here depends on one
provider.
The format
- A
uiblock holds one component or an array of them. A component is an object withtypeand that type's props; containers takechildren, an array of components and strings. - Strings in
childrenand props of the kind text may use inline Markdown. - The Markdown around it is the Markdown models write anyway: headings, lists and task lists, tables, quotes, notes (
> [!WARNING]), code fences, links and emphasis. - The fence may also be named
prismoraorpm-ui.
Components
Props marked ? are optional. The full kinds and choices are in the prompt (uiPrompt()) and in the schema (uiSchema()).
| Type | What it is | Props |
|---|---|---|
stack | Children one under another. | gap?children |
row | Children side by side, wrapping when there is no room. For buttons, badges and short items. | gap?align?children |
grid | Children in equal columns that fold to fewer on narrow screens. For stats and cards to compare. | min?children |
card | A bordered container with an optional heading. Groups one result, option or summary. | heading?description?children |
tabs | Alternative views of the same thing, one visible at a time. Children are `tab`. | label?children |
tab | One view of `tabs`.Inside tabs. | labelchildren |
accordion | Sections that open and close, for details most readers skip. Children are `section`. | single?children |
section | One section of `accordion`.Inside accordion. | headingopen?children |
divider | A line between two parts. | |
heading | A heading inside a component. | textlevel? |
text | A paragraph inside a component. | textsize?muted? |
markdown | Markdown inside a component: lists, tables, code. | text |
badge | A short label for a state or category. | texttone?variant? |
status | A coloured dot with a label: online, failing, pending. | texttone?pulse? |
alert | A highlighted note: a warning, a tip, an error, a success. | tone?heading?text?children |
code | Source code with highlighting and a copy button. | codelanguage?label? |
stat | One key number with its label and change. | labelvaluedelta?trend?description?icon? |
table | Rows and columns of data. Prefer it to a Markdown table when values need formatting or sorting. | labelcolumnsrowsstriped? |
chart | A bar, line, area or donut chart. For trends and comparisons of numbers. | kindlabellabelsseries?values?stacked?height?valuePrefix?valueSuffix? |
progress | How far something has come. | labelvaluemax?showValue?variant? |
rating | A star rating. With `name` inside a form it is an input. | labelvalue?max?name? |
details | Label and value pairs: the facts of one thing (an order, a person, a booking). | itemslayout?columns? |
list | A list of items with a heading, a description and an optional link or action each. | labelitemsdivided? |
steps | Numbered steps of a process, with the current one marked. | label?itemscurrent?orientation? |
timeline | Events in time order. | label?items |
image | A picture with a caption. | srcaltcaption?ratio? |
avatar | A person: picture or initials. | namesrc?size? |
result | The outcome of something that was done: success, failure. | statusheadingdescription?children |
button | A button. With `action` it reports back to you; with `href` it is a link. | labelaction?params?href?variant?tone?size?icon? |
suggestions | Short replies the reader can pick instead of typing. Put them last. | items |
form | Fields the reader fills in and sends back to you. Children are fields and text. | actionparams?submit?children |
input | One line of text.Inside form. | namelabelhint?required?kind?placeholder?value? |
textarea | Several lines of text.Inside form. | namelabelhint?required?placeholder?value?rows? |
select | One choice from a dropdown. For more than five options.Inside form. | namelabelhint?required?optionsvalue?placeholder? |
choice | One choice from a few visible options.Inside form. | namelabelhint?required?optionsvalue?layout? |
checkbox | A yes or no the reader ticks.Inside form. | namelabelhint?checked? |
switch | A setting that is on or off.Inside form. | namelabelhint?checked? |
slider | A number picked on a scale.Inside form. | namelabelhint?required?min?max?step?value?unit? |
date | A date, or a range of dates.Inside form. | namelabelhint?required?value?min?max?range? |
To give the model fewer components:
Buttons, suggestions and forms
Components never do anything themselves. A button with an action, a picked suggestion and a sent form fire pm-action on the element, and your code decides. The event's detail:
| Field | Holds |
|---|---|
action | The name of the action, one of those you declared in uiPrompt({ actions }). A suggestion reports reply. |
params | Data the model attached to the button or form. |
values | A form's values by field name: text as strings, sliders and ratings as numbers, checkboxes and switches as true or false. |
label | The text of the button or suggestion. |
text | A sentence to send to the model as the next user message. |
A form checks its required fields before it reports, and is locked once it was sent (call event.preventDefault() to keep it open). Treat action, params and values like any input from outside: the model chose them, so check them on your server before acting.
While it streams
- Set
streamingwhile text arrives, and assignvalue(or callwrite(chunk)) as often as you like. Only the block that changed is drawn again: a finished chart does not flicker while the next paragraph is written. - Containers and text appear as they arrive. A chart, a table or a stat appears once all of it is there, so readers never see half a table.
- Unfinished Markdown is read as what it will become: an open code fence is a code block,
**bolis bold. - The element sets
aria-busywhile it streams. Put it in apm-chat-messagefor the announcement of a finished answer.
Safety
An answer is untrusted input: the model can be wrong, and text it read (a web page, a document, an email) can try to steer it.
- No HTML, ever. The answer is parsed into data and drawn with
createElementand text nodes.<script>or<img onerror>in an answer shows as text. - Only the catalogue. Unknown components and props are left out; values are checked against their kind. There is no way to set a style, a class, an event handler or an arbitrary attribute.
- Addresses are checked. Links may be http(s), mailto, tel or paths of your site; pictures http(s) or inline PNG, JPEG, GIF and WebP. Never
javascript:ordata:documents. Links to other sites open in a new tab without access to yours. - Pictures can leak. The address of a picture is requested as soon as it is drawn, and can carry text from the conversation to another server. Set
images="off", or allow only your own hosts withallowUrl, when the model reads content you do not control. - Limits. At most 400 components and 12 levels of nesting in one block.
- Actions are yours. Nothing is sent or changed until your
pm-actionhandler does it.
Frameworks
The element has a wrapper in every framework package, like every other component:
The elements an answer uses are loaded the first time an answer needs them, so the chat costs what its answers show.
On a server, @prismora/elements/ai has no DOM: the prompt, the schema and the check run in Node, Bun,
Deno and edge runtimes.
As a tool instead of a block
Where you prefer tool use (or structured output) to a fenced block, uiTool() is a tool named show_ui whose input is { ui: [...] }. Give that input to the element's ui property; it is drawn after value.
The fenced block is the default because it works with every model, streams with the text, and keeps text and components in the order the model wrote them.
API
From @prismora/elements/ai | Does |
|---|---|
uiPrompt({ actions?, types? }) | The instructions for the model. |
uiSchema(options), uiTool(options) | JSON Schema of the components, and the show_ui tool that carries it. |
checkUi(value, limits?) | Cleans what a model wrote: { nodes, problems }. |
renderMarkdown(text, options?), renderUi(ui, options?) | Draw without the element; return a fragment. |
watchActions(root, report) | Reports the actions used inside what you drew. |
parseMarkdown, parsePartial, safeUrl | The parts, for your own renderer. |
UI_CATALOG, UI_TYPES | The components and their props, as data. |
The element's attributes, properties and event are on the component page. For an assistant that writes your code with Prismora, see AI, MCP & CLI.
Other formats
Typed components for model output are becoming a shared idea: Google's A2UI defines a protocol of messages between an agent and a client with a component catalogue, and Vercel's json-render renders a model's JSON through a catalogue of your own components. Prismora's format is deliberately small: Markdown with JSON blocks and a fixed catalogue, which any chat model can write without an agent framework. It is not compatible with those protocols today; an adapter that draws A2UI messages with Prismora elements is on the roadmap.