Skip to content
Aurabase Logo
aurabase

Natural Language to SQL

POST/v1/ai/{project_id}/nl2sql

Converts natural language into secure, read-only PostgreSQL queries checked by an Abstract Syntax Tree (AST) parser.

Parameters#

ParameterTypeRequiredDescription
questionstringyesNatural language question about the project's data.
dialectstringnoDatabase dialect. Accepts 'postgresql' or 'postgres'.
examplesobject[]noOptional few-shot examples [{ question, sql }] guiding query generation.
limitnumbernoMaximum row limit injected if omitted by model (default 100, max 1000).

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 with HTTP 400.
  • System catalog tables (pg_catalog, information_schema) are strictly disallowed.
  • If the model omits a LIMIT clause, the server injects LIMIT 100 (capped at 1000) and marks limit_injected: true.
Last updated · @aurabase/aurabase-js@0.7.5 · aura@0.3.4↗ Report a problem