You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/toolkits/databases/postgres.mdx
+95-16Lines changed: 95 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,37 +16,64 @@ import ToolFooter from "@/components/ToolFooter";
16
16
17
17
<Badgesrepo="arcadeai/arcade-postgres" />
18
18
19
-
The Arcade Postgres toolkit provides a pre-built set of tools for interacting with PostgreSQL databases in a read-only manner.
19
+
The Arcade Postgres toolkit provides a pre-built set of tools for interacting with PostgreSQL databases in a read-only manner. This toolkit enables agents to discover database schemas, explore table structures, and execute SELECT queries safely. This toolkit is a companion to the blog post [Designing SQL Tools for AI Agents](https://blog.arcade.dev/sql-tools-ai-agents-security).
20
20
21
21
<Note>
22
-
This toolkit is meant to be an example of how to build a toolkit for a database, and is not intended to be used in production. For production use, we recommend forking this repository and building your own toolkit with use-case specific tools.
22
+
This toolkit is meant to be an example of how to build a toolkit for a database, and is not intended to be used in production. For production use, we recommend forking this repository and building your own toolkit with use-case specific tools.
23
23
</Note>
24
24
25
+
## Key Features
25
26
26
-
This repository demonstrates a few concepts to aid in LLM-powered database interactions.
27
-
* Re-use an existing database pool for all tool calls
28
-
* Enforce read-only access to the database
29
-
* Hint to the LLM that both table and schema discovery is required before executing a query
30
-
* Enforce a limit on the number of rows returned by a query
27
+
This toolkit demonstrates several important concepts for LLM-powered database interactions:
28
+
29
+
***Schema Discovery**: Automatically discover available database schemas
30
+
***Table Exploration**: Find all tables within a specific schema
31
+
***Schema Inspection**: Get detailed column information including data types, primary keys, and indexes
32
+
***Safe Query Execution**: Execute SELECT queries with built-in safety measures
Discover all tables in a specific schema. This tool should be used before any other tool that requires a table name.
74
+
75
+
**Parameters:**
76
+
-`schema_name` (str): The database schema to discover tables in (default: "public")
50
77
51
78
<TabbedCodeBlock
52
79
tabs={[
@@ -61,9 +88,14 @@ Discover all tables in a PostgreSQL database.
61
88
}
62
89
]}
63
90
/>
91
+
64
92
## Postgres.GetTableSchema
65
93
66
-
Get the schema of a table in a PostgreSQL database.
94
+
Get the detailed schema of a specific table. This tool provides column information including data types, primary key indicators, and index information. Always use this tool before executing any query.
95
+
96
+
**Parameters:**
97
+
-`schema_name` (str): The database schema containing the table
98
+
-`table_name` (str): The name of the table to inspect
67
99
68
100
<TabbedCodeBlock
69
101
tabs={[
@@ -78,20 +110,67 @@ Get the schema of a table in a PostgreSQL database.
78
110
}
79
111
]}
80
112
/>
81
-
## Postgres.ExecuteQuery
113
+
114
+
## Postgres.ExecuteSelectQuery
115
+
116
+
Execute a SELECT query with comprehensive clause support. This tool allows you to build complex queries using individual clauses while maintaining safety and performance.
117
+
118
+
**Parameters:**
119
+
-`select_clause` (str): Columns to select (without SELECT keyword)
120
+
-`from_clause` (str): Table(s) to query from (without FROM keyword)
121
+
-`limit` (int): Maximum rows to return (default: 100)
122
+
-`offset` (int): Number of rows to skip (default: 0)
Execute a query on a PostgreSQL database. Be sure that your agent runs the `Postgres.DiscoverTables` and `Postgres.GetTableSchema` tools before executing a query.
165
+
## Usage Workflow
166
+
167
+
For optimal results, follow this workflow when using the Postgres toolkit:
168
+
169
+
1.**Discover Schemas**: Use `discover_schemas` to see available schemas
170
+
2.**Discover Tables**: Use `discover_tables` with your target schema
171
+
3.**Get Table Schema**: Use `get_table_schema` for each table you plan to query
172
+
4.**Execute Query**: Use `execute_select_query` with the schema information
173
+
174
+
This workflow ensures your agent has complete information about the database structure before attempting queries, reducing errors and improving query performance.
0 commit comments