Open Source · Multi-Agent AI

Natural language questions. Instant SQL. No SQL knowledge required.

NL-2-SQL Agents is an open source AI agent system that translates plain-English questions into accurate SQL queries, refines them autonomously, and explains every step — across any major database.

Multi
Agent
5+
Databases
Zero
SQL Knowledge
MIT
License
Open Source: NL-2-SQL Agents is MIT licensed and free to embed in your applications. A multi-agent pipeline that handles schema discovery, query generation, refinement, and explanation — all autonomously.

What It Is

A Multi-Agent Pipeline for Accurate SQL Generation

NL-2-SQL Agents orchestrates specialized AI agents that collaborate to turn any natural language question into a correct, optimized SQL query — with full explainability.

Schema Discovery Agent

Automatically introspects your database schema, understands table relationships, and builds a semantic context layer for accurate query generation.

Query Generation Agent

Translates the natural language question into SQL using the schema context, with support for complex JOINs, aggregations, and subqueries.

Refinement Agent

Validates and iteratively improves the generated SQL against the actual schema, catching errors before execution.

Explanation Agent

Generates a plain-English explanation of what the SQL query does — making every result transparent and auditable.

Capabilities

Everything You Need for Natural Language Data Access

NL-2-SQL Agents is built for developers who want to embed intelligent SQL generation into their applications.

Multi-Database Support

Works with PostgreSQL, MySQL, SQLite, Snowflake, and BigQuery out of the box. Pluggable connectors for additional databases.

Agentic Query Refinement

Agents autonomously retry and refine queries that fail validation, dramatically improving accuracy on complex schemas.

Schema-Aware Context

Automatically builds a semantic understanding of your schema — table names, column types, foreign keys, and relationships.

Explainable Results

Every generated query comes with a plain-English explanation. Show your users exactly what data is being retrieved and why.

Embeddable API

Expose NL-2-SQL as a REST API or integrate it directly into your Java, Python, or Node.js application with a clean SDK.

Audit & Safety

Read-only query enforcement, query approval workflows, and full audit logging — safe to deploy in production environments.

LLM Agnostic

Works with OpenAI, Anthropic, Azure OpenAI, and local LLMs via Ollama. Swap models without changing your application code.

MIT Licensed

Fully open source. Self-host it, embed it, extend it — free to use with attribution.

How It Works

NL-2-SQL Agents follows a structured multi-agent pipeline for every query.

Step 1: Connect your database

Provide your database connection string. The Schema Discovery Agent introspects your tables, columns, types, and relationships automatically.

Step 2: Ask in plain English

A user types a question like "Show me total revenue by region for Q1 2025." No SQL knowledge needed.

Step 3: Agents generate & refine

The Query Generation Agent produces the SQL. The Refinement Agent validates it against the schema and iterates until correct.

Step 4: Execute & explain

The query runs safely (read-only by default). The Explanation Agent returns results alongside a plain-English breakdown of what was queried.

Data pipeline visualization

Integration

Embed in Minutes

NL-2-SQL Agents is designed to be embedded directly into your existing applications.

# Python example
from nl2sql_agents import NL2SQLPipeline

pipeline = NL2SQLPipeline(
  db_url="postgresql://...",
  llm="openai/gpt-4o"
)

result = pipeline.query(
  "What were our top 10 customers by revenue last quarter?"
)

print(result.sql)         # Generated SQL
print(result.data)        # Query results
print(result.explanation) # Plain-English explanation
      

REST API

Deploy as a standalone REST service and call it from any language or framework.

Python & Java SDKs

Native client libraries for Python and Java with full async support.

Streaming Results

Stream query results and explanations in real time for responsive UIs.

Open source. Self-hostable. Free.

MIT licensed and free to embed in your applications. Star us on GitHub and help shape the roadmap.