Skip to main content
SQLTools enable an Agent to run SQL queries and interact with databases.

Prerequisites

The following example requires the sqlalchemy and openai libraries and a database URL.
You will also need to install the appropriate Python adapter for the specific database you intend to use.

PostgreSQL

For PostgreSQL, you can install the psycopg adapter:

MySQL

For MySQL, you can install the mysqlclient adapter:
The mysqlclient adapter may have additional system-level dependencies. Please consult the official installation guide for more details. You will also need a database. The following example uses a Postgres database running in a Docker container.

Example

The following agent will run a SQL query to list all tables in the database and describe the contents of one of the tables.
cookbook/91_tools/sql_tools.py

Toolkit Params

Toolkit Functions

Developer Resources