How to Configure Pydantic AI SQL Server Approval
You set up pydantic ai sql server approval by pausing agent tool calls for human review. Your app holds the generated query until a reviewer approves it to run. Many teams start by giving their agent a basic database login and role. If that role is too broad, a bad prompt can change or drop tables. How pydantic ai sql server approval works in practice An AI agent builds SQL queries based on user questions and schema data. In your app, you define a database tool that the model can call. Instea
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 pydantic ai sql server approval by pausing agent tool calls for human review. Your app holds the generated query until a reviewer approves it to run. Many teams start by giving their agent a basic database login and role. If that role is too broad, a bad prompt can change or drop tables.
How pydantic ai sql server approval works in practice
An AI agent builds SQL queries based on user questions and schema data. In your app, you define a database tool that the model can call. Instead of running the query right away, the tool sends the text to a queue. A person on your team checks the SQL statement in a chat app or dashboard.
If the person clicks approve, the app sends the query to the database. On the database side, an admin sets up a login in the master database. That login maps to a specific database user for the app. For one database, an admin can enable and use a contained database user with a password.
Admins then place that user into a fixed database role to limit actions. For read tasks, teams add the user to the datareader role. Members of that role can read all data from all user tables and views. If the agent must write data, teams add the datawriter role. That role lets the user add, delete, or change data in all user tables.
What native roles solve and where gaps remain
Native database roles control who can log in and what tables they can touch. You can block writes by adding the denydatawriter role to the agent user. You can also block reads on all user tables with the denydatareader role. These fixed database roles have set permissions that you cannot change.
If someone puts the agent in the owner role, the risk grows fast. The owner role can do all maintenance tasks and even drop the database. Native roles only check permissions at login and table level. They do not inspect what an individual statement does in flight.
Approval Chains & Escalation + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
A user in the datareader role can still read every user table and view. That means the agent can pull emails, phone numbers, card numbers, or national IDs. App-level review catches some bad queries, but developers must maintain custom review code. Every new script or agent needs the same review logic built from scratch.
Designing a safer review workflow for agent queries
A strong setup separates read queries from write queries before they reach the server. You can let safe read queries run while holding write queries for a human check. The reviewer should see the exact statement and the user who asked for it. Once approved, the query runs once and the log records the decision.
You also need a way to handle sensitive columns during read tasks. Data masking rewrites matched fields like emails or card numbers in the query results. This keeps raw personal data out of the model context while keeping queries working.
Govern SQL Server queries and responses in flight
Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev is an open-source proxy that sits next to SQL Server as a sidecar for your SQL Server. It inspects TDS batches and parameterized queries in real time.
With hoop.dev guardrails and hoop.dev data masking, banned statements are refused with your message. Matched sensitive fields in supported result columns are masked in memory, and each decision is logged per listener. Check out the code on GitHub.
Frequently asked questions
Can I restrict an AI agent to read-only queries in SQL Server?
Yes, add the database user to the fixed datareader role. You can also add the denydatawriter role to block all data changes. Keep in mind that datareader still allows reading all user tables and views.
Should an AI agent use a master login or a contained user?
Use a contained database user if the agent only needs one or a few databases. An admin must first enable contained databases on the server and database. Use a login in master if the user needs many databases on the instance.
Why is app-level query review hard to scale across teams?
App-level review lives inside one codebase and only checks that single app. If another team builds a second agent, they must write the review flow again. It also does not rewrite sensitive fields like phone numbers or national IDs in results.
Related guides
In this post