Databases / Amazon Redshift
Natural language to SQL for Amazon Redshift
NLQueries is an open source natural language to SQL engine for Amazon Redshift. Ask a question in plain English, get SQL that is validated against your real Redshift schema before it runs, and see the answer.
It works from the command line, as a Python library, and as an MCP server for Claude Desktop, Cursor and other AI assistants.
Connect Redshift and ask your first question
Install the package, register the connection once, build the knowledge base, and query. Leave out --password and it is prompted for without echoing, then stored in your OS keychain rather than the connectors file. Only where no keychain is available does it go into the stored connection URL, with a warning.
$ pip install "nlqueries-core[redshift]" $ nlqueries connect redshift --host my-cluster.abc123.us-east-1.redshift.amazonaws.com --port 5439 --database dev --user awsuser --alias redshift-prod $ nlqueries process-history redshift-prod --annotate $ nlqueries export-kb redshift-prod $ nlqueries query redshift-prod "how many orders were placed last month by first-time customers?"
How NL2SQL works on Redshift
Most text-to-SQL tools hand the LLM a schema dump and hope. NLQueries builds a YAML knowledge base from your Redshift schema and from real query history, in this case STL_QUERY (needs superuser or pg_read_all_stats; provisioned clusters only), so it learns which joins your team actually uses and what your columns mean. That knowledge base is what the model sees when it writes SQL.
Every generated statement is parsed with sqlglot and refused unless it is a single read-only query, and its columns are checked against the schema in the knowledge base. It then runs read-only where the engine allows it, with a statement timeout; what each connector enforces has the details per engine. Use nlqueries ask to see the SQL without running it, or nlqueries query to run it. A semantic cache answers repeated questions without another LLM call, and runs the stored SQL again so the rows are current.
Redshift-specific details
The connector does not read table or column comments, so descriptions come from import-dbt or from editing the knowledge base YAML by hand. Row counts come from SVV_TABLE_INFO. Annotating the knowledge base pays off more here than on other engines.
Each query runs in a READ ONLY transaction with a statement timeout, and the connection always uses TLS.
REDSHIFT_SOCKET_TIMEOUT_SECONDS bounds the whole connection, including how long a query may run without sending data. It defaults to the statement timeout plus 30 seconds, never less than 60, and must stay above the statement timeout. The same value covers a Serverless workgroup resuming from idle.
Full connector notes are in the connectors guide, and the read-only role to create is in database hardening. This connector covers Redshift provisioned clusters and Redshift Serverless.
Use it from Claude, Cursor or any MCP client
Run nlqueries mcp-server start and point Claude Desktop, Cursor, or any Model Context Protocol client at it. Its query tool generates SQL through the same pipeline, runs it read-only and returns the rows. Over stdio, the transport desktop clients use, there is nothing to configure. A network transport will not start without authentication, by OIDC or a pre-shared token, and grants per agent and action decide who may run SQL. See MCP authentication.
FAQ
Amazon RedshiftFrequently asked questions
How does NLQueries turn a natural language question into SQL?
It retrieves the relevant tables, columns, relationships and past query patterns from a YAML knowledge base built from your schema and, where the engine keeps one, your query history. It asks an LLM for SQL with that context, checks the SQL with sqlglot against a read-only statement policy and the schema in the knowledge base, and runs it read-only where the engine allows, with a statement timeout.
Is the generated SQL safe to run against production?
Every statement is parsed and refused unless it is a single read-only query, then run read-only where the engine allows it, with a timeout and result caps. nlqueries ask shows the SQL without running it. What each engine enforces differs, and on some the database grant is the only control, so pair it with a least-privilege role; the database hardening guide has one per engine.
Does NLQueries work with Redshift Serverless?
Yes. The same connector covers provisioned clusters and Serverless workgroups, and the socket timeout default leaves room for a workgroup to resume from zero. Serverless has no STL_QUERY, so process-history stops with an error there; build the knowledge base from the schema with export-kb.
Can Claude Desktop or Cursor query this database through NLQueries?
Yes. nlqueries mcp-server start runs a Model Context Protocol server. Its query tool generates SQL through the same pipeline, runs it read-only and returns the rows, so any MCP client can ask questions as a native tool call.
Other engines: Postgres · MySQL · Snowflake · BigQuery · SQL Server · DuckDB · SQLite