NL2SQL Platform Documentation
These docs describe the shipped behaviour of NL2SQL, for engineers who use it, run it or contribute to it. Where a page states a limitation, the limitation is the fact; known gaps are listed in Status and limitations.
Problem this system solves
NL2SQL converts natural language requests into validated SQL across one or more datasources. The model emits a typed AST, never SQL text; the AST is checked against the retrieved schema and the caller's RBAC policy before any SQL is generated. The system is built for multi-datasource environments where correctness and inspectable failure matter more than conversational flexibility.
Model output itself is not reproducible; see Determinism for exactly which parts of a run are stable and which are not.
Design philosophy
- Determinism where it is achievable: stable content-hashed IDs, sorted DAG layering, and a fixed graph topology. The LLM's output is not part of that guarantee.
- Schema grounding: planning is constrained by a schema snapshot retrieved via structured chunks.
- Explicit validation gates: logical validation enforces schema and RBAC constraints before execution.
- Modularity: adapters, subgraphs, and executors are capability-driven and replaceable.
- Bounded waiting: a global timeout bounds how long the caller waits for a run, not how long the work runs (on expiry the caller gets
PIPELINE_TIMEOUTand the worker thread winds down in the background); each run carries a per-run cancellation token, and the graph itself runs in-process on a thread pool. - Observability: structured logging always; events on every run, which observers turn into logs, an audit log under
storage.pathand, with theotelextra, OpenTelemetry metrics and traces. See Observability Stack.
Non-functional goals
- Reliability under partial failures (a circuit breaker on vector retrieval, SQL-agent retry semantics, errors returned as state rather than raised).
- Extensibility via plugins and registries (datasources, subgraphs, executors).
- Cost awareness (a row limit is baked into every generated statement;
max_bytesis reported, not enforced). - Authorization at planning time (RBAC policy-based table access). The role is supplied by the caller, so the deployer owns authentication; see Security Model.
Packages
Four packages share one version. Each arrow points at what the package imports; the SDK sits at the base, and the engine's import nl2sql facade is the only door the API and the CLI use. Third-party adapters compile against the SDK alone and are found through the nl2sql.adapters entry points.
flowchart TB
people["People"]
apps["Apps and MCP clients"]
devs["Python developers"]
thirdparty["Third-party adapters"]
subgraph packages["Packages"]
direction TB
web["nl2sql-api<br/>REST API, serves the web UI<br/>(built from nl2sql-ui/)"]
cli["nl2sql-cli<br/>nl2sql command, nl2sql chat<br/>(web extra = nl2sql-api)"]
engine["nl2sql-engine<br/>import nl2sql facade, pipeline,<br/>MCP server, adapters via entry points"]
sdk["nl2sql-sdk<br/>adapter and extension interfaces<br/>(pydantic only)"]
end
people -->|"browser"| web
people -->|"terminal"| cli
apps -->|"REST"| web
apps -->|"MCP: nl2sql mcp"| cli
devs -->|"import nl2sql"| engine
web --> engine
cli --> engine
engine --> sdk
thirdparty --> sdk
| Package | Import | What it is |
|---|---|---|
nl2sql-sdk |
nl2sql_sdk |
The interfaces an extension implements (adapters, secrets, stores, policy checks). Depends on pydantic only. |
nl2sql-engine |
nl2sql |
The facade, the pipeline, the built-in adapters and the MCP server (mcp extra). |
nl2sql-api |
nl2sql_api |
The REST API, and the web UI built from nl2sql-ui/. |
nl2sql-cli |
nl2sql_cli |
The nl2sql command and the nl2sql chat terminal app. |
High-level flow
flowchart TD
User[User Query] --> Resolver[DatasourceResolverNode]
Resolver --> Decomposer[DecomposerNode]
Decomposer --> Router[Scan Layer Router]
Router --> Subgraph[SQL Agent Subgraph]
Subgraph --> Router
Router --> Aggregator[EngineAggregatorNode]
Aggregator --> Synthesizer[AnswerSynthesizerNode]
Core entry points
- Pipeline runtime:
nl2sql.pipeline.runtime.run_with_graph - Graph builder:
nl2sql.pipeline.graph.build_graph - Application context:
nl2sql.runtime.Runtime
Navigate the docs
- Get started to install and ask a first question.
- How it works: the pipeline, state, determinism, invariants, failure and recovery and indexing.
- Schema store for schema contracts and retrieval.
- Execution isolation for what the runtime bounds, and what it does not.
- Adapters for plugin discovery and capability-based routing.
- Observability and error handling for metrics, logging and error contracts.