Documentation Index
Fetch the complete documentation index at: https://mintlify.com/metabase/metabase/llms.txt
Use this file to discover all available pages before exploring further.
One-shot SQL generation with your own API key is only available on self-hosted Metabases. For Metabase Cloud, check out Metabot.
Setting up SQL generation
To enable SQL generation on a self-hosted Metabase:Add your Anthropic API key
Enter your Anthropic API key in the provided field
You’ll need an API key from Anthropic. Currently, only Anthropic is supported.
Generate SQL from natural language
To generate SQL from a natural language prompt:Select tables
Enter one or more tables that your query will reference
You must select at least one table for both new queries and edits.
Edit existing SQL
You can also edit existing SQL queries using AI:- Place your cursor in the query
- Trigger the prompt with Cmd+Shift+I (Mac) or Ctrl+Shift+I (Windows)
- Describe the change you want to make (like “add a filter for orders from this year”)
- Review the suggested edits and accept or reject them
Like with all generative AI, always double-check the output before running queries.
How it works
Context independence
Each prompt is independent — the AI doesn’t retain context from previous generations. This means:- Every generation starts fresh
- You need to provide all context in each prompt
- Previous prompts won’t influence new ones
Schema context
When you generate SQL, Metabase provides the AI with:- Database schema - Table and column structure from your selected tables
- Semantic types - Field meanings and data types
- Relationships - Foreign key relationships between tables
- Metadata - Descriptions and display names you’ve added
Dialect-specific generation
The SQL generator adapts to your database dialect automatically:Configuration options
Admins can configure several settings for SQL generation:API settings
- Anthropic API key - Your API key from Anthropic (required)
- Model selection - Choose which Claude model to use (default: claude-opus-4-5)
- Max tokens - Maximum tokens for LLM responses (default: 4096)
- Request timeout - Socket timeout in milliseconds (default: 60000ms)
- Connection timeout - Connection timeout in milliseconds (default: 5000ms)
Rate limiting
To prevent abuse and control costs:- Per user limit - Maximum requests per user per minute (default: 20)
- Per IP limit - Maximum requests per IP address per minute (default: 100)
These rate limits help manage API costs and prevent excessive usage. Adjust them based on your team’s needs and API budget.
Best practices
Improve generation quality
Add table and field descriptions
Provide context about what your tables and fields represent. The AI uses these descriptions to better understand your data model.
Set correct semantic types
Ensure fields have accurate semantic types (e.g., Creation Date, Email, Price). This helps the AI generate appropriate SQL operations.
Be specific in prompts
Instead of “show me sales”, try “show me total sales by month for the last year, sorted by month descending”.
Security considerations
- API keys are encrypted when stored in Metabase
- SQL generation respects user permissions - users can only generate queries for tables they have access to
- Generated SQL is not automatically executed, giving users a chance to review before running
- Rate limits prevent excessive API usage
Differences from Metabot
SQL generation on self-hosted differs from Metabot in several ways:| Feature | Self-hosted SQL Generation | Metabot (Cloud) |
|---|---|---|
| Availability | Self-hosted only | Cloud only |
| Authentication | Your own Anthropic API key | Included in add-on |
| Context | One-shot (no conversation history) | Maintains conversation context |
| Capabilities | SQL generation only | SQL, query builder, analysis, fixing errors |
| Chat interface | Inline editing only | Full chat sidebar |
| Model selection | Choose your Claude model | Managed by Metabase |
| Cost | Pay Anthropic directly | Included in Metabot pricing |
Troubleshooting
”LLM is not configured” error
Make sure you’ve added a valid Anthropic API key in Admin settings > AI. The key must start withsk-ant-.
”No tables found” error
You must select at least one table before generating SQL. Either:- Use @mentions to reference tables:
@orders @customers - Provide source SQL that references tables
- Explicitly select tables in the interface
”Failed to parse SQL” error
If Metabase cannot parse your existing SQL to extract table references, use @mentions to provide table context instead.Poor quality results
Improve results by:- Adding descriptions to tables and fields
- Setting correct semantic types
- Being more specific in your prompts
- Using Opus models instead of Sonnet
- Mentioning specific table names in prompts