Applies to: VaultKit 0.9.0-alpha (control plane and funl runtime)
AQL (Access Query Language) is the JSON format for asking VaultKit for data. A query says which table, columns, filters and aggregates you want; it never contains SQL.
How a query runs:
Only PostgreSQL datasources are supported today.
| Who | Endpoint | Body |
|---|---|---|
People and scripts (vkit request) |
POST /api/v1/orgs/<org>/requests |
{"aql": { … }} — the full format on this page |
| Agents (Python SDK, MCP server) | POST /api/v1/orgs/<org>/intent/requests |
{"request": { … }} — the intent format, a simpler subset |
{
"source_table": "orders",
"columns": ["status"],
"joins": [],
"filters": [{"field": "status", "operator": "neq", "value": "refunded"}],
"aggregates": [{"func": "count", "field": "id", "alias": "orders"}],
"group_by": ["status"],
"having": [],
"order_by": {"column": "status", "direction": "ASC"},
"limit": 100,
"offset": 0
}
| Field | Type | Required | Notes |
|---|---|---|---|
source_table |
string | yes | A dataset in your registry. dataset is accepted as an alias. |
columns |
array of strings | no | Columns, or table.column with joins. Aggregate expressions such as "MAX(amount)" are also allowed. With no columns and no aggregates, every column is selected. |
joins |
array | no | See Joins. |
filters |
array | no | Combined with AND. See Filters. |
aggregates |
array | no | See Aggregates. |
group_by |
array of strings or time buckets | no | See Grouping and Time buckets. |
having |
array | no | Conditions on aggregates. |
order_by |
object | no | One {"column", "direction"}, not a list. |
limit |
integer | no | Default 100, maximum 10,000. |
offset |
integer | no | Default 0. |
Table and column names must be plain identifiers (letters, digits, underscores,
optionally table.column). Quoted or schema-qualified names are rejected. Write them
exactly as the registry has them, case included: firstName, riskScore. Every value
in filters and having, and the limit and offset, is sent as a bound parameter.
Every dataset and field a query names must be in the deployed registry (0.12.0-alpha):
in columns, filters, aggregates, grouping, sorting, having and joins.
422, listing the fields you can use:
“Unknown field brand on payment_methods. Valid fields: id, card_brand, …”.404 {"error": "Dataset not found", "request_id": "…"} on both APIs. So does a
tenant-scoped dataset for an agent with no tenant."joins": [
{"type": "LEFT", "table": "customers", "alias": "c",
"left_field": "orders.customer_id", "right_field": "c.id"}
]
type: INNER (the default), LEFT, RIGHT or FULL.alias is optional. Once a joined table has one, references written as
customers.email are rewritten to c.email for you.A filter compares one field to a value. Top-level filters are combined with AND.
"filters": [
{"field": "status", "operator": "eq", "value": "failed"},
{"logic": "OR", "conditions": [
{"field": "amount", "operator": "gte", "value": 1000},
{"field": "region", "operator": "in", "value": ["EU", "CA"]}
]}
]
| Operator | Meaning |
|---|---|
eq, neq |
equal, not equal |
gt, gte, lt, lte |
greater or less than (or equal) |
like |
contains: the value is matched as %value% |
in |
one of a non-empty array of values |
is_null, is_not_null |
no value needed |
{"logic": "AND" | "OR", "conditions": [ … ]}, nested as deep as you
need, and is always parenthesised in the SQL.hash-masked fields: the column is hashed before it’s compared.
Fields masked full or partial can be returned masked, but not used to filter,
group or sort."aggregates": [
{"func": "count", "field": "id", "alias": "orders"},
{"func": "sum", "field": "total", "alias": "revenue"}
]
func: COUNT, SUM, AVG, MIN, MAX, in any case.field: a column, table.column, or * (only with COUNT).alias: the output column name, which order_by can use.COUNT is allowed: SUM, AVG, MIN and MAX would
reveal the raw values, so the request is denied.With aggregates, the plain columns are the grouping columns. group_by makes the
grouping explicit. Grouping or sorting by a field masked full or partial is
denied; hash-masked fields are allowed.
A group_by entry is a column name, or a time bucket of a timestamp or date
column. A bucket groups rows by the day, week, month, quarter or year they fall in,
so a trend (“failed payments per quarter”) is one grouped query instead of one query
per period.
{
"source_table": "payments",
"aggregates": [{ "func": "count", "field": "*", "alias": "payments" }],
"filters": [{ "operator": "eq", "field": "status", "value": "failed" }],
"group_by": [{ "field": "created_at", "bucket": "quarter", "alias": "quarter", "timezone": "America/Toronto" }],
"order_by": { "column": "quarter", "direction": "ASC" }
}
Generated SQL (PostgreSQL):
SELECT to_char(date_trunc('quarter', payments.created_at AT TIME ZONE 'America/Toronto'), 'YYYY-MM-DD') AS quarter,
COUNT(*) AS payments
FROM payments
WHERE payments.status = $1
GROUP BY to_char(date_trunc('quarter', payments.created_at AT TIME ZONE 'America/Toronto'), 'YYYY-MM-DD')
ORDER BY quarter ASC
Each row has the first day of its period under the alias, as a YYYY-MM-DD date in
the bucket’s time zone (for example 2024-04-01 for the second quarter of 2024),
and the aggregates. Periods with no rows are not returned.
| Key | Required | Description |
|---|---|---|
field |
yes | A timestamp or date column of the dataset (or of a joined table, qualified). |
bucket |
yes | day, week, month, quarter or year. Weeks start on Monday (ISO 8601). |
alias |
no | The result column’s name. Defaults to <field>_<bucket>, e.g. created_at_quarter. order_by can use it. |
timezone |
no | An IANA time zone such as UTC or America/Toronto. Periods start at midnight in that zone. Defaults to UTC. |
Rules:
aggregates, and can be mixed with plain columns:
"group_by": ["status", {"field": "created_at", "bucket": "month"}].columns (it isn’t grouped).timezone applies only to timestamp with time zone columns. Dates and timestamps
without a time zone are bucketed as stored; UTC is accepted for them and ignored.422 and a message that says which.GROUP BY date_of_birth in the reason).
A hash-masked column can be bucketed; its bucket values are returned hashed.date_trunc and to_char. Other
engines map the same units to their own functions."having": [{"field": "COUNT(id)", "operator": "gt", "value": 5}]
Operators: gt, gte, lt, lte, eq. Conditions are combined with AND.
"order_by": {"column": "revenue", "direction": "DESC"}
One column, an aggregate alias or an aggregate expression. direction is ASC
(the default) or DESC.
The control plane sets a limit of 100 rows when none is given, and refuses more than
10,000, zero, negatives and non-integers. offset defaults to 0.
Policies decide which fields are masked and how; queries don’t ask for it. Masking is applied to the returned values:
| Method | Returns |
|---|---|
full |
***** |
partial |
the first three characters, then **** |
hash |
a SHA-256 hex digest |
Aggregates over masked fields are masked too, except COUNT. See the
Policy Guide for how masking policies combine.
For a dataset marked with tenant_column, the control plane adds
<table>.<tenant_column> = <your tenant> to every query that reads it, ANDed with
your filters, for the source table and every joined table. A requester without a
tenant can’t read it: an agent gets “Dataset not found” (0.12.0-alpha), a person a
403 that says why. See Tenant-scoped datasets.
The query at the top of this page, minus the filter, becomes:
SELECT "public"."orders"."status" AS "status", COUNT("id") AS "orders"
FROM "public"."orders"
GROUP BY "status"
ORDER BY "status" ASC
LIMIT $1
Tables are qualified with their schema, and each column gets an alias. Every name is
quoted (0.12.0-alpha), so mixed-case columns keep their case and reserved words such
as order or user work. Results are keyed by the names you asked for, case
included. When two selected columns share a name, they come back as
<table>_<column>.
The database’s errors are reported clearly (0.12.0-alpha), with a code and the
correlation_id, and never with SQL, parameter values or connection details:
| Problem | Response |
|---|---|
A column or table the database doesn’t have (undefined_column, undefined_table) |
422: “Column x doesn’t exist on dataset”, asking for a rescan |
A value of the wrong type, or an incompatible comparison (type_mismatch) |
422, for example “A filter value isn’t a valid bigint.” |
The datasource’s login can’t read the data (permission_denied) |
403 |
The datasource is busy (datasource_busy) |
503 with Retry-After |
The query ran past the timeout (query_timeout) |
504 |
| Anything else | 502 “Query engine error” |
The failed run is recorded on the request. Admins see its SQL, with placeholders and no parameters, on the Activity page.
Agents send a simpler request through the intent API, which the Python SDK and MCP server use:
{
"request": {
"dataset": "orders",
"fields": ["status"],
"aggregates": [{"func": "sum", "field": "total", "alias": "revenue"}],
"group_by": ["status"],
"filters": [{"field": "created_at", "operator": "gte", "value": "2026-10-01"}],
"order_by": {"column": "revenue", "direction": "DESC"},
"limit": 50,
"purpose": "Weekly revenue summary for the finance channel"
}
}
Differences from full AQL:
offset is always 0.= or > shorthands). logic must be
AND or OR, groups can’t be empty, and nesting is limited to 5 levels.fields can’t contain *, and a request needs fields or aggregates;vaultkit_describe (or
GET /aql/datasets/:name/schema) to list them.group_by, every selected field must be in it;having needs aggregates, a numeric value, and an aggregate expression as its
field.purpose is recorded with the request and shown to approvers. Rewording it
doesn’t trigger a new approval.{
"source_table": "orders",
"columns": ["orders.id", "orders.total", "c.region"],
"joins": [{"type": "INNER", "table": "customers", "alias": "c",
"left_field": "orders.customer_id", "right_field": "c.id"}],
"filters": [{"field": "orders.status", "operator": "eq", "value": "completed"}],
"order_by": {"column": "orders.total", "direction": "DESC"},
"limit": 20
}