← Back to all agents
Research Open Source

Vanna

Open-source Python agent that writes SQL for you from natural language, trained on your schema.

Our take

The de-facto open-source SQL agent — trains RAG on your own schema and docs, so it actually knows your database.

What it is

Vanna is an open-source Python library for conversational SQL. Instead of a generic text-to-SQL wrapper, it uses RAG trained on your DDL, documentation, and past queries, so it improves over time and produces queries tailored to your specific database. It connects to Snowflake, BigQuery, Postgres, and more.

Best for

  • Ask questions of your database in plain English
  • Let non-technical teams self-serve analytics
  • Train a private SQL assistant on your schema

Pros

  • Open-source, RAG-trained on your own schema
  • Improves with more training data
  • Connects to all major databases

Cons

  • Needs Python + initial training setup
  • Quality depends on good DDL/docs

Quick start

  1. pip install vanna (or uv add vanna) — the library is MIT-licensed and ~1 MB.
  2. Pick a backend: vanna-ai/vanna-openai (works with OpenAI / Anthropic / Ollama), vanna-ai/vanna-qdrant for full self-host.
  3. Train on your data: vn.train(ddl=…) for schema, vn.train(documentation=…) for context, vn.train(question=…, sql=…) for examples — RAG builds automatically.
  4. Ask: vn.ask("Top 5 customers by lifetime spend in 2026 Q1") → returns SQL + a Plotly chart.
  5. Build a UI: Vanna ships Streamlit / Flask / FastAPI samples; or call vn.ask() from any Python service.
  6. For hosted: sign up at vanna.ai → Vanna Cloud manages RAG + model layer; free tier = 100 questions/day.

Sample input / output

Input
import vanna as vn
from vanna.openai import OpenAI_Chat
from vanna.chromadb import ChromaDB_VectorStore

class MyVanna(ChromaDB_VectorStore, OpenAI_Chat):
    pass

vn.set_model(MyVanna(model="gpt-4o"))

# Train on schema (DDL)
vn.train(ddl="""
  CREATE TABLE customers (
    id INT PRIMARY KEY, name TEXT, signup_date DATE, country TEXT
  );
  CREATE TABLE orders (
    id INT PRIMARY KEY, customer_id INT REFERENCES customers(id),
    amount NUMERIC, created_at TIMESTAMP
  );
""")

vn.train(documentation="customers.country uses ISO-2 codes; orders.created_at is UTC.")

sql, df, fig = vn.ask("Top 5 countries by 2026 H1 revenue, with customer counts.")
print(sql)
df.head()
Output
Question → SQL (auto):
SELECT c.country,
       SUM(o.amount) AS revenue,
       COUNT(DISTINCT c.id) AS customer_count
FROM   customers c
JOIN   orders o ON o.customer_id = c.id
WHERE  o.created_at >= '2026-01-01'
  AND  o.created_at <  '2026-07-01'
GROUP  BY c.country
ORDER  BY revenue DESC
LIMIT  5;

Returned as DataFrame (5 rows, 0.4s) and a Plotly bar chart (12 KB).
RAG context used: 3 DDL chunks + 2 doc chunks. Token cost: $0.0024 (GPT-4o).

Benchmarks

License MIT (library); proprietary Vanna Cloud — vanna.ai github
GitHub stars 12k (main repo) — GitHub 2026
Supported databases Snowflake, BigQuery, Postgres, MySQL, Redshift, DuckDB, +40 — Vanna docs
Backing model flexibility Any OpenAI-compatible API incl. local Ollama models — Vanna pluggable LLM
Free tier 100 questions/day (Vanna Cloud) — Vanna pricing

Pricing

Free library; hosted Vanna Cloud

Underlying models

OpenAIAnthropiclocal models via Ollama

Self-hosting

Yes — Vanna can be self-hosted under the MIT license. This gives you full control over data and deployment.

Should you pick this?

Pick it if You're a data team that wants a private SQL/RAG assistant your analysts can rely on, trained on your schema and docs — and you'd rather not pay an enterprise BI vendor.
Skip it if You want a no-code BI tool for business users (pick Text-to-SQL on top of ThoughtSpot, Sigma, or Power BI Copilot) — Vanna assumes a Python-friendly user.

Similar agents