Skip to content

SQL Query Database Tool

SQL Query Database Tool gives an agent access to a SQL database. When it is asked something that is in your data, the agent writes the query, runs it and answers with the result. If the query fails, the agent gets the error and can correct it and try again.

It receives the connection from the SQLDatabase component, and its Tool output connects to the agent’s Tools input.

When to use it

  • The sales team asks in plain language “How much did we invoice in March?” without knowing how to write queries.
  • An internal assistant checks order status or warehouse stock.
  • You want an agent to prepare reports from the tables in your database.
  • A support agent checks a customer’s details before answering.

Configuration

FieldWhat it does
SQLDatabase (required)The database connection. Connect the output of a SQLDatabase component to it.

Output

The Tool output connects to an agent’s Tools input. Each time the agent uses it, it receives the rows returned by its query or the database error message.

Example

A distributor wants its sales team to ask about sales without requesting reports from the data department.

  1. Add a SQLDatabase component with the access details of the sales database.
  2. Add SQL Query Database Tool and connect the SQLDatabase output to its SQLDatabase field.
  3. Connect the Tool output to the agent’s Tools input.
  4. A sales rep asks “Who were the five customers who bought the most last quarter?”. The agent queries the database and answers with the list.

Good practices

  • Describe in the agent’s instructions which tables exist and what each one holds: it will get the queries right sooner.
  • SQLDatabase: the connection this component needs.
  • Agent: the agent that uses the tool.