Generative AI¶
Language models are good at writing HTML. BI Components turn that into dashboards: the model writes a short page made of a dozen tags, and your application displays it in the sandbox, on real data, with the rights of the person looking at it.
The playground is a chat with recorded conversations. For each answer you can see the dashboard, the HTML behind it and the system prompt. It is not connected to a model, but everything after the model is real: the sandbox, the validation, the queries.
How it fits together¶
- Your chat sends the conversation to a model, with a system prompt that describes the components and your data dictionary.
- The model answers with HTML. Your application gives it to
embedDashboard, which shows it in a sandboxed frame. - The components ask for data. Your page checks the shape of every query, and your server refuses the names it does not know, applies the viewer's rights and answers.
- A refused query shows its reason in the component. Send that text back to the model: the next version is fixed.
Steps 2 and 3 are what this project provides, and they are the sandbox setup, unchanged: it does not depend on who wrote the HTML. Steps 1 and 4 are a few lines around the model of your choice.
Why this format suits a model¶
Letting a model write what your users will run is first a security question. That is where most of the work went:
- What it writes is contained. Generated HTML and JavaScript run in a sandboxed frame that can reach no server. They cannot read your page, its cookies or its tokens, and cannot send data anywhere.
- Every request is checked. The frame can only ask your application for data. Your application validates each request, and refuses anything you did not allow.
- The viewer's rights apply, whoever wrote the page. Row-level security is added by your application for the person looking at the dashboard. A dashboard shared by someone else never shows more than its viewer may see.
- Mistakes are visible, not dangerous. A refused request shows its reason in the component, which is also what you feed back to the model.
The format itself helps too:
- Small and declarative.
<bar-chart measure="revenue" by="country">is the whole chart. There is no code to get wrong, no library version, no build. - Custom code is possible, and contained. When no component fits, the model can write a script with ECharts and the same data access as the components. It runs in the same sandbox.
- Iteration is cheap. "Compare with last year" changes one attribute. The whole page is small enough to be rewritten at each turn.
The system prompt¶
This is the prompt used by the playground. The two placeholders at the end are filled with your own measures and dimensions.
You build dashboards for a retail company. The person you talk to cannot code.
Answer with one or two plain sentences, then ONE block of HTML. No explanation of the code.
## What you write
An HTML fragment (no <html>, <head> or <body>). It is displayed in a sandboxed frame that already
provides the components below, Tailwind CSS 4 and daisyUI 5.
- Never reference external scripts, styles, images or fonts: the frame cannot load them.
- Never write CSS. Use the classes of Tailwind (layout, spacing, text) and of daisyUI (card, stats,
tabs, badge, alert, collapse, progress, table...).
- Colors: daisyUI names only (bg-base-100, border-base-300, text-base-content/70, text-primary,
badge-success...). They follow the light and dark themes; a fixed color does not.
- What you write at the top level is stacked with a gap. Start with one <h1 class="text-2xl font-semibold">.
- Filters go in <div class="flex flex-wrap items-center gap-3">.
- Key figures and charts go in grids ("grid gap-4 sm:grid-cols-3", "grid gap-4 md:grid-cols-2") of cards:
<div class="card card-border bg-base-100"><div class="card-body">
<h2 class="card-title text-base">Title</h2> ...
</div></div>
- Use ONLY the measures and dimensions of the data dictionary. Any other name is refused.
## Components
Key figure <score-card measure="M" compare="yoy"></score-card>
Trend over time <line-chart measure="M" granularity="month" compare="yoy"></line-chart>
Comparison <bar-chart measure="M" by="D" breakdown-by="D2" stacked horizontal sort-by="M" limit="10"></bar-chart>
Share <pie-chart measure="M" by="D"></pie-chart>
Table <data-table by="D" measures="M1,M2,M3" sort-by="M1" limit="20"></data-table>
Period <date-range-filter presets="all,30d,90d,365d,ytd"></date-range-filter>
Filter on a dimension <ui-filter dimension="D" type="select" label="..."></ui-filter> (type: select | segmented)
Business switch <ui-filter option="exclude_discounts" type="toggle" label="..."></ui-filter>
- One measure per chart; a table can show several.
- granularity: day | week | month | quarter | year. compare: yoy | mom | prev_period.
- Optional on charts: height="300px", title="...".
- Clicking a bar, a point or a table row filters the other components. You have nothing to code for that.
## Custom charts
Only when no component fits. Write a <script type="module"> using the two globals of the frame:
const chart = window.echarts.init(element, 'app'); // 'app' is the theme of the page
const { rows, meta } = await window.dashboard.query({ metrics: ['M1', 'M2'], dimensions: ['D'] });
window.dashboard.subscribe(render); // filters, period or theme changed
window.dashboard.filters.toggle('D', value); // filter the rest of the page
meta.labels and meta.formats describe each measure (formats: eur, pct, int).
## Data dictionary
Measures:
{{metrics}}
Dimensions:
{{dimensions}}
Things that work well in practice:
- Give labels and units with each measure (
avg_order_value: Average order value (eur)), so the model picks the right one from a business question. - Give the frame a CSS framework, and forbid CSS. The playground gives every dashboard daisyUI and Tailwind, which models already know: the prompt names them and a few patterns (a card, a grid), and the model writes class names only. To make generated pages look like your product instead, give the frame your own stylesheet and describe its classes.
- Feed errors back. When a component shows "Unknown metrics: profit_margin", send that text to the model: it corrects the page in one turn. The playground has a recorded example of this.
- Keep one measure per chart. It is a rule of the components, and it keeps generated charts readable.
Connect a model¶
The loop to write is small:
- Ask. Send the conversation and the system prompt, with your dictionary filled in, to the model.
- Extract. Take the HTML block of its answer.
- Show. Give it to the dashboard you embedded:
dashboard.load(html). - Correct. When a component reports an error (
onRuntimeErrorfor a script, the text of a refused query from yourresolveQuery), send it back as the next message.
Nothing else changes when the author is a model: the sandbox, the validation and your engine are those of the sandbox setup. Store the HTML of a dashboard, a few kilobytes, to show it again later or to another person; it will run with their rights.
A semantic layer, or SQL expressions¶
Both work, with the same components and the same sandbox. You choose what the model is allowed to ask for:
| The model writes | Your application checks | Choose it when | |
|---|---|---|---|
| Named measures | Names of your dictionary: measure="revenue" by="country" |
That each name exists; it then computes the measure its own way | You have governed definitions (a semantic layer, dbt metrics, SQL views) and want one definition of each figure |
| SQL expressions | Expressions on tables you expose: table="orders" measure="sum(revenue)" by="country" |
The Host refuses statements, sub-queries and unsafe functions; you say which tables and columns exist | You want the model to explore tables freely, without defining measures first |
In both cases the model never sends a full SQL statement: it sends a description of a chart, and your application builds the query. The playground uses named measures; the direct queries example shows the other way, with the SQL that was run. In code: Named measures, or SQL expressions.
What a generated dashboard can and cannot do¶
A dashboard written by a model, or by another user, is untrusted code. It runs with the rights of the viewer, not of its author.
| It can | It cannot |
|---|---|
| Ask for what your engine allows (measures of the dictionary, or expressions on exposed tables), within the viewer's rights | Send a SQL statement or a sub-query, or get a measure, table or column your engine refuses |
| Display anything inside its frame, including custom charts | Read your page, cookies, storage or tokens |
| Set filters and options | See more rows than the viewer is allowed to |
| Send data to another server |
The details, including what remains your application's responsibility, are in the security model.
Want this on your data?¶
The playground runs on sample data. Setting it up in a company means plugging your measures (a semantic layer, dbt metrics, or plain SQL views) behind the Host, and connecting the model of your choice. Contact me on LinkedIn or open an issue.