You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Architecture/sql-result-visualization.md
+83Lines changed: 83 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,89 @@ This architecture governs:
65
65
- The supported chart types MUST be constrained to the known allowlist above.
66
66
- The implementation MUST retry up to two times when the model returns malformed JSON or an invalid chart config, and each correction prompt MUST include the latest validation error.
67
67
68
+
## Chart Config Examples
69
+
70
+
Vertical or horizontal bar charts use one category key and one or more numeric series keys:
Pie-like charts use one label key and one numeric value key:
126
+
127
+
```json
128
+
{
129
+
"config": {
130
+
"type": "doughnut",
131
+
"title": "Feature flag states",
132
+
"labelKey": "state",
133
+
"valueKey": "count",
134
+
"data": [
135
+
{ "state": "Enabled", "count": 9 },
136
+
{ "state": "Disabled", "count": 4 }
137
+
]
138
+
}
139
+
}
140
+
```
141
+
142
+
## Renderer Contract
143
+
144
+
-`bar` and `horizontal-bar` render through `BarChart`, `Bar`, `BarXAxis`, and `BarYAxis`.
145
+
-`line` renders through `LineChart`, `Line`, and `XAxis`.
146
+
-`pie` and `doughnut` render through `PieChart` and `PieSlice`.
147
+
- All chart types use the shared Bklit `Grid` and `ChartTooltip` primitives where applicable.
148
+
- Series colors default to Studio chart CSS variables (`--chart-1` through `--chart-5`) unless a validated series color is provided.
149
+
- The renderer MUST ignore arbitrary chart-library options. All display behavior is derived from the validated Studio config and local component composition.
150
+
68
151
## Chart Lifecycle Contract
69
152
70
153
- Chart rendering MUST use the Bklit ShadCN chart primitives checked into `ui/components/charts`.
Copy file name to clipboardExpand all lines: FEATURES.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -228,7 +228,7 @@ If AI-generated SQL fails when the user runs it, Studio sends the original reque
228
228
229
229
When SQL query results are visible and `llm` is configured, Studio can also turn the returned rows into an in-grid Bklit visualization.
230
230
The visualization uses a minimal summary-row trigger labeled `Visualize data with AI`, right-aligned beside the query result count, and mounts the generated chart above the SQL result headers inside the shared scrollable grid without a regenerate control.
231
-
Studio sends the executed SQL, the concrete database engine, and the full result row set to the model, and when the result came from `Generate SQL with AI` it also includes the original natural-language request for extra visualization context. The model is asked for a strict Bklit chart config for bar, horizontalbar, line, pie, doughnut, or stacked bar charts, and Studio validates that schema before rendering.
231
+
Studio sends the executed SQL, the concrete database engine, and the full result row set to the model, and when the result came from `Generate SQL with AI` it also includes the original natural-language request for extra visualization context. The model is asked for a strict Studio-owned Bklit chart config for `bar`, `horizontal-bar`, `line`, `pie`, `doughnut`, or stacked `bar`/`horizontal-bar` charts; arbitrary Chart.js-style options, callbacks, plugins, and non-primitive row values are rejected before rendering.
232
232
Mounted charts sit inside an in-grid background band that stays tied to the visible result viewport instead of the total table width, while the chart itself stays centered and width-clamped between 300px and 1200px so wide result grids do not force giant charts.
233
233
When SQL is generated through AI, the same model call also decides whether the expected result is graph-worthy; if it says yes, Studio auto-generates the chart after the user manually runs that generated SQL instead of waiting for a separate chart button click.
234
234
If another query starts running, the visualization resets immediately so stale charts do not persist across changing result sets. Visualization generation also retries up to two times on malformed JSON, invalid chart configs, or explicit provider output-limit failures.
Copy file name to clipboardExpand all lines: README.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,6 +138,69 @@ type StudioLlmResponse =
138
138
139
139
Studio treats `output-limit-exceeded` as a first-class retry signal for SQL generation and visualization correction loops. When `sqlLint` is available, Studio validates AI-generated SQL before showing it and feeds lint diagnostics back through the same `sql-generation` transport when correction is needed. If AI-generated SQL still fails after the user manually runs it, Studio sends the failed SQL and database error back through that same transport so the model can propose corrected SQL without auto-running it. All prompting and retry behavior live in Studio itself, so host implementations should stay transport-only.
140
140
141
+
### SQL Result Visualization Charts
142
+
143
+
SQL result visualization uses the shared `llm` hook with `task: "sql-visualization"`. The host does not need to provide chart components, Chart.js options, callbacks, plugins, or chart-specific APIs. Studio builds the prompt from the executed SQL, database engine, full result rows, and the original AI SQL request when available; the host only forwards that prompt to the model and returns the model text.
144
+
145
+
Studio validates the model response as a small Bklit chart config before rendering. The response must be strict JSON in this shape:
Invalid JSON, unsupported chart types, non-primitive row values, missing keys, non-numeric series values, and non-date line x-values are rejected and fed back to the model for correction. The normative implementation details live in [`Architecture/sql-result-visualization.md`](Architecture/sql-result-visualization.md).
203
+
141
204
## Integration Checklist
142
205
143
206
Studio is an embeddable React surface, not a standalone app shell. A production integration should:
0 commit comments