strands-sql
strands-sql is a general-purpose SQL tool for Strands Agents — supports PostgreSQL, MySQL, and SQLite via SQLAlchemy with built-in safety controls.
Installation
Section titled “Installation”# SQLite (no extra driver needed)pip install strands-sql
# PostgreSQLpip install "strands-sql[postgres]"
# MySQLpip install "strands-sql[mysql]"from strands import Agentfrom strands_sql import sql_database
agent = Agent(tools=[sql_database])
# Discover the schemaagent.tool.sql_database(action="schema_summary")
# Run a queryagent.tool.sql_database( action="query", sql="SELECT * FROM orders WHERE amount > 100 LIMIT 20",)
# Describe a tableagent.tool.sql_database(action="describe_table", table="users")Key Features
Section titled “Key Features”- Multi-dialect support: PostgreSQL, MySQL, and SQLite via SQLAlchemy
- Safe by default: read-only mode, row limits, query timeouts
- Access control: table allowlist and blocklist
- LLM-friendly output: Markdown and CSV result formats
- Schema discovery:
list_tables,describe_table,schema_summary - Query execution:
query,execute,explain
Configuration
Section titled “Configuration”Set your database connection via environment variable:
export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"Or pass it directly per call:
agent.tool.sql_database( action="list_tables", connection_string="sqlite:///./local.db",)Troubleshooting
Section titled “Troubleshooting”- No connection string found — make sure
DATABASE_URLis set or passconnection_stringexplicitly. - Write query blocked — write operations require
read_only=Falseexplicitly. - Timeout errors — increase
query_timeout(default: 30s).