Sqlalchemy nl2sql agent
Project description
SQLAlchemy LLM Agent
sqlalchemy-llm-agent packages a small, batteries-included LangChain agent that can inspect
SQLAlchemy schemas and run ad-hoc SQL queries generated by an LLM. It is helpful when you want
to whether work within cli or build quick administrative panel.
Features
- Only read operations - Gives agent only to use safe sqlqueries.
- Config-driven access control – restrict the agent to a whitelist of tables by name or give
it access to every table in the database via the special
"*"entry.
Installation
pip install sqlalchemy-llm-agent
Quickstart
Below is a minimal end-to-end example that shows how to configure and call the agent. This
example assumes you already have a SQLAlchemy Engine and have run inspect(engine) to
produce an inspector object.
from sqlalchemy import create_engine, inspect
from sqlalchemy_llm_agent import SqlalchemyAgent, SqlalchemyAgentConfig
engine = create_engine("postgresql+psycopg://user:pass@localhost:5432/mydb")
inspector = inspect(engine)
config = SqlalchemyAgentConfig(
api_key="sk-openai-123", # Replace with your actual OpenAI API key
model="gpt-5", # Optional, defaults to gpt-5
tables=["users", "orders"], # Limit the agent to just these tables or ["*"]
row_limit=100,
inspector=inspector,
engine=engine,
)
agent = SqlalchemyAgent(config)
result_rows = agent.query("List the five most recent orders including user email")
for row in result_rows:
print(row)
The agent will automatically:
- Inspect the
usersandorderstables to learn their columns. - Generate a SQL query using the configured LLM (
gpt-5by default). - Execute the query through your SQLAlchemy engine and return the results as a list of dictionaries.
You now have a reusable component that can power chatbots, dashboards, or internal tools that need natural-language access to relational data.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_llm_agent-0.1.2.tar.gz.
File metadata
- Download URL: sqlalchemy_llm_agent-0.1.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8fbe12799041cb5e704b299e3c1c9eec127909c23bf06c18a19c4143ff1a945
|
|
| MD5 |
54a419d53d2d30e552e903545677f5a8
|
|
| BLAKE2b-256 |
1f1eefd06fa5dbbc0bd78f43f0cd0f6ca03006ff4d2847fc1f108a554341e8ae
|
File details
Details for the file sqlalchemy_llm_agent-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_llm_agent-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83cf1a234491fdda365f2b8c2610de59fe03a8a43a84cc86232e323c90adcae0
|
|
| MD5 |
017b4529aa6a466be2f2186c01f4bc13
|
|
| BLAKE2b-256 |
0dd3a80ac753713296649fbe5d9f1e4fc29828bec02849d5cb6cb92830ef5c61
|