How to Configure OpenAI Agents SDK SQL Server Guardrails
You set up openai agents sdk sql server guardrails by pairing agent checks with database roles. This setup stops AI tools from changing or dropping your production tables. Most teams start by giving an agent a standard database login. That shortcut creates high risk when a shared account has broad permissions. If an agent writes a bad query, it can delete rows or expose private data. A safer setup limits both the agent code and the database user. How to set up openai agents sdk sql server guar
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 openai agents sdk sql server guardrails by pairing agent checks with database roles. This setup stops AI tools from changing or dropping your production tables. Most teams start by giving an agent a standard database login. That shortcut creates high risk when a shared account has broad permissions. If an agent writes a bad query, it can delete rows or expose private data. A safer setup limits both the agent code and the database user.
How to set up openai agents sdk sql server guardrails
Your first step happens inside the database server itself. In SQL Server, a database user is the identity of a login when it connects. When an account needs many databases on one instance, admins create a login in master. When an agent only needs one database, a contained database user is an option. This user has a password and does not tie to a login in master. An admin must enable contained databases on the server and database first.
After you create the user, you must limit what it can do. SQL Server provides fixed database roles for this job. You cannot change the permissions assigned to fixed database roles. Every role, including the public role, has permission to connect. Never place an AI agent in the database owner role. Members of that role can run all maintenance tasks and drop the database.
Instead, assign the agent to the fixed data reader role. Members of this role can read all data from all user tables and views. You can also add the agent to the fixed deny data writer role. That role stops the user from adding, changing, or deleting table data. If you must block all reads on a database, use the fixed deny data reader role. Members of that role cannot read data or metadata from user tables and views.
How agent checks work with database roles
Database roles form the base layer of your safety setup. The second layer lives inside your agent app. The OpenAI Agents SDK lets you attach input and output checks to your workflow. Input checks inspect the prompt before the model generates a query. They help catch bad requests or prompt tricks early in the run.
Output checks inspect the tool call before the app sends SQL to the server. Your team can write a check that looks for write commands in the query string. If the agent tries to run a delete or update command, the check blocks the run. Combining app checks with a read-only database user gives your team two safety nets.
Kubernetes API Server Access + AI Guardrails: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native roles and SDK checks leave open
Native roles and app checks solve the login and basic command problem. They make sure the agent logs in with a restricted user account. They also block simple write statements from leaving the agent app. Still, this native setup leaves major operational gaps open in production.
First, the fixed data reader role lets the user read all user tables and views. If a table holds emails, phone numbers, card numbers, or national IDs, the agent reads them. The raw results flow straight back into the model context and logs. Native fixed roles do not rewrite matched fields in query results on the fly.
Second, app checks run inside the same process as the agent. Every app needs database credentials stored in its local environment to connect. If you run ten agents across your team, you must manage ten sets of secrets. Also, local code checks do not give security teams one central audit log. Once the login succeeds, SQL Server does not pause risky queries for human approval.
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
Should an AI agent use a master login or a contained user?
Use a contained database user when the agent only needs one or a few databases. This keeps the account inside the target database instead of the master database. An admin must enable contained databases on the server and database first.
Does the fixed data reader role hide sensitive columns from agents?
No, members of the fixed data reader role can read all user tables and views. To hide emails, phone numbers, or card numbers, you need custom permissions or data masking. Data masking rewrites matched fields in results before the agent uses them.
Can we change the permissions inside a SQL Server fixed database role?
No, the permissions assigned to fixed database roles cannot be changed in SQL Server. You can combine fixed roles like data reader and deny data writer on one user. For finer table rules, you must create a custom role instead.
Related guides
In this post