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-ai-generation.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,13 @@ This architecture governs:
62
62
- Successful responses MAY surface the rationale inline to explain what was generated.
63
63
- Successful responses MUST carry the visualization decision forward so the next manual execution of that same AI-generated SQL can auto-generate a chart for graph-worthy results.
64
64
65
+
## Database Error Correction Contract
66
+
67
+
- If the user manually executes SQL that was generated by AI and the database returns an execution error, Studio MUST feed the original natural-language request, the failed SQL, and the database error message back through the same `sql-generation` LLM transport.
68
+
- The correction request MUST preserve the original explicit-execution contract: corrected SQL replaces the editor contents, updates the rationale and visualization decision, and focuses the editor, but Studio MUST NOT auto-run the corrected SQL.
69
+
- Database-error correction MUST only run for editor contents that still match the pending AI-generated SQL. Manually edited SQL errors MUST stay as normal inline query errors and MUST NOT trigger hidden AI calls.
70
+
- If database-error correction fails, Studio MUST keep the database error visible and surface the AI correction failure inline without discarding the user's current SQL.
71
+
65
72
## Embedder and Demo Contract
66
73
67
74
- Embedders own the actual provider call through one shared `llm({ task, prompt })` hook.
@@ -81,3 +88,5 @@ Changes to AI SQL generation MUST include tests covering:
81
88
- preserving the visualization decision until the user manually runs the generated SQL
82
89
- surfacing the visualization decision from the AI response
83
90
- inline error rendering for failed AI generation
91
+
- feeding execution errors from AI-generated SQL back into the model without auto-running the corrected SQL
92
+
- leaving manually written SQL execution errors as normal inline query errors without invoking AI correction
Copy file name to clipboardExpand all lines: Architecture/sql-result-visualization.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,8 +57,10 @@ This architecture governs:
57
57
-`title`: optional short display title
58
58
-`data`: plain JSON objects with primitive field values only
59
59
-`xKey` plus `series[]` for `bar` and `line` charts
60
+
- optional `stacked: true` for `bar` charts only
60
61
-`labelKey` plus `valueKey` for `pie` and `doughnut` charts
61
62
-`line` charts MUST use date-like `xKey` values: ISO dates, ISO datetimes, or epoch milliseconds. Generic categorical data should use `bar`.
63
+
- Stacked bar charts MUST use one data row per category and separate numeric series fields for each stack segment. Long/tidy SQL result rows MAY be pivoted by the AI visualization response into this Studio-owned chart config.
62
64
- The supported chart types MUST be constrained to the known allowlist above.
63
65
- 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.
64
66
@@ -78,3 +80,4 @@ Changes to SQL result visualization MUST include tests covering:
78
80
- automatic chart generation for AI-generated SQL results that request visualization
79
81
- replacement of the action with a mounted chart
80
82
- reset behavior when another query execution starts
83
+
- validation and rendering support for stacked bar chart configs
Copy file name to clipboardExpand all lines: FEATURES.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -221,12 +221,13 @@ The prompt context is built from live introspection metadata, including the conc
221
221
AI responses must satisfy a strict JSON contract with generated SQL, a short rationale, and a yes/no visualization decision, and Studio retries once if the model returns malformed JSON.
222
222
Submitted AI requests are also stored locally in the SQL-view TanStack collection, so an empty focused prompt field can browse older requests with `ArrowUp` / `ArrowDown` as placeholder-only previews before committing one back into the input for editing.
223
223
Provider output-limit failures are surfaced explicitly and can feed into the next JSON-correction prompt instead of showing up as a vague parse failure. The visualization decision from AI generation is also preserved so the later manual run can still auto-chart graph-worthy results.
224
+
If AI-generated SQL fails when the user runs it, Studio sends the original request, failed SQL, and database error back to the model, then replaces the editor with a corrected query without auto-running it.
224
225
225
226
## AI SQL Result Visualization
226
227
227
228
When SQL query results are visible and `llm` is configured, Studio can also turn the returned rows into an in-grid Bklit visualization.
228
229
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.
229
-
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, line, pie, or doughnut charts, and Studio validates that schema before rendering.
230
+
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, line, pie, doughnut, or stacked bar charts, and Studio validates that schema before rendering.
230
231
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.
231
232
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.
232
233
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
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,7 +109,7 @@ export function EmbeddedStudio() {
109
109
-`queryInsights` is optional. Pass it only when your BFF implements the `query-insights` procedure; otherwise omit it so Studio hides the `Queries` view.
110
110
- Studio does not render a built-in fullscreen header button. If your host needs fullscreen behavior, render that control at the host container level, as the local demo does.
111
111
112
-
Studio handles prompt construction, type-aware validation, correction retries, SQL execution retries, and conversion into the normal filter, SQL, and visualization surfaces. The host transport only needs to forward the prepared request to an LLM provider and return the typed result.
112
+
Studio handles prompt construction, type-aware validation, correction retries, database-error correction for AI-generated SQL, and conversion into the normal filter, SQL, and visualization surfaces. The host transport only needs to forward the prepared request to an LLM provider and return the typed result.
113
113
114
114
## AI Contract
115
115
@@ -136,7 +136,7 @@ type StudioLlmResponse =
136
136
};
137
137
```
138
138
139
-
Studio treats `output-limit-exceeded` as a first-class retry signal for SQL generation and visualization correction loops. All prompting and retry behavior live in Studio itself, so host implementations should stay transport-only.
139
+
Studio treats `output-limit-exceeded` as a first-class retry signal for SQL generation and visualization correction loops. If AI-generated SQL fails after the user manually runs it, Studio also sends the failed SQL and database error back through the same `sql-generation` 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.
0 commit comments