SQL AI Agent node#
The SQL Agent uses a SQL database as a data source. It can understand natural language questions, convert them into SQL queries, execute the queries, and present the results in a user-friendly format. This agent is valuable for building natural language interfaces to databases.
Refer to AI Agent for more information on the AI Agent node itself.
Node parameters#
Configure the SQL Agent using the following parameters.
Data Source#
Choose the database to use as a data source for the node. Options include:
- MySQL: Select this option to use a MySQL database.
- Also select the Credential for MySQL.
- SQLite: Select this option to use a SQLite database.
- You must add a Read/Write File From Disk node before the Agent to read your SQLite file.
- Also enter the Input Binary Field name of your SQLite file coming from the Read/Write File From Disk node.
- Postgres: Select this option to use a Postgres database.
- Also select the Credential for Postgres.
Postgres and MySQL Agents
If you are using Postgres or MySQL, this agent doesn't support the credential tunnel options.
Prompt#
Select how you want the node to construct the prompt (also known as the user's query or input from the chat).
Choose from:
- Take from previous node automatically: If you select this option, the node expects an input from a previous node called
chatInput
. - Define below: If you select this option, enter the Text you want to use as the prompt. You can use expressions here for dynamic content.
Node options#
Refine the SQL Agent node's behavior using these options:
Ignored Tables#
If you'd like the node to ignore any tables from the database, enter a comma-separated list of tables you'd like it to ignore.
If left empty, the agent doesn't ignore any tables.
Include Sample Rows#
Enter the number of sample rows to include in the prompt to the agent. Default is 3
.
Sample rows help the agent understand the schema of the database, but they also increase the number of tokens used.
Included Tables#
If you'd only like to include specific tables from the database, enter a comma-separated list of tables to include.
If left empty, the agent includes all tables.
Prefix Prompt#
Enter a message you'd like to send to the agent before the Prompt text. This initial message can provide more context and guidance to the agent about what it can and can't do, and how to format the response.
n8n fills this field with an example.
Suffix Prompt#
Enter a message you'd like to send to the agent after the Prompt text.
Available LangChain expressions:
{chatHistory}
: A history of messages in this conversation, useful for maintaining context.{input}
: Contains the user prompt.{agent_scratchpad}
: Information to remember for the next iteration.
n8n fills this field with an example.
Limit#
Enter the maximum number of results to return.
Default is 10
.
Templates and examples#
Refer to the main AI Agent node's Templates and examples section.
Common issues#
For common questions or issues and suggested solutions, refer to Common issues.
AI glossary#
- completion: Completions are the responses generated by a model like GPT.
- hallucinations: Hallucination in AI is when an LLM (large language model) mistakenly perceives patterns or objects that don't exist.
- vector database: A vector database stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.
- vector store: A vector store, or vector database, stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.