🪸6 Text2SQL Tools to Write Stunning SQL for you ☄️
Tags: productivity, opensource, ai, java
Published: 2024-02-05 02:30:00

Text2SQL, or Chat2SQL tools convert natural language or questions into SQL queries. Imagine having ChatGPT write beautiful, correct, and useful SQL queries for you!


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nvvgba19h5f13duh0wq9.gif)

These tools started to bridge the gap between non-tech users and databases, by allowing them to interact with databases using natural language and reduce the barrier to accessing and analyzing data. But with the advance of AI models, these tools now support more advanced features such as handling complex queries, joining multiple tables, or even supporting natural language conversations.

They can also help improve productivity by automating the process of generating SQL queries, thereby saving time and effort.

In this edition of Star History monthly, we have compiled a collection of open-source Text2SQL tools.

## Chat2DB
[Chat2DB](https://github.com/chat2db/chat2db) aims to be a general-purpose SQL client and reporting tool that incorporates AI capabilities from the start. It supports connection to a handful of databases including MySQL, Postgres, Oracle, SQL Server, SQLite, ClickHouse and more.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v03qpfs6zlvev8qmkq51.png)

There was a bit of [drama](https://www.linkedin.com/feed/update/urn:li:activity:7153040091454611456/) involving Chat2DB a while ago, we won't get into details here but curious to know what you think.

## SQL Chat
[SQL Chat](https://github.com/sqlchat/sqlchat) is a chat-based SQL client, and you can use natural language to communicate with your database to implement operations, such as query, modification, addition, and deletion (!) of the database.

It currently supports MySQL, Postgres, SQL Server and TiDB serverless.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqngu77q3x3f8ca49pku.png)

It's [open-sourced by Bytebase](https://www.bytebase.com/blog/sql-chat/), a database migration tool for teams.

## Vanna
[Vanna](https://github.com/vanna-ai/vanna) is a Python framework that allows the training of an RAG model with queries, DDL, and documentation from a database.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh8olbfyogqr6kvnsrnf.png)

You can use Vanna as is, or build your own custom UI with an existing tool (e.g. Streamlit, Slack).

It was open-sourced in July 2023, and [got really popular this January](https://star-history.com/#vanna-ai/vanna&Date).

## DuckDB-NSQL
[DuckDB-NSQL](https://github.com/NumbersStationAI/DuckDB-NSQL) is a Text2SQL LLM built for local DuckDB SQL analytics tasks, by [MontherDuck](https://motherduck.com/blog/duckdb-text2sql-llm/) and [Numbers Station](https://www.numbersstation.ai/). This can certainly help users leverage the full power of DuckDB and its analytic potential, without having to go back and forth between the DuckDB documentation and the SQL shell.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3oqnvdyy646panuxdth4.png)

## Langchain
With Langchain, you can [build](https://python.langchain.com/docs/use_cases/sql/
) a Q&A chain and agent over an SQL database yourself.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syu2bgbekrnv2i8eqq87.png)

LangChain also has an SQL Agent that you can add onto the chain. It can not only answer questions based on the databases’ schema and content, but also recover from errors by running a generated query, catching the traceback and regenerating it correctly.

## Awesome Text2SQL
[Awesome Text2SQL](https://github.com/eosphoros-ai/Awesome-Text2SQL) is a suite of curated tutorials and resources for LLMs, Text2SQL, Text2DSL, Text2API, Text2Vis and more. Most of the models are LLM+Text2SQL, and for each model, there are links for papers, code, dataset. If you want to dive deep into Text2SQL, take a look.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hifnuiujba01hf60vclq.png)

## To Wrap up
LLM or not, you should still be extra careful when executing model-generated SQL queries. Some ways to minimize risks include describing your database schema, data; constraining the size of the output; validating and reviewing the generated SQL queries before executing them.

## Lastly
If you want more AI content, check out earlier editions of the Star History open-source monthly:

- [GPT Wrappers](https://star-history.com/blog/gpt-wrappers)
- [TTS (Text-to-Speech) Tools](https://star-history.com/blog/tts)
- [AI Extensions for Postgres](https://star-history.com/blog/ai-for-postgres)
- [GitHub Copilot alternatives](https://star-history.com/blog/coding-ai)
- [CLI Tools for Working with LLMs](https://star-history.com/blog/cli-tool-for-llm)
- [Llama 2 and Ecosystem](https://star-history.com/blog/llama2)
- [ChatGPT Special](https://star-history.com/blog/star-history-monthly-pick-202303)