Skip to content

SQLAgent

SQLAgent answers questions about the data in your database. You write the question in your own words (“which five products sold best in March?”), the agent checks which tables exist, prepares the query, runs it and answers with the results it obtained. If a query fails, it corrects it and tries again.

It is meant for reading data, not changing it: its instructions forbid it from inserting, changing or deleting records, and ask it to answer only with data it has obtained from the database. Unless you ask for a different number, it limits results to ten rows.

When to use it

  • Letting the sales team look up sales by customer, product or date without writing queries.
  • An internal assistant that answers questions about inventory.
  • Quick reports from order or booking data.
  • Giving another agent the ability to query your database, by connecting it as a tool.

Configuration

ConnectionWhat to connect
Model (required)The AI model that interprets the question and prepares the queries.
Database Info (required)The database to query. Connect the Database Info output of a database component such as MySQL, Postgres SQL, SQL Server or SQLite.
FieldWhat it does
InputThe question to answer, usually from Chat Input.

Advanced options

FieldWhat it does
Extra ToolsConnection for additional tools the agent can use alongside the database.
Handle Parse ErrorsIf the model returns an answer in an unexpected format, the agent tries to recover instead of stopping. Default: on.
VerboseLogs the agent’s steps in detail. Default: on.
Max IterationsThe maximum number of steps (queries and checks) before stopping. Default: 15.

Using it as an agent tool

You can connect this component to an agent’s Tools input. In the Tool tab, Tool Name and Tool Description are the name and explanation the agent uses to recognise the tool and decide when to call it: write a clear description of what it does.

Output

  • Response: the answer to the question as a message. Connect it to Chat Output or to any component that takes text.
  • Agent: the configured agent, to connect it to components that take an agent.
  • Tool: the agent turned into a tool, for another agent’s Tools input.

Example

The distributor Frutas del Valle keeps its orders in a MySQL database. It connects a MySQL component to Database Info, an AI model to Model and Chat Input to Input. From the chat, the sales manager asks: “Which three customers have placed the most orders this quarter?”. The agent queries the orders table and answers with the three customers and their number of orders.

Good practices

  • Connect the database with a user that only has read permission: that way you make sure nothing is changed.