Natural Language to SQL
POST
/v1/ai/{project_id}/nl2sqlConverts natural language into secure, read-only PostgreSQL queries checked by an Abstract Syntax Tree (AST) parser.
#
Request
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
question | string | yes | Natural language question about the project's data. |
dialect | string | no | Database dialect. Accepts 'postgresql' or 'postgres'. |
examples | object[] | no | Optional few-shot examples [{ question, sql }] guiding query generation. |
limit | number | no | Maximum row limit injected if omitted by model (default 100, max 1000). |
#
Security
AST Mutation Guards
Info
The server parses the generated SQL with an Abstract Syntax Tree (AST) engine prior to returning it:
- Any non-SELECT mutation statement (
INSERT,UPDATE,DELETE,DROP,ALTER,TRUNCATE) is rejected immediately withHTTP 400. - System catalog tables (
pg_catalog,information_schema) are strictly disallowed. - If the model omits a
LIMITclause, the server injectsLIMIT 100(capped at 1000) and markslimit_injected: true.
v1.0 · revised Oct 31, 2026