Skip to content

Generate Sql

POST
/api/v1/generate

Generate SQL from natural language, with optional execution.

Supports SELECT, DML, and DDL generation. Agent callers are subject to guardrail levels that restrict which statement types are allowed. If execute=true, runs the generated SQL and returns results.

GenerateSqlRequest
object
connection_id
required
Connection Id

UUID of the registered database connection.

string
prompt
required
Prompt

Natural language description of the SQL to generate.

string
>= 1 characters
execute
Execute

If true, execute the generated SQL after generation.

boolean
caller
CallerType

Who is generating: ‘human’ (no guardrails) or ‘agent’ (guardrails apply).

string
default: human
Allowed values: human agent
guardrail
AgentGuardrail

Agent guardrail level. Only applies when caller=‘agent’.

string
default: strict
Allowed values: strict moderate permissive

Successful Response

GenerateSqlResponse
object
success
required
Success
boolean
data
Any of:
GenerateSqlData
object
sql
required
Sql

The generated SQL statement.

string
explanation
required
Explanation

Explanation of what the SQL does.

string
sql_type
required
Sql Type

Type of SQL: select, dml, or ddl.

string
executed
required
Executed

Whether the SQL was executed.

boolean
execution_result
Any of:
ExecuteSqlData
object
columns
required
Columns

Column names from the result set.

Array<string>
rows
required
Rows

Result rows as arrays of values.

Array<Array>
row_count
required
Row Count

Number of rows returned.

integer
truncated
required
Truncated

True if results were capped by row_limit.

boolean
affected_rows
Any of:
integer
execution_error
Any of:
string
error
Any of:
ExecuteSqlError
object
code
required
Code

Error code (e.g., GUARDRAIL_VIOLATION, SQL_ERROR, TIMEOUT).

string
message
required
Message

Human-readable error message.

string

Validation Error

HTTPValidationError
object
detail
Detail
Array<object>
ValidationError
object
loc
required
Location
Array
msg
required
Message
string
type
required
Error Type
string
input
Input
ctx
Context
object