Dashboards API
engine.workspaces and engine.dashboards store, open, refresh and generate dashboards, for applications that embed the engine (Dashboards). A conversation builds and edits a draft with the dashboard_edit and dashboard_pin chat tools.
Key Modules
packages/nl2sql/src/nl2sql/api/workspaces_api.py(WorkspacesAPI, internal)packages/nl2sql/src/nl2sql/api/dashboards_api.py(DashboardsAPI, internal)packages/nl2sql/src/nl2sql/dashboards/models.py(Workspace,Dashboard,Tile,DashboardEdit)packages/nl2sql/src/nl2sql/dashboards/workspaces.py,api.py,edits.py,store.py,run.py(running the charts),schedule.py, and for the starter dashboardroles.py,templates.pyandlayout.py(the logic behind the two faces)
Public Surface
Every method takes user_context keyword-only and required, except run_scheduled, which runs each
dashboard as its stored owner. Another owner's workspace or dashboard is WorkspaceNotFound or
DashboardNotFound. A missing caller (user_context=None) is a TypeError, not an anonymous owner.
Behaviour
- Private. A workspace and its dashboards belong to the
(tenant_id, user_id)that made them; anyone else's isWorkspaceNotFoundorDashboardNotFound, never "forbidden". - Workspaces.
createandrenamerefuse an empty name and a name the owner already uses (ignoring case).deleteraisesWorkspaceNotEmptywhile a dashboard, draft or saved, is in it. They are listed oldest first. listreturns onestatus(savedby default, ordraft) and, withworkspace_id, one workspace, newest first.refreshed_atis the oldest stored result of its charts (None until a refresh stores some).pinsaves a draft whole, inworkspace_id, else the workspace the draft is in, else "General" (made on first use). There is no way to pin one chart. An empty draft, a dashboard already saved, or a blanktitleis aValueError.create_draft(title=None, workspace_id=None, conversation_id=None)makes an empty draft owned by the caller (title "New dashboard"; inworkspace_id, else "General", made on first use) and publishesdashboard.changed(created). Thedashboard_editchat tool calls it on first use, with the conversation's id, which is stored asDashboard.conversation_id; aconversation_idthat is not the caller's isConversationNotFound. The tool also makes a new draft when the conversation's dashboard has been deleted.edit(dashboard_id, edits, conversation=None)applies a list of edits in order, each seeing the ones before, all or none. The named methods (rename,rename_tile,set_tile_chart,remove_tile,arrange,set_filters,set_schedule,move) each build one edit. None calls a model, and none takes a question or a plan: what data a chart shows changes only through a conversation step (add_tile,replace_plan) or by naming a reviewed query or the caller's own saved answer by id (add_verified_tile,add_saved_tile; a verified id thatcurated.listdoes not show the caller is "no verified query").add_tileandreplace_planread anaskstep of theconversationpassed (it must be the caller's, elseValueError; the chat tool passes the one it runs in) and are aValueErrorwithout one. The step's whole decomposition and each sub-query's plan, or the verified query that answered, become the chart's plan; it is first checked by a run that executes nothing, as the caller and under the dashboard's lock, and a plan the validator rejects or the caller may not read raises aValueErrorthat ends with "Nothing was saved." An unknown chart id is aValueError.from_step.turndefaults to the conversation's latest turn.conversationis trusted: its steps are not re-read from the store, only its owner is checked against the caller, so it is for SDK code holding the caller's ownConversationand is not exposed over REST or MCP; the plan's access check still runs as the caller. The lock lasts as long as the edit's checks (one time limit peradd_tileorreplace_plan). Two more edits add a chart without a conversation step and call no model:add_verified_tile(datasource_id,verified_id,title,params,question) from a verified query of the curated section (an unknown id or parameter, or a missing parameter without a default, isInvalidArgument), andadd_saved_tile(saved_id,title) from the caller's own saved answer (another user's isAnswerNotFound); the saved plan is copied, so later changes to the answer do not touch the chart. Both get the same access check asadd_tile, and the chat tooldashboard_editaccepts them.set_tile_chartwith a kind the chart's last result cannot be drawn as raises aValueErrornaming the kinds it can be, judged from the column kinds stored with that result (so a result last drawn as a table can still be drawn as a bar). With no stored result any kind is accepted.set_schedule(every_minutes)belowdashboards.min_refresh_minutesisScheduleTooFrequent; otherwise it stores the schedule with the caller'suser_id,tenant_idand roles, andNoneremoves it. It runs only while a long-running process callsrun_scheduled(nl2sql-apidoes, every minute).- Stored results.
remove_tilediscards that chart's stored result andset_filters(when the filters change) every chart's; renaming, redrawing, arranging, moving and scheduling keep them. open(dashboard_id, refresh_due=True)checks access first: each stored plan is checked under the caller's current roles, running no query (a generated plan is validated and generated; a verified query is checked by the curated matcher). It returnsDashboardView(dashboard, runs, refreshed_at, due).runsholds the stored result of each chart thisopenchecked: as stored when the check endedok,empty, orneeds_approvalwith no other error; otherwise the check's result (denied,needs_fixing,error, ...) without rows. A denial wins: a chart with one query refused, or one a hook dropped, isdenied. A result another process stored after the check is not served; the chart stays indue. Withrefresh_due, the charts with no result or one older than the schedule are then refreshed (trigger="open", as the caller, never approving);duelists the ids still due (an app that passedFalse, a chart waiting for approval, or a dashboard another process is refreshing).refresh(dashboard_id, tile_id=None, approvals=())runs the stored plans of one chart or all, in layout order, as the caller, and stores each result (TileRun:at,status, the chart with its rows, thecolumn_kinds, the plain-Englishexplanation, theerror). Statuses:ok,empty,needs_fixing(a plan that no longer validates or parses; the refiner is never asked),denied,needs_approval(its requests inapprovals_needed; the stored result is kept),stopped(a cap; the remaining charts arestoppedand keep theirs) anderror(returned, not stored: the chart keeps its last good result). It raisesDashboardBusy(aValueError) while the dashboard is being refreshed or edited,ApprovalNotFoundfor a request id inapprovalsthat is unknown, waiting, denied or expired (nothing runs), andValueErrorfor atile_idthe dashboard does not have.filtersmaps filter ids to values:refresh(dashboard_id, filters={"country": ["Brazil"]}). Each value is checked against the filter's kind first (number,temporalasYYYY-MM-DDorYYYY-MM-DDTHH:MM[:SS[.ffffff]]with an optionalZor+HH:MM,boolean,text;intakes 1 to 100 values,betweenexactly two), and a wrong one, or an id the dashboard does not have, is aValueErrornaming the filter, raised before any chart runs. The predicate (betweenas>=and<=, with a date-only upper bound as<the next day;inasORs; the values as plan literals) is added to each stored query that reads the filter's table (schema and name; a plan table with no schema never matches) before the plan goes torun_query; other queries run unfiltered.TileRun.filteredis true when every query of the chart got a filter and every active filter reached the chart,DashboardRun.filtersholds the values anddashboard.refreshedthe ids. A filtered refresh is returned, not stored, and takes no refresh lock (an unfiltered one does).filter_values(dashboard_id, filter_id, *, user_context, limit=100)returns the distinct values of aninfilter's column (at mostlimit, 1 to 1,000, in order) or[min, max]of abetweenone ([]when there are none), by a plan built in code and run as the caller throughrun_query, so the caller's scope and policies apply and no model is called. A column the caller cannot read, or an unknown filter, is aValueError.run_scheduled(now=None)has no caller: it refreshes each dashboard whose schedule is due, as its saved identity, and returns theDashboardRuns (trigger="schedule"). A schedule that fails a check stops, withstate="stopped"anderror={"code", "message"}onDashboard.schedule, anddashboard.schedule_stopped. The codes areSCHEDULE_IDENTITY_EXPIRED,SCHEDULE_ROLE_REMOVED,SCHEDULE_ACCESS_DENIED(a chart the owner can no longer read) andSCHEDULE_HOOK_DENIED(a hook denied a chart; the message names the chart and the hook's reason). Anowwithout a timezone is aValueError.generate(datasource_id, title=None, workspace_id=None, max_tiles=None, on_tile=None, cancellation_token=None)builds the no-model starter dashboard and returns(Dashboard, DashboardRun)(how it chooses). The roles come from the indexed snapshot and the glossary, only for tables the caller can read; each template chart runs as the caller (trigger="generate"); the charts whose first run isokare kept and the others are inDashboardRun.skipped(title,status,reason). The result is saved, owned by the caller, inworkspace_idor "General". RaisesNotIndexed(namesnl2sql index --datasource <id>),NoTiles(no table the caller reaches, or no chart answered),WorkspaceNotFound, andValueErrorformax_tilesbelow 1.on_tileis called with aTileProgress(title,status,done,total) after each chart ran. Cancellingcancellation_tokenstops before the next chart and raisesnl2sql.RunCancelled; the dashboard is not saved, no tile result is stored, and no draft or workspace this call made is left (a chart that already ran keeps its query trace, as any question does).suggest_questions(datasource_id, n=5)returns the questions of the firstnchartsgeneratewould choose and runs and saves nothing ([]when the caller reaches no table;NotIndexedas above).- A verified chart keeps its datasource in
ChartPlan.verified_datasource_id, required withverified. - Events.
dashboard.changed(the edit kinds,created,pinnedordeleted, andby),dashboard.schedule_set,dashboard.generated,dashboard.refreshed(the counts per status and the filter ids applied),dashboard.schedule_stoppedandworkspace.changed. They carry no titles, names or values. - Retention.
engine.storage.purge()deletes drafts last edited more thanconversations.max_age_daysago; saved dashboards are never purged.
Guided builder
engine.dashboards.builder_options, propose_tiles and build build a dashboard from choices, not from a
description. All take user_context, and the ids
they offer are limited to what the caller's scope reaches.
builder_options(datasource_id, *, user_context) -> BuilderOptionsreturnscurated(the datasource's verified queries with no required parameter,VerifiedQueryInfo),saved(the caller's own saved answers),metrics(glossary terms whose columns the caller may read; a term with any hidden column is left out whole),dimensionsandtime_columns(from the column roles) andranges(last_7_days,last_30_days,last_90_days,last_12_months,this_year). It calls no model.propose_tiles(datasource_id, *, user_context, sources, curated_ids=(), saved_ids=(), metrics=(), dimensions=(), time_range=None, text=None, llm_override=None) -> list[TileProposal]reads and writes nothing.sourcesis any ofcurated,saved,asked. Curated and saved proposals use no model.askedmakes one model call for at most 3 new questions (from the chosen metrics and dimensions, the time range and the freetext). The list is capped atdashboards.max_tiles. Without a key,askedraisesMissingProviderKey; curated and saved still work.llm_overrideis the caller's own key, as forask.build(datasource_id, tiles, *, user_context, title=None, workspace_id=None, time_column=None, on_tile=None, cancellation_token=None, llm_override=None) -> BuildReporttakes the tickedTileProposals (more thanmax_tilesisInvalidArgument) and makes a draft: curated and saved tiles through the two edits above, asked tiles asasksteps of one builder conversation joined throughadd_tile(that conversation is deleted afterwards). A question that cannot be answered is reported inBuildReport.skipped(question,code,message) and the rest are kept; nothing built raisesNoTiles; a cancel or failure leaves nothing behind. Withtime_columnabetweenfilter on it is added. It then pins the draft, publishesdashboard.generatedand returnsBuildReport(dashboard, built, skipped). It does not run the tiles; opening refreshes them.on_tilereceives aTileProgressper tile.engine.curated.list(*, user_context, datasource_id=None) -> list[VerifiedQueryInfo]lists the verified queries the caller's scope reaches, with their parameters.
Methods
| Method |
|---|
workspaces.create(name, *, user_context), rename(workspace_id, name, *, user_context), list(*, user_context), delete(workspace_id, *, user_context) |
dashboards.get(dashboard_id, *, user_context), list(*, user_context, workspace_id=None, status="saved"), delete(...) |
dashboards.pin(dashboard_id, *, user_context, workspace_id=None, title=None), move(dashboard_id, workspace_id, *, user_context) |
dashboards.edit(dashboard_id, edits, *, user_context) and the named edits rename, rename_tile, set_tile_chart, remove_tile, arrange, set_filters, set_schedule |
dashboards.open(dashboard_id, *, user_context, refresh_due=True) -> DashboardView |
dashboards.refresh(dashboard_id, *, user_context, tile_id=None, filters=None, approvals=()) -> DashboardRun (approvals are Approval objects or granted request ids) |
dashboards.filter_values(dashboard_id, filter_id, *, user_context, limit=100) -> list |
dashboards.run_scheduled(*, now=None) -> list[DashboardRun] |
dashboards.generate(datasource_id, *, user_context, title=None, workspace_id=None, max_tiles=None, on_tile=None, cancellation_token=None) |
dashboards.suggest_questions(datasource_id, *, user_context, n=5) -> list[str] |
dashboards.builder_options(...), propose_tiles(...), build(...); edits add_verified_tile, add_saved_tile; curated.list(...) |