On this page
SQL-to-artifact workflow for agents
Prefer a structured specification over assembling executable JavaScript or raw HTML. Miniplot does not invoke an LLM. These APIs let an existing agent create, inspect, reproduce and export artifacts through SQL.
-
Discover the installed API. The installed binary is authoritative, especially when using an older community build:
SELECT function_name, parameters, parameter_types, description, examples, has_side_effects FROM duckdb_functions() WHERE function_name IN ('chart_report_html', 'chart_report', 'chart_export', 'scatter_gl_chart_html', 'heatmap_chart_html'); -
Build JSON from DuckDB structs with
to_json. Validate against report.schema.json when producing a report specification. Report fields are plain strings and Plotly trace/layout/config JSON. Raw HTML and Markdown are not interpreted. Invalid SQL inputs produce errors;TRY(chart_report_html(spec))can recover per row. -
Use pure
*_htmlfunctions while iterating. They do not create files or open a browser. Query the function catalog for runnable examples rather than infer signatures from another plotting library. -
Save explicitly with
chart_report(spec, 'report.html')or a chart's optional output path. For native PNG/PDF artifacts, install the optional local exporter and callchart_export(chart_report_html(spec), 'report.pdf'). -
Preserve the specification. Generated reports contain its exact JSON values in
script#miniplot-report[type="application/json"]. Parse that text as JSON; never evaluate it. This retains provenance fields supplied in the specification as well as chart data, without inferring values from pixels.
For large datasets, filter/aggregate in SQL or choose scatter_gl_chart_html.
No API silently samples data. Reports retain both their specification and plotting
instructions, increasing HTML size relative to a standalone chart.
Native export uses a separate Node/Chromium process, with local Plotly resources and network requests blocked. It waits for chart promises/fonts and writes the destination only after successful rendering. Browser startup occurs for every export call. File/browser/export functions are volatile and honor DuckDB's external-access setting; pure HTML generation remains available when disabled.
Primary references used in the design
- DuckDB function catalog:
native discovery through
duckdb_functions(). - Plotly configuration: chart configuration remains Plotly JSON rather than a second incompatible option system.
- Playwright Page API: screenshot/PDF output and page/viewport behavior.
The report contract, embedded specification and SQL export integration are project design choices; the references document the underlying capabilities.