Intro to Vanna: A Python-based AI SQL co-pilot

Ashish Singal
Vanna AI
Published in
4 min readJul 9, 2023

TLDR: We help data people that know Python write SQL faster using AI. See our starter notebook here.

The deluge of data

We are bathing in an ocean of data, sitting in Snowflake or BigQuery, that is brimming with potential insights. Yet only a small fraction of people in an enterprise have the two skills required to harness the data —

  1. A solid comprehension of advanced SQL, and
  2. A comprehensive knowledge of the data structure & schema

The burden of being data-savvy

Since you are reading this, chances are you are one of those fortunate few (data analysts, data scientists, data engineers, etc) with those abilities. It’s an invaluable skill, but you also get hit tons requests requiring you to write complex SQL queries. Annoying!

Introducing Vanna, the SQL co-pilot

Vanna, at its core, is a co-pilot to Python & SQL savvy data people to to streamline the process of writing custom SQL on your company’s data warehouse using AI and LLMs. Most of our users use our Python package directly via Jupyter Notebooks (starter notebook here) —

sql = vn.generate_sql(question='What are the top 10 customers by Sales?')
print(sql)

And here are the results —

SELECT customer_name,
total_sales
FROM (SELECT c.c_name as customer_name,
sum(l.l_extendedprice * (1 - l.l_discount)) as total_sales,
row_number() OVER (ORDER BY sum(l.l_extendedprice * (1 - l.l_discount)) desc) as rank
FROM snowflake_sample_data.tpch_sf1.lineitem l join snowflake_sample_data.tpch_sf1.orders o
ON l.l_orderkey = o.o_orderkey join snowflake_sample_data.tpch_sf1.customer c
ON o.o_custkey = c.c_custkey
GROUP BY customer_name)
WHERE rank <= 10;

Getting started with Vanna in a Notebook

Vanna is super easy to get started with —

  1. Grab an API key directly through the notebook
  2. Train a custom model on some past queries from your data warehouse
  3. Ask questions in plain English and get back SQL that you can run in your workflow

Check out the full starter notebook here.

Vanna is built with a privacy-first and security-first design — your data never leaves your environment.

Using Vanna with a Streamlit front end

Streamlit is an open source pure Python front end. We have built an UI for Vanna on top of Streamlit, that you can either use directly (eg our hosted version), and that you can clone, download, optionally modify, and self host.

If you choose to self host it, you can run Vanna with a UI without any data leaving your environment.

Pre-trained datasets

While every company has a unique data warehouse, many datasets contain similar schemas across companies. For example, users of Google Ads, Facebook Ads, Salesforce, Stripe and Spotify will all have similar schemas representing this data, especially if they’ve used tools like Fivetran or Airbyte to ingest them.

Vanna provides out of the box, open source, “pre-trained” queries for some of these datasets. You can augment them with your own queries, but it means that a bunch of questions will answer correctly immediately.

Advanced features

Not only can Vanna generate SQL, but Vanna can generate tabular results by running the query, it can generate explanations of the SQL, and Plotly charts. Let’s see it in action —

Making insights more accessible to all

Most of our initial users within an organization are more sophisticated data people using Vanna in Jupyter Notebooks or similar environments as a co-pilot. But often, especially once they are more comfortable with Vanna’s performance, they want to enable their entire organization, and even their customers, to use Vanna and get data insights. Here are some ways you make Vanna and data insights more accessible —

  1. Python / Notebooks: Start here.
  2. Streamlit: We’ve open sourced a few Streamlit apps that you can host for an easy UI on Vanna in your environment.
  3. Customer facing: You can build a UI directly for end customers in your web app.

Beyond these, we are working on a hosted web app, a Slackbot, and integration with BI tools.

Next steps

Get started with Vanna today. If you would like a 1:1 dem and white-glove onboarding, please contact us.

--

--