Training Vanna on your schema
Vanna needs to understand your database schema to generate good SQL. You train it with: DDL statements (CREATE TABLE), documentation (column descriptions), and example SQL queries with their English equivalents. Training takes 10 minutes for a 20-table schema. After training, Vanna uses a combination of RAG (retrieving relevant schema from the training data) and LLM prompting to generate SQL. The DDL + documentation approach produces 85% accurate SQL. Adding 50 example queries boosts accuracy to 92%.
The accuracy breakdown by query type
Simple SELECTs with WHERE and GROUP BY: 95% accurate. 'Show me total revenue by product category for last month' works reliably. JOINs across 2-3 tables: 85% accurate. 'Show me customer names with their last order date' works most of the time. JOINs with subqueries: 65% accurate. 'Customers who spent more than the average in their city' fails 35% of the time. Window functions: 50% accurate. 'Running total of sales per day' generates syntax errors.
Security: questions are not SQL injection
Vanna generates SQL as text, which carries SQL injection risk if the LLM hallucinates dangerous syntax. Vanna mitigates this with: a SQL validator that checks for dangerous patterns (DROP, DELETE, INSERT without WHERE), a read-only database connection by default, and a preview step that shows the SQL before execution. For production use, always use a read-only database user and enable the SQL validator.
The charting integration: SQL to visualization
Vanna integrates with Plotly for charting. Ask 'show me a bar chart of revenue by month' and it generates the SQL, runs it, and plots a bar chart. The chart type selection (bar, line, pie, scatter) is based on the question phrasing and data shape. The charts are functional but not beautiful: standard Plotly defaults with bare styling. For presentation-quality charts, export the data and visualize in your own tool.
Vanna vs writing SQL vs ChatGPT
Vanna: trained on your schema, generates and executes SQL, built-in charting. Best for analytics teams that query the same database daily. ChatGPT: can generate SQL from schema description, can not execute it, hallucinates column names. Best for one-off queries. Writing SQL yourself: 100% accurate, slowest. Best for complex queries where accuracy matters more than speed.