How to Configure Vercel AI SDK Postgres Approval
You set up vercel ai sdk postgres approval by pausing tool calls before database runs. A human or rule checks the query first, and then the app runs it. Engineering teams often build AI agents that query databases directly. Many teams give the agent a single database login with broad rights. When a model generates a bad query, broad rights let it delete or expose data. Adding an approval step and strict database roles stops bad queries early. How a vercel ai sdk postgres approval flow works T
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up vercel ai sdk postgres approval by pausing tool calls before database runs. A human or rule checks the query first, and then the app runs it. Engineering teams often build AI agents that query databases directly. Many teams give the agent a single database login with broad rights. When a model generates a bad query, broad rights let it delete or expose data. Adding an approval step and strict database roles stops bad queries early.
How a vercel ai sdk postgres approval flow works
The AI framework lets models pick tools to answer user questions. When the model wants database facts, it creates a tool call with a SQL string. Instead of running the SQL right away, your app holds the request in a pending state. The app sends the pending query to a reviewer in a chat channel or dashboard. The reviewer reads the SQL string and clicks approve or reject. Only after approval does the app send the query to the database.
You must also lock down the database role that the agent uses. In PostgreSQL, the SELECT privilege lets a role read specific columns or whole tables. This same privilege also allows the COPY TO command to export data. You can create group roles to manage privileges for your AI services. Then you grant the agent login membership in that group role. If you only want the agent to read safe data, grant SELECT on safe columns only.
Check your database defaults as well. A special role named PUBLIC gives rights to every role on the system. By default, PUBLIC gets the right to connect to databases and create temporary tables. It also gets the right to run functions and procedures. Object owners can revoke these default rights from PUBLIC to lock down the database. In PostgreSQL 15 and newer, users cannot create objects in the public schema by default. On older or upgraded databases, an admin must revoke that create right from PUBLIC.
Where native roles and app checks fall short
Database privileges decide who logs in and which tables they can touch. They do not inspect what individual SQL statements do in flight. Even with column privileges, a permitted SELECT query can pull millions of rows at once. An approved query might also return sensitive emails, phone numbers, card numbers, or national IDs. Native database roles do not rewrite matched fields in query results on the fly.
Approval Chains & Escalation + AI Agent Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
App-level review code also creates maintenance work for your team. Developers must write custom state logic to pause, store, and resume tool calls. If you run many apps, every app needs its own review logic and database keys. When an engineer leaves or a key leaks, rotating secrets across many apps takes time. Teams need a central way to enforce query reviews and mask sensitive fields in results.
Best practices for safe AI database queries
Start by separating read and write tools in your agent design. Let routine read queries run under a strict, column-limited database role. Route any query that changes data or reads sensitive tables into an approval queue. Always revoke unneeded PUBLIC rights so the agent cannot run hidden functions. Log every prompt, tool call, and reviewer choice so your security team can audit them later.
Check every Postgres query on the wire
Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres. It runs beside your database and reads the Postgres wire protocol. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.
Before a query runs, hoop.dev guardrails check the statement by its effect, table, or pattern. They refuse bad deletes or drops with a real Postgres error. On the way back, hoop.dev data masking rewrites sensitive values in returned rows based on your rules. Every query and verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.
Frequently asked questions
How do you pause a database tool call for human review?
Define the tool without an automatic run step so the app returns the raw SQL parameters. Store those parameters in your app state and wait for a user confirmation signal before querying.
Can PostgreSQL restrict an AI agent to specific table columns?
Yes, PostgreSQL lets an admin grant the SELECT privilege on specific columns of a table or view. The database will reject any query from that role that tries to read other columns.
Why should you check PUBLIC privileges when setting up an AI database role?
Every database role inherits rights granted to the special PUBLIC role by default. Revoking default connect, function execution, and schema creation rights from PUBLIC keeps the agent role strict.
Related guides
In this post