Governed SQL Generation Chatbot
Design an analytics chatbot that generates grounded SQL while enforcing user authorization and protecting a shared Trino cluster from unsafe queries.
Problem statement
For this exercise, assume an organization has an existing Trino cluster, metadata catalog, and authorization service. Internal analysts ask a chatbot questions in natural language.
The assistant may discover only metadata the current user is allowed to see, generate one read-only SQL statement, explain the referenced objects and assumptions, and ask for clarification when the request is ambiguous.
Before execution, a deterministic broker must parse and validate the SQL, re-authorize every referenced catalog, schema, table, column, and governed row or masking policy, estimate cost, and enforce resource limits independently of the language model.
DDL, data-changing DML, multi-statement input, unknown objects, and requests beyond the user's budget are rejected or returned for revision.
Unqualified cartesian products are rejected by default; an explicitly reviewed small-side exception may proceed only when deterministic authorization, cardinality, and resource budgets pass.
The user reviews the SQL before execution; every generation, policy decision, execution, cancellation, and result reference is auditable. Training a model, designing Trino itself, and creating the organization's authorization rules are out of scope.
What to build
- Retrieve schema, semantic, and example metadata only from objects the authenticated user is currently allowed to discover.
- Produce one read-only SQL draft with an explanation, referenced objects, uncertainty, and clarifying questions when intent or joins are ambiguous.
- Deterministically parse, authorize, safety-check, budget, and admit the final SQL independently of model output before sending it to Trino.
- Let users confirm, execute, monitor, cancel, and inspect bounded results while retaining an immutable audit trail of inputs, decisions, versions, and outcomes.
At scale
- Support 500 daily users, 20 concurrent generations, and 20 admitted query executions against a catalog of 20,000 tables and 500,000 columns.
- Return a SQL draft or clarification within eight seconds at p95 and an allow, deny, or revision decision within two seconds at p95, excluding Trino execution time.
- Reflect authorization revocations for new executions and result reads within 60 seconds and metadata changes in generation context within five minutes; fail closed when either authority is unavailable or stale beyond its bound.
- Default each user-confirmed query to a five-gigabyte scan budget, 30-second runtime limit, and 1,000-row preview, with per-user concurrency and daily resource quotas.