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.
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.
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.
How to use
- Install Vanna:
pip install vanna - Connect to your database (PostgreSQL, MySQL, SQLite, BigQuery, Snowflake)
- Train Vanna on your schema with DDL statements and example queries
- Ask questions in natural language and get SQL + results
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)
Related on TokRepo
- Database tools -- Database management and query tools
- RAG tools -- Retrieval-augmented generation pipelines
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
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.
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.
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.
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.
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
Related on TokRepo
Source & Thanks
Created by Vanna AI. Licensed under MIT. vanna-ai/vanna — 23,000+ GitHub stars
Discussion
Related Assets
Moodle — Open-Source Learning Management System
The most widely used open-source learning platform, providing course management, assessments, and collaboration tools for educators and organizations worldwide.
Sylius — Headless E-Commerce Framework on Symfony
An open-source headless e-commerce platform built on Symfony and API Platform, designed for developers who need a customizable and API-first commerce solution.
Akaunting — Free Self-Hosted Accounting Software
A free, open-source online accounting application built on Laravel for small businesses and freelancers to manage invoices, expenses, and financial reports.