- Combine separate data sources. Join explores that have no dbt join between them, or join a warehouse explore with a live source or an attached CSV.
- Reshape or re-aggregate governed results. Answer questions like “how many orders were above that customer’s own average, by status?”, which compares each order to its customer’s average before regrouping by status. You can also compute a 7-day rolling average of daily signups that counts days with zero signups. A single explore query omits empty days, so DuckDB builds a date spine and joins the governed metric onto it.
- Run statistics and models in Python. Fit a trend line, forecast, regression, or anomaly score over governed query results.


Two semantic-layer explores joined in DuckDB and passed to a four-week Python forecast
Before you start
Multi-step queries are on by default on Lightdash Cloud. On a self-hosted instance, enable thecompose-sql-runner feature flag, configure results storage, and add a Python sandbox if you want Python steps. See Post-processing with DuckDB and Python.
- Lightdash AI agents. Turn multi-step queries on or off per agent in the agent’s settings. The setting is on by default once the feature is enabled, and the agent needs data access that lets it read result rows.
- Lightdash MCP. Multi-step queries are available whenever your role holds
manage:Explore, which Interactive Viewer, Editor, Developer, and Admin roles include. If you pin an agent, that agent must also have multi-step queries turned on. - Warehouse SQL steps. Running raw SQL against your warehouse requires
manage:SqlRunner, which Developer and Admin roles include by default. In Lightdash AI agents, warehouse SQL steps also require SQL mode and query approval. DuckDB and Python steps over semantic-layer results require neither SQL Runner access nor approval.
Why run transformations in Lightdash
Without multi-step queries, complex questions fail in two ways. Either the AI client runs several separate queries and dumps thousands of raw rows into its context window to join by hand, or it falls back to raw warehouse SQL and bypasses your semantic layer. Multi-step queries run the whole workflow on the Lightdash server:- Keep queries on your semantic layer. Agents pull governed metrics from explores first, then apply window functions, rankings, ratios, and cross-explore joins in DuckDB instead of writing raw warehouse SQL. Your dbt metric definitions, joins, and user attributes apply to every source step.
- Keep the context window small. Four explores might produce thousands of intermediate rows while the joined and ranked answer is ten rows. Lightdash runs the intermediate steps on the server and returns only the final result. The model never truncates intermediate rows or does the arithmetic by hand.
- No local tools to install. Non-coding clients such as Claude Desktop, Slack, and the Lightdash app get DuckDB and Python execution over one connection, with no local Python environment, packages, or DuckDB binary to set up.
- One server-side call over MCP. One request to Lightdash MCP runs your semantic-layer queries and DuckDB or Python post-processing together on the server, instead of pulling raw tables into a local script or chat window.
Run multi-step queries over Lightdash MCP
Connect an MCP client, such as Claude Desktop or Cursor, to Lightdash MCP and ask cross-explore or analytical questions in plain language. Your MCP client plans the steps, sends them to Lightdash in a single request, and receives only the final result table instead of every intermediate query’s rows. For full tool arguments and schema details, see Query pipelines in Lightdash MCP.Example MCP pipeline payload
Example MCP pipeline payload
Inspect lineage in AI agents
When a Lightdash AI agent answers with a multi-step query, the result panel opens with a Chart and Lineage toggle in its top-right corner. Switch to Lineage to audit every step:- Dependency graph. Each node shows its title, kind, and row count, and Final result marks the output. Select any node in the graph to jump to its detail card.
- Step cards. Semantic-layer cards show the explore, selected dimensions, metrics, filters, and a toggle between the metric query and compiled SQL, plus Explore from here to open that source in Explore. DuckDB and Python cards show their SQL or code, execution time, and upstream references.
- Intermediate rows. Expand the row-count bar on any step to inspect the exact table that step produced.
- Add to chat. Pin any intermediate step to the message input to ask follow-up questions over it without rebuilding earlier steps.
···) menu, Download results exports the final table as CSV and Export image downloads chart results as an image. Both actions require manage:ExportCsv, which Viewer roles and above include.
How multi-step queries run
Every multi-step query runs in two layers on the Lightdash server:- Sources run first. Semantic-layer queries compile through your semantic layer and run against your warehouse, or match a pre-aggregate or results cache entry. Warehouse SQL runs only when allowed and needed.
- DuckDB and Python transform the results inside Lightdash. Each transformation reads only the results of its upstream steps and never connects to your warehouse. Same-grain explore joins preserve governed field labels and formatting, and apply the same fan-out protection as Merge queries.
- Only the final result returns to the client. Intermediate rows stay on the server.
Run Python inside Lightdash
For forecasts, trend lines, regressions, or statistical calculations that SQL expresses poorly, Lightdash runs Python in an isolated sandbox created for each run and destroyed afterward. The sandbox has no network access, no warehouse credentials, and no runtime package installs. It receives only the upstream query results it transforms, and comes preinstalled withpandas, numpy, scipy, pyarrow, scikit-learn, and polars. You can visualize Python outputs with built-in chart types or a custom chart from Chart Studio.


A four-week Python OLS forecast with a 95% prediction interval over weekly orders and payments, rendered with a custom chart from Chart Studio
Save as a chart
Saving multi-step queries as charts is gated by the
composer-charts feature flag, which is off by default. Contact Lightdash support to enable it on Lightdash Cloud, or add composer-charts to LIGHTDASH_ENABLE_FEATURE_FLAGS on a self-hosted instance.- Save and edit through AI agents or MCP. Open Quick actions (
···) and choose Save in an AI agent thread, or ask an AI agent or MCP client to save or update the chart in a space or dashboard. - Works with the rest of Lightdash. Multi-step charts support content-as-code, project promotion, spaces, dashboards, dashboard filters, parameters, date zoom, and dashboard scheduled deliveries and exports.


Open Quick actions in the result panel to download results or save the multi-step query to a space or dashboard


A saved multi-step chart page showing the rendered chart above its full Lineage graph and step details
Permissions for saving charts
Viewing a multi-step chart or dashboard tile uses the same space and dashboard view permissions as any other chart. Saving or editing one requiresmanage:ComposerChart, which Editor, Developer, and Admin roles include, plus the scope for any step type in the query: