SQL Query Database Tool
The SQL Query Database Tool lets you run SQL commands against a database that you have connected to Nappai. It creates a reusable “tool” that can be called by other parts of your workflow, such as an LLM component, to fetch or modify data.
How it Works
When you add this component to your dashboard, you simply point it at a database connection (the SQLDatabase input). Internally, the component builds a CustomQuerySQLDataBaseTool
that knows how to talk to that database. The tool is then exposed as an output so that other components can use it to execute SQL statements on demand. No code is required—just connect the database and let the tool handle the rest.
Inputs
- SQLDatabase: The database connection you want to query. Provide a connection that has the necessary permissions for the queries you plan to run.
Outputs
- Tool: A
Tool
object (specifically aBaseTool
) that can be passed to other components, such as an LLM, to execute SQL queries. The tool carries the database connection and any metadata needed for the workflow.
Usage Example
- Add a Database Connection – Drag a “Database Connection” component onto the canvas and configure it with your database credentials.
- Add the SQL Query Database Tool – Connect the output of the Database Connection to the SQLDatabase input of this component.
- Use the Tool in an LLM – Drag an “LLM” component, and in its settings choose “Use Tool” and select the Tool output from the SQL Query Database Tool.
Now the LLM can ask the database directly, e.g., “What is the total sales for last month?” and the tool will run the appropriate SQL query and return the result.
Related Components
- Database Connection – Create and manage connections to various databases.
- LLM – Natural‑language model that can call tools like the SQL Query Database Tool.
- SQL Query Executor – A component that runs a fixed SQL query without the tool abstraction.
Tips and Best Practices
- Validate Queries – Test your SQL statements in a safe environment before connecting them to the tool.
- Use Parameterized Queries – When possible, pass parameters instead of embedding user input directly to avoid SQL injection.
- Limit Permissions – Grant the database user only the permissions needed for the queries you intend to run.
- Monitor Usage – Keep an eye on query performance and logs to catch slow or problematic queries early.
Security Considerations
- The tool executes SQL with the credentials of the database connection you provide.
- Ensure that the database user has the least privileges required for your tasks.
- Avoid exposing sensitive data in query results unless you have proper access controls in place.
- If you share the workflow with others, be mindful that they can run arbitrary SQL through the tool.