Text To Sql Agent banner
langchain-ai langchain-ai

Text To Sql Agent

Data community

Description

A natural language to SQL query agent powered by LangChain. Ask questions about your database in plain English and get accurate SQL queries and results.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

Text-to-SQL Agent

A natural language to SQL query agent powered by LangChain. Ask questions about your database in plain English and get accurate SQL queries and results.

Features

  • Natural language to SQL query conversion
  • Automatic query validation and error correction
  • Support for complex queries (JOINs, aggregations, subqueries)
  • LangSmith integration for tracing and debugging
  • Interactive tutorial notebook included

Demo Database

Uses the [Chinook database](https://github.com/lerocha/chinook-database) - a sample database representing a digital media store with tables for artists, albums, tracks, customers, invoices, and more.

Quick Start

Prerequisites

  • Python 3.11 or higher
  • Anthropic API key (get one here) (Or you can use a different model provider)
  • (Optional) LangSmith API key for tracing (sign up here)

Installation

  1. Clone the repository:
git clone https://github.com/kevinbfrank/text-to-sql-agent.git
cd text-to-sql-agent
  1. Download the Chinook database:
# Download the SQLite database file
curl -L -o chinook.db https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite
  1. Create a virtual environment and install dependencies:
# Using uv (recommended)
uv venv --python 3.11
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e .

# Or using standard pip
python3.11 -m venv .venv
source .venv/bin/activate
pip install -e .
  1. Set up your environment variables:
cp .env.example .env
# Edit .env and add your API keys

Required in `.env`:

ANTHROPIC_API_KEY=your_anthropic_api_key_here

Optional for LangSmith tracing:

LANGCHAIN_TRACING_V2=true
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGCHAIN_API_KEY=your_langsmith_api_key_here
LANGCHAIN_PROJECT=text2sql-agent

Usage

Command Line Interface

Run the agent from t