ScriptsMar 31, 2026·2 min read

Vanna — Chat with Your SQL Database Using AI

AI-powered text-to-SQL. Ask questions in plain English, get accurate SQL queries and visualizations. Learns your schema. Works with any database. 23K+ stars.

TL;DR
Vanna converts natural language questions into accurate SQL queries and visualizations.
§01

What it is

Vanna is an AI-powered text-to-SQL tool. You ask a question in plain English, and Vanna generates the correct SQL query, runs it against your database, and returns the results with optional visualizations. It learns your schema, table relationships, and query patterns to improve accuracy over time.

Vanna targets data analysts, business users, and developers who need quick answers from databases without writing SQL manually.

§02

How it saves time or tokens

Vanna's training step lets it memorize your schema, column meanings, and example queries. Once trained, it generates accurate SQL on the first attempt rather than requiring iterative prompt engineering. This reduces both human time (no SQL writing) and token cost (fewer retries).

The visualization layer means you get charts directly from natural language without exporting to a BI tool.

§03

How to use

  1. Install Vanna: pip install vanna
  2. Connect to your database (PostgreSQL, MySQL, SQLite, BigQuery, Snowflake)
  3. Train Vanna on your schema with DDL statements and example queries
  4. Ask questions in natural language and get SQL + results
§04

Example

import vanna
from vanna.remote import VannaDefault

vn = VannaDefault(model='my-model', api_key='...')
vn.connect_to_postgres(
    host='localhost',
    dbname='analytics',
    user='reader',
    password='secret'
)

# Train on your schema
vn.train(ddl='CREATE TABLE orders (id INT, customer_id INT, total DECIMAL, created_at TIMESTAMP)')
vn.train(question='Total revenue last month', sql='SELECT SUM(total) FROM orders WHERE created_at >= DATE_TRUNC(\'month\', NOW()) - INTERVAL \'1 month\'')

# Ask questions
sql = vn.generate_sql('What are the top 10 customers by revenue?')
df = vn.run_sql(sql)
vn.generate_plotly_chart(df)
§05

Related on TokRepo

§06

Common pitfalls

  • Vanna accuracy depends heavily on training quality; provide representative DDL and at least 10-20 example question-SQL pairs
  • Complex joins across many tables may produce incorrect queries; verify generated SQL before running on production data
  • The default model uses Vanna's cloud API; for privacy, configure a local LLM backend

Frequently Asked Questions

Which databases does Vanna support?+

Vanna supports PostgreSQL, MySQL, SQLite, BigQuery, Snowflake, DuckDB, and any database accessible via SQLAlchemy. You connect using the appropriate connector method and Vanna handles the rest.

How does Vanna learn my schema?+

You train Vanna by providing DDL statements (CREATE TABLE), example question-SQL pairs, and documentation strings. Vanna stores these in a vector database and retrieves relevant context when generating SQL for new questions.

Can I use Vanna with a local LLM?+

Yes. Vanna supports multiple LLM backends including OpenAI, Anthropic, Ollama, and any OpenAI-compatible endpoint. Configure the model parameter and API endpoint to use your preferred provider.

How accurate is the generated SQL?+

Accuracy depends on training quality. With good DDL coverage and 10-20 example queries, Vanna achieves high accuracy on typical analytical questions. Complex queries with subqueries or window functions may need more training examples.

Does Vanna handle data visualization?+

Yes. After running a query, Vanna can generate Plotly charts from the result DataFrame. It selects appropriate chart types (bar, line, pie) based on the data shape and the original question.

Citations (3)
  • Vanna GitHub— Vanna is an AI-powered text-to-SQL tool with 23K+ GitHub stars
  • Vanna Docs— Vanna supports multiple database connectors and LLM backends
  • arXiv— Text-to-SQL approaches for natural language database querying
🙏

Source & Thanks

Created by Vanna AI. Licensed under MIT. vanna-ai/vanna — 23,000+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets