Retrieved article excerpt
Open article · Retrieved 2026-10-12T14:28:04.623439+00:00
query generation for agents and apps
# Don't let the model write SQL.
It writes a spec instead: measures, dimensions, filters, in the names your business already
uses. 0sql resolves the spec against your governed model and returns one correct statement for
your warehouse, or a refusal that says exactly why. It never sees a row.
0sql never connects to your warehouse, so your data never leaves your network. The same spec
and model always produce the same statement, with row-level security already compiled in.
That is the security, determinism and reliability your application inherits the day it stops
assembling SQL by hand.
[Try it live](https://0sql.io/try/) [Get an API key](https://app.0sql.io) [Read the quickstart](https://0sql.io/docs/getting-started/quickstart/)
$ curl -fsSL https://0sql.io/install.sh | sh copy [Need the whole stack?Strata is this planner with execution, caching, dashboards,
self-service and AI agents already around it.
strata.do →](https://strata.do)
request
```
curl -s https://app.0sql.io/projects/tpcds/branches/main/sql \
-H "Authorization: Bearer zqk_…" \
-H "Content-Type: application/json" \
-d '{
"spec": {
"projections": [
{"field": "Web Net Paid"},
{"field": "Web Sold Date"},
{"field": "Net Paid"}
]
}
}'
```
shorthand
```
zsql sql --expr "web net paid, web sold date, net paid"
```
request.js
```
const res = await fetch('https://app.0sql.io/projects/tpcds/branches/main/sql', {
method: 'POST',
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
spec: { projections: [{ field: 'Web Net Paid' }, { field: 'Web Sold Date' }, { field: 'Net Paid' }] },
}),
});
const { sql } = await res.json();
```
↓ response `sql`, adapter `postgres`, planned in 70 µs
response.sql
```
WITH ag29130fae5cf6548d6ddb1bd37298b407 AS (
SELECT
sum(T0."ws_net_paid") AS "msr501e4a8",
T0."ws_sold_date_sk" AS "dimed56b67"
FROM
web_sales T0
GROUP BY
T0."ws_sold_date_sk"
), ag7098b0d0901f2eb16d14f9356f0bb2a0 AS (
SELECT
T0."ss_sold_date_sk" AS "dimed56b67",
sum(T0."ss_net_paid") AS "msr621f67c"
FROM
store_sales T0
GROUP BY
T0."ss_sold_date_sk"
)
SELECT
A0.msr501e4a8 AS "Web Net Paid",
COALESCE(A1.dimed56b67, A0.dimed56b67) AS "Web Sold Date",
A1.msr621f67c AS "Net Paid"
FROM
ag29130fae5cf6548d6ddb1bd37298b407 A0
FULL OUTER JOIN ag7098b0d0901f2eb16d14f9356f0bb2a0 A1
ON A1.dimed56b67 = A0.dimed56b67
```
Two measures from two fact tables, one conformed date. Each fact is aggregated at its own grain
and stitched with a full outer join. Nothing double counts, and nobody modeled that query.
In
Business terms
Ask in the names your business already uses, plus who is asking. As JSON, or as one shorthand line.
- measures
- dimensions
- filters
- cohorts
- [Measure]@m formulas
- security context
→
Out
One SQL statement
In your warehouse's dialect, ready to run. Or an error that names exactly what could not be resolved.
- joins
- grain
- aggregation
- row-level security
- masks
- dialect
Never
A connection to your data
0sql holds the shape of your warehouse, never its contents. The statement runs inside your network.
- credentials
- connection
- rows
- results
- cache
example · open source
## Build a custom agentic dashboard using 0sql only for query generation.
This example shows how to use 0sql, the semantic layer as a service, to build a custom
analytics dashboard. The dashboard is a chat. You type a question, an AI agent writes a 0sql
query spec, 0sql returns the SQL, and the app runs that SQL on its own warehouse and draws the
chart. Say “pin that” and the chart becomes a tile on the dashboard.
The app, the semantic model and the warehouse are all open source. The walkthrough builds it
in three steps: deploy the model, give the agent the 0sql tools, wire up the dashboard. Switch
the user in the header and the same question returns different SQL, because row-level
security lives in the model, not in the prompt.
[Read the walkthrough](https://0sql.io/docs/examples/chat-dashboard/) [Clone the repo](https://github.com/stratasite/0sql-dashboard-demo)
[▶ watch the build, step by step · 34 min](https://youtu.be/6stVUI4MUio)
The chat dashboard demo. On the left, the question “Which call centers have the longest average handle time?”, the agent's trace, the bar chart it produced and its written answer. On the right, pinned dashboard tiles: contacts per day, contacts by call center, resolution mix, average handle time by region. The chat dashboard demo. On the left, the question “Which call centers have the longest average handle time?”, the agent's trace, the bar chart it produced and its written answer. On the right, pinned dashboard tiles: contacts per day, contacts by call center, resolution mix, average handle time by region. open full size
The demo app, mid-conversation. Left: the question, the agent's trace, the chart it drew.
Right: the dashboard tiles. Open it full size to read the trace.
one turn, under the hood
> Which call centers have the longest average handle time?
↓ the agent writes a spec, never SQL
spec
```
{
"projections": [
{ "field": "Call Center" },
{ "field": "Average Contact Duration Secs",
"alias": "Average Handle Time Secs", "order_by": "desc" }
]
}
```
↓ 0sql plans it against the deployed model
planned.sql
```
SELECT
T1."call_center_desc" AS "Call Center",
sum(T0."contact_duration_secs") * 1.0 / nullif(count(*), 0) AS "Average Handle Time Secs"
FROM
cs_contact_f T0
LEFT JOIN cs_call_center_d T1
ON T0.call_center_id = T1.call_center_id
GROUP BY
T1."call_center_desc"
ORDER BY
sum(T0."contact_duration_secs") * 1.0 / nullif(count(*), 0) desc
```
The join came from the model and the average is the measure's own formula, because an average
of an average is a bug and that gets settled once, in the YAML, not in every question.
[ø] chat dashboard demo · a custom dashboard built on 0sql close `esc`
The chat dashboard demo. On the left, the question “Which call centers have the longest average handle time?”, the agent's trace, the bar chart it produced and its written answer. On the right, pinned dashboard tiles: contacts per day, contacts by call center, resolution mix, average handle time by region. The chat dashboard demo. On the left, the question “Which call centers have the longest average handle time?”, the agent's trace, the bar chart it produced and its written answer. On the right, pinned dashboard tiles: contacts per day, contacts by call center, resolution mix, average handle time by region.
## Model. Deploy. Request. Run.
Four steps, three of them yours. The semantic model is YAML in git; a branch deploys as a branch.
1. 01
model
### Tables, fields and joins in YAML
Name a measure once. Declare joins with cardinality. The planner derives every reachable combination; you never write a query.
models/sales/tbl.web\_sales.yml
```
name: Web Sales
physical_name: web_sales
datasource: warehouse
cost: 100
fields:
- type: measure
name: Web Net Paid
data_type: decimal
expression:
sql: sum(ws_net_paid)
```
models/sales/rel.sales.yml
```
datasource: warehouse
web_sales_item:
left: Web Sales
right: Item
sql: left.ws_item_sk = right.i_item_sk
cardinality: many_to_one
```
2. 02
deploy
### One command, per git branch
Secrets are stripped before upload. The service validates the model, forms the universes, runs your tests and answers with counts and warnings.
terminal
```
$ zsql deploy
deploy tpcds (6120 bytes) as tpcds/main (the production branch) to https://app.0sql.io
deployed tpcds/main: 6 tables, 41 fields, 7 joins, 11 paths, 1 policies
PASSED category by net paid
tests: 1 passed, 0 failed
```
3. 03
request
### A spec, or one line of shorthand
Decorators for month grains and period-over-period, filters that land in WHERE or HAVING by themselves.
POST /projects/tpcds/branches/main/sql
```
{
"spec": {
"projections": [
{"field": "Date", "decorators": [{"type": "truncate", "grain": "month"}], "order_by": "asc"},
{"field": "Web Net Paid", "decorators": [{"type": "temporalize", "transform": "month_over_month"}]}
],
"filters": [{"field": "Web Net Paid", "predicate": "greater_than", "value": "100"}]
}
}
```
= the same, as shorthand: `zsql sql --expr "month(date) asc, mom(web net paid), web net paid > 100"`
4. 04
run
### In your code, on your warehouse
Top five categories by revenue: a ranking CTE joined back, no window-function guesswork. Hand it to your driver.
response.sql
```
WITH ag5c9bb8d550197b3a219ae50f0b427905 AS (
SELECT
T1."i_category" AS "dim30d09b7",
sum(T0."ws_net_paid") AS "msr0c0d023"
FROM
web_sales T0
JOIN item T1
ON T0.ws_item_sk = T1.i_item_sk
GROUP BY
T1."i_category"
ORDER BY
sum(T0."ws_net_paid") desc
LIMIT 5
)
SELECT
sum(T0."ws_net_paid") AS "Web Net Paid",
T1."i_category" AS "Category"
FROM
web_sales T0
JOIN item T1
ON T0.ws_item_sk = T1.i_item_sk
INNER JOIN ag5c9bb8d550197b3a219ae50f0b427905 AS A2
ON T1."i_category" = A2.dim30d09b7
GROUP BY
T1."i_category"
```
security
## Your data never leaves your network.
0sql holds the shape of your warehouse, never its contents. The statement comes back to you and runs inside your own perimeter.
your network
- your application
- your warehouse and its rows
- your credentials
- every result
spec → ← sql
0sql
- your semantic model
- the planner
- a connection
- a single row
Specs and contexts are planned in memory, never stored or logged. [What is kept.](https://0sql.io/docs/accounts/)
row-level security, compiled into the statement
request
```
{
"spec": {"projections": [{"field": "Country"}]},
"context": {
"email": "[email protected]",
"groups": [
{"name": "CC-TMNT", "tags": ["call_center_id:TMNT"]},
{"name": "CC-AVCL", "tags": ["call_center_id:AVCL"]}
]
}
}
```
↓ the policy in the model fires on the caller's groups
response.sql
```
SELECT
T0."cc_country" AS "Country"
FROM
call_center T0
WHERE
LOWER(T0."cc_call_center_id") IN ('tmnt', 'avcl')
```
The context comes from your auth system with every request. A branch with policies refuses to plan without one.
determinism
## Same spec, same SQL. Byte for byte.
On every deploy and every replica. Join routes and merge order are settled by name, never by row id, so planning is not a coin flip.
Pin a statement in a test. A model edit that would change the SQL your application depends on fails the deploy instead of surprising you in production.
The planner is held to byte-for-byte parity with the engine inside Strata, which has run at Netflix scale for years.
tests/revenue\_by\_category.yml
```
name: revenue by category
projections:
- Category
- Net Paid
assert_sql: |
SELECT
T1."i_category" AS "Category",
sum(T0."ss_net_paid") AS "Net Paid"
FROM
store_sales T0
JOIN item T1
ON T0.ss_item_sk = T1.i_item_sk
GROUP BY
T1."i_category"
```
↓ runs on every deploy
terminal
```
$ zsql deploy
deploy tpcds (6120 bytes) as tpcds/main (the production branch) to https://app.0sql.io
deployed tpcds/main: 6 tables, 41 fields, 7 joins, 11 paths, 1 policies
PASSED category by net paid
tests: 1 passed, 0 failed
```
reliability
## Refusals, not wrong numbers.
A measure asked for by a dimension its fact cannot reach is an error with a class and a message, never a fan-out. A hallucinated field is a 422, not a confident wrong answer.
Misspelled fields resolve by similarity when one clearly leads, and the response says so under `corrections`.
/explain
: The node tree, join routes and microsecond timings behind a statement.
/explore
: What a query can still add and