WrenAI: Open-Source Text-to-SQL for Natural Language Data Queries

Aug 12, 2025

Introduction

Data teams often struggle with the bottleneck of SQL query writing, where non-technical stakeholders must rely on data analysts to extract simple insights. WrenAI solves this by providing an open-source Text-to-SQL engine that allows anyone to query databases using natural language. With a growing community and a focus on semantic modeling, WrenAI transforms how organizations interact with their data, making real-time insights accessible without requiring deep SQL expertise.

What Is WrenAI?

WrenAI is an open-source Text-to-SQL solution that enables users to query databases using natural language for faster, actionable insights. It acts as a semantic layer between the user’s natural language question and the underlying database, java-based backend services, and LLM-driven SQL generation. Maintained by Canner, it is licensed under the GNU Affero General Public License (AGPL), ensuring the tool remains open and accessible for data teams worldwide.

Unlike simple prompt-based Text-to-SQL tools, WrenAI emphasizes a semantic layer that defines the relationships and business logic of the data, ensuring that the generated SQL is accurate and aligned with business definitions.

Why WrenAI Matters

The primary gap WrenAI fills is the “SQL bottleneck.” In most organizations, the data analyst is the only person who can translate a business question into a technical query. This creates a delays in decision-making and puts an undue burden on technical staff. WrenAI democratizes data access by allowing business users to ask questions in plain English (or other supported languages) and receive immediate SQL results.

By implementing a semantic layer, WrenAI avoids the common pitfalls of LLM-generated SQL, which often suffers from “hallucinations” or incorrect join logic. By providing the LLM with a structured understanding of the data model, WrenAI ensures that the generated queries are reliable and verifiable. This makes it a viable tool for production-grade data exploration rather than just a prototype.

As the open-source community grows, WrenAI is becoming a critical piece of the modern data stack, allowing teams to move from a request-based data culture to a self-service data culture.

Key Features

  • Natural Language Processing: WrenAI converts complex business questions into precise SQL queries seamlessly, reducing the need for manual query writing.
  • Semantic Modeling Layer: A dedicated layer where users can define business logic, relationships, and calculations, ensuring the LLM generates SQL based on business-accurate definitions.
  • Multi-Database Support: The engine supports a wide array of databases, including PostgreSQL, MySQL, SQL Server, and other major data warehouses, providing versatility across different environments.
  • Interactive Query UI: A user-friendly interface that allows users to write, test, and refine their natural language queries and visualize the resulting data.
  • End-to-End Testing: Built-in capabilities for testing configurations and queries, ensuring that the semantic model and the generated SQL are functioning as expected.
  • LLM Agnostic Approach: While it leverages LLMs for translation, the architecture is designed to be flexible, allowing teams to integrate different models to optimize for cost or performance.
  • Open-Source Transparency: Being AGPL licensed, the entire codebase is open for audit, modification, and community-driven enhancements.

How WrenAI Compares

Feature WrenAI Vanna.ai Text-to-SQL LLM (Raw)
Semantic Layer Yes (Integrated) Training-based No
Open Source Yes (AGPL) Partial/Open Core Depends on Model
Setup Complexity Medium Medium Low
Accuracy/Reliability High (Model-driven) High (Training-driven) Variable

WrenAI differentiates itself by focusing on the semantic layer. While tools like Vanna.ai rely heavily on training the model on your specific schema and previous queries, WrenAI allows you to explicitly define the business logic. This means that if a business definition changes (e.g., how “Active User” is defined), you change it in the semantic layer once, and every natural language query that uses that term is automatically updated.

Compared to using a raw LLM (like GPT-4) with a schema prompt, WrenAI provides a structured environment. Raw LLMs often struggle with complex joins or specific database dialects. WrenAI’s architecture ensures that the LLM is guided by a strict semantic model, which significantly reduces hallucinations and increases the reliability of the generated SQL.

Getting Started: Installation

WrenAI can be deployed using Docker, which is the recommended method for managing its various backend services and the frontend UI.

Prerequisites

Ensure you have Docker and Docker Compose installed on your system. You will also need an API key for the LLM you intend to use (e.g., OpenAI API key).

Docker Installation

# Clone the repository
git clone https://github.com/Canner/WrenAI.git
cd WrenAI

# Start the services using Docker Compose
docker-compose up -d

Once the services are running, you can access the WrenAI UI via your browser at http://localhost:3000.

Post-Install Verification

After launching the UI, follow the setup wizard to connect your database and configure your LLM provider. Verify the connection by asking a simple question like “Show me all tables in my database” to ensure the translation engine is working.

How to Use WrenAI

The basic workflow in WrenAI involves three main steps: connecting your data source, defining your semantic model, and querying in natural language.

First, connect your database. In the UI, navigate to the data source settings and provide the necessary credentials for your PostgreSQL, MySQL, or SQL Server instance. WrenAI will scan your schema to identify tables and columns.

Next, define your semantic model. This is the critical step where you map natural language terms to SQL expressions. For example, you can define that “Revenue” equals SUM(price * quantity). Once this is defined, any user asking for “total revenue” will trigger the correct calculation regardless of their SQL knowledge.

Finally, start querying. Use the chat interface to ask business questions. WrenAI will translate the question into SQL, execute it against your database, and return the results in a table format. You can also review the generated SQL to verify the accuracy of the translation.

Code Examples

WrenAI handles the translation from natural language to SQL, but the underlying configuration and testing can be performed via code. Below are examples of how the system interacts with your data.

Basic Query Translation

A user asks: "What are the sales figures for last quarter?"

WrenAI’s engine translates this into a SQL query similar to the following:

SELECT sum(sales_amount) FROM orders WHERE order_date >= '2023-10-01' AND order_date <= '2023-12-31';

This translation is driven by the semantic model's understanding of "sales figures" and "last quarter" based on the date columns in your schema.

Complex Join Translation

A user asks: "Which customers have spent more than $10,000 in total?"

WrenAI translates this into a join query:

SELECT c.customer_name, SUM(o.total_amount) as total_spent
FROM customers c
JOIN orders o ON c.id = o.customer_id
WHERE o.status = 'completed'
GROUP BY c.customer_name
HAVING SUM(o.total_amount) > 10000;

The semantic layer ensures that the join between customers and orders is correctly identified using the foreign key relationships defined in the model.

Real-World Use Cases

  • Executive Dashboards: A CEO or Manager can ask "What was our churn rate last month?" without waiting for a data analyst to write a custom SQL query and build a dashboard.
  • Customer Support Teams: Support agents can query order statuses or customer history using natural language, allowing them to find specific customer issues without needing access to a database GUI.
  • Customer Success Managers:L can ask "Which customers are at risk of churning based on their activity in the last 30 days?" to proactively identify accounts that need attention.
  • Data Analysts: Analysts can use WrenAI to quickly prototype queries and explore data without writing repetitive boilerplate SQL, speeding up the overall analysis process.

Contributing to WrenAI

WrenAI is an open-source project and encourages contributions from the developer community. If you wish to contribute, start by reading the CONTRIBUTING.md file in the repository. The project follows standard GitHub flow: report bugs via the issue tracker, submit feature requests, and open pull requests for code changes.

To set up a local development environment, clone the repository and follow the environment setup guide in the README. You can contribute by improving the translation engine, adding support for new database connectors, or enhancing the UI/UX of the semantic modeling layer.

Community and Support

WrenAI is maintained by Canner and has a dedicated community of data engineers and AI enthusiasts. Support is primarily handled through GitHub Discussions and the official documentation site. You can find detailed conceptual guides on how to build a semantic layer and the installation guides for various environments.

The project is active, with frequent commits and the latest releases being pushed to the GitHub releases page. For real-time collaboration, check the GitHub repository for links to their Discord or community forums.

Conclusion

WrenAI is a powerful tool for organizations that want to democratize data access. By combining a semantic layer with the power of LLMs, it provides a reliable way to translate natural language into SQL, reducing the bottleneck of the data analyst and allowing business users to self-serve their insights.

WrenAI is the right choice when you have a complex database schema and need a high degree of accuracy in your queries. It is not the best choice if you are using a very simple database with no need for a semantic layer or if you are strictly prohibited from using LLM-based translation services.

Star the repo, try the quickstart, and join the community to start transforming your data queries.

What is WrenAI and what problem does it solve?

WrenAI is an open-source Text-to-SQL solution that allows users to query databases using natural language. It solves the "SQL bottleneck" by enabling non-technical users to extract insights from databases without needing to write SQL queries manually.

How do I install WrenAI?

The recommended installation method is via Docker. Clone the repository and run docker-compose up -d to launch all the necessary backend services and the frontend UI.

Which databases does WrenAI support?

WrenAI supports a wide range of databases, including PostgreSQL, MySQL, and SQL Server, among others. This allows it to be integrated into most modern data stacks.

How does WrenAI compare to Vanna.ai?

While Vanna.ai relies more on training the model on your schema and previous queries, WrenAI uses a semantic layer to explicitly define business logic, which ensures higher consistency and accuracy for business-specific terms.

Can I use WrenAI for complex joins?

Yes, WrenAI can handle complex joins across multiple tables based on the relationships defined in its semantic layer. This allows users to ask questions that require data from multiple sources.

What license does WrenAI use?

WrenAI is licensed under the GNU Affero General Public License (AGPL), which means it is open-source and allows for modification and distribution provided the same license is maintained.

Is WrenAI free to use?

Yes, the open-source version of WrenAI is free to use. However, you will need to provide your own API keys for the LLM (such as OpenAI) that the system uses to translate natural language to SQL.