Skip to content

Generate Query

POST
/api/v1/connections/{connection_id}/queries/generate

Answer a natural language question by generating and executing SQL.

Uses pgvector similarity search to retrieve relevant schema chunks, generates a validated SQL statement via Claude Sonnet (AWS Bedrock), executes it against the customer database, and returns the results formatted as markdown.

The response includes:

  • markdown_output: query results as a markdown table (primary consumer field)
  • The generated SQL and confidence score
  • Schema context used for generation
  • Structured error details when generation or execution fails
connection_id
required
Connection Id
string format: uuid
GenerateQueryRequest
object
query
required
Query

Natural language description of the query to generate.

string
>= 1 characters
max_schema_chunks
Max Schema Chunks

Maximum number of schema chunks to retrieve via vector similarity search.

integer
default: 5 >= 1 <= 20
max_doc_chunks
Max Doc Chunks

Maximum number of document chunks to include as business context.

integer
default: 3 <= 20

Successful Response

GenerateQueryApiResponse

Response envelope for POST /queries/generate.

object
success
required
Success

Whether the request succeeded.

boolean
data
Any of:
GenerateQueryResult
object
connection_id
required
Connection Id

ID of the connection the query was generated for.

string format: uuid
natural_language_query
required
Natural Language Query

The original natural language query, echoed back.

string
sql
required
Sql

Generated PostgreSQL SQL statement.

string
confidence
required
Confidence

LLM confidence score (0.0–1.0) based on schema coverage.

number
reasoning
required
Reasoning

LLM explanation of table/column selection and any assumptions.

string
referenced_tables
required
Referenced Tables

Tables referenced in the generated SQL.

Array<string>
warnings
Warnings

Warnings about schema gaps or ambiguities.

Array<string>
default:
sql_valid
required
Sql Valid

Whether the generated SQL passed pglast parse and schema validation.

boolean
hallucinated_tables
Hallucinated Tables

Table names in the SQL that were not found in the retrieved schema context.

Array<string>
default:
hallucinated_columns
Hallucinated Columns

Qualified column references (table.column) in the SQL that were not found in the retrieved schema context.

Array<string>
default:
schema_chunks_used
required
Schema Chunks Used

Number of schema chunks retrieved and included in the LLM prompt.

integer
doc_chunks_used
required
Doc Chunks Used

Number of document chunks retrieved and included as business context.

integer
execution_error
Any of:
string
markdown_output
required
Markdown Output

Primary output for callers: query results formatted as a markdown table on success, or an error summary when generation or execution failed.

string
error
Any of:
ErrorDetail
object
code
required
Code

Machine-readable error code (e.g., ‘NOT_FOUND’, ‘VALIDATION_ERROR’).

string
message
required
Message

Human-readable error message describing what went wrong.

string
details
Any of:

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