LangChain SQL Tools icon

LangChain SQL Tools

python.langchain.com

LangChain provides SQLDatabaseToolkit and SQL Agent capabilities for building text-to-SQL applications with LLM orchestration. Open-source (MIT license) Python and JavaScript libraries.

Visit WebsiteText-to-SQLOpen Source

The SQLDatabaseToolkit wraps database connections with tools for schema introspection, query execution, and error handling that LLMs can use autonomously. SQL Agent provides ReAct-style reasoning, the LLM iteratively explores schema, generates queries, executes them, and refines based on results. Supports PostgreSQL, MySQL, SQLite, SQL Server, and any SQLAlchemy-compatible database. Key components include SQLDatabase (connection wrapper), QuerySQLDataBaseTool (query execution), InfoSQLDatabaseTool (schema retrieval), and ListSQLDatabaseTool (table listing). Few-shot example injection and custom prompting enable accuracy improvements. Integration with vector stores enables RAG-enhanced query generation. For production: combine with LangSmith for tracing and evaluation.

Tags

Popular tags