> For the complete documentation index, see [llms.txt](https://docs.canso.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.canso.ai/ai-agents/toolkit/sql-runner.md).

# SQL Runner

The SQL Runner Tool (CansoSQLRunnerTool) is a tool in Canso toolkit that enables AI agents to execute SQL queries against databases. It delegates the execution of the SQL queries to the [Task Server](/ai-agents/concepts/task-server.md), where the queries are executed, and results are returned to the AI Agent.

### Usage

The constructor for the CansoSQLRunnerTool has following parameters:

| Parameter     | Description          | Example            |
| ------------- | -------------------- | ------------------ |
| `db_host`     | Database hostname    | `"db.example.com"` |
| `db_port`     | Database port        | `"5432"`           |
| `db_username` | Database username    | `"db_user"`        |
| `db_password` | Database password    | `"password123"`    |
| `db_name`     | Target database name | `"my_database"`    |

The input parameters for the tool, provided at runtime by the workflow or the agent, include:

| Parameter | Description          | Example                 |
| --------- | -------------------- | ----------------------- |
| `query`   | Query to be executed | `"select * from table"` |

The following code snippet illustrates how the CansoSQLRunnerTool can be integrated with your AI Agent.

```python
from gru.tools import CansoSQLRunnerTool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import ToolNode

sql_tool = CansoSQLRunnerTool(
    db_host="db.example.com",
    db_port="5432",
    db_username="db_user",
    db_password="password123",
    db_name="my_database"
)

tools = [sql_tool]
tool_node = ToolNode(tools)

model = ChatOpenAI(model="gpt-4o", temperature=0,  max_tokens=None, timeout=None, max_retries=2,)
model = model.bind_tools(tools)

```

## Tool Tips

* Go to [Toolkit](/ai-agents/toolkit.md) ⬅️
* See [Kubernetes Job Tool](broken://pages/gevaokF9PzqAPLiVJyfG) ➡️
* Learn about [Task Server](/ai-agents/concepts/task-server.md) ➡️
* Explore [Examples](https://github.com/Yugen-ai/gru/blob/main/gru_docs/ai-agents/examples.md) ➡️


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.canso.ai/ai-agents/toolkit/sql-runner.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
