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.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install 695f1e28-3ca1-437a-b53e-cf9bdb86bd11 --target codexRun after dry-run confirms the install plan.
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
SQLx — Compile-Time Checked SQL for Rust
SQLx is an async, pure-Rust SQL crate that checks queries against your database at compile time. It supports PostgreSQL, MySQL, MariaDB, and SQLite without a DSL or ORM layer.
sqlmap — Automatic SQL Injection and Database Takeover Tool
An open-source penetration testing tool that automates detection and exploitation of SQL injection flaws in web applications.
Chatbot UI — Open Source AI Chat Interface for Any Model
Self-hosted chat interface supporting multiple AI providers with conversation management and a clean responsive design.
SQLModel — SQL Databases in Python with Type Safety and Pydantic
SQLModel combines SQLAlchemy and Pydantic into a single library, letting you define database models as Python classes with type annotations that serve as both ORM models and data validation schemas.