nlp2sql supports Redshift as a first-class warehouse target while keeping the same DSL and semantic model used for PostgreSQL.
The public examples here stay generic and use the repository's own e-commerce-style concepts rather than any private warehouse naming.
At the API level, very little changes:
- use a
redshift://URL or a compatible PostgreSQL-style Redshift URL - keep using
connect()andask() - use schema filters aggressively on large warehouses
- use semantic context when questions could map to multiple fact tables
import os
import nlp2sql
from nlp2sql import ProviderConfig, SemanticContext
nlp = await nlp2sql.connect(
"redshift://user:password@cluster.region.redshift.amazonaws.com:5439/analytics",
provider=ProviderConfig(provider="anthropic", api_key=os.environ["ANTHROPIC_API_KEY"]),
schema="analytics",
schema_filters={
"include_tables": [
"stores",
"marketing_channels",
"daily_channel_metrics",
],
"exclude_system_tables": True,
},
semantic_context=SemanticContext(
domain="ecommerce_channel_performance",
canonical_tables=["daily_channel_metrics"],
),
)
result = await nlp.ask(
"Show daily revenue by source category for the flagship store",
validate=True,
repair=True,
)nlp2sql query \
--database-url redshift://user:password@cluster.region.redshift.amazonaws.com:5439/analytics \
--schema analytics \
--provider anthropic \
--question "Show daily revenue by source category for the flagship store" \
--semantic-context-file semantic-context.json \
--examples-file examples.json \
--validate \
--repair \
--show-semantic-context \
--show-sql-intent-planStandard Redshift cluster:
redshift://username:password@cluster-id.region.redshift.amazonaws.com:5439/databaseRedshift Serverless:
redshift://username:password@workgroup.account.region.redshift-serverless.amazonaws.com:5439/databaseCompatible PostgreSQL-style URL:
postgresql://username:password@cluster-id.region.redshift.amazonaws.com:5439/databaseWarehouse schemas often contain staging, helper, and legacy tables. Prefer:
include_schemasinclude_tablesexclude_tablesexclude_system_tables
This improves both retrieval quality and performance.
If multiple Redshift tables could satisfy the same question, use semantic context to define:
- the canonical fact table
- required dimensions
- required filters
- disallowed tables
This is usually more reliable than relying on examples alone.
Few-shot examples are still useful, especially when you need:
- preferred join patterns
- preferred date logic
- preferred naming of derived metrics
But examples work best when the semantic layer has already narrowed the solution space.
- metadata discovery uses Redshift-appropriate system views
- disk caching is especially helpful because warehouse catalog scans are relatively expensive
- Redshift benefits more than small PostgreSQL databases from warm retrieval caches and strong schema filters
Check:
- network access and allowlists
- SSL requirements
- schema permissions
- readonly access for validation flows
If SQL executes but the answer is semantically wrong:
- inspect
semantic_context - inspect
sql_intent_plan - verify your schema filters are narrow enough
- add or improve semantic context before adding more examples
If you see a message about index dimensions not matching the current embedding provider:
nlp2sql cache clear --embeddingsThen rerun with the intended embedding provider.
The repository also includes local Redshift-oriented test infrastructure through Docker and LocalStack-style flows. Use that for development rather than depending on private infrastructure names in docs or examples.