How to Configure OpenAI Agents SDK SQL Server Prevent Delete
To set up an openai agents sdk sql server prevent delete rule, restrict the database user role. You must remove delete rights from the account that your agent uses to log in. Many teams connect AI agents to databases using a single shared admin login. This broad role lets the agent read, change, or drop any table by mistake. When a model writes a bad query, wide permissions turn a small bug into data loss. How to set up openai agents sdk sql server prevent delete rules In this framework, an a
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.
To set up an openai agents sdk sql server prevent delete rule, restrict the database user role. You must remove delete rights from the account that your agent uses to log in. Many teams connect AI agents to databases using a single shared admin login. This broad role lets the agent read, change, or drop any table by mistake. When a model writes a bad query, wide permissions turn a small bug into data loss.
How to set up openai agents sdk sql server prevent delete rules
In this framework, an agent reaches a database through custom tool functions or model context servers. Your Python code holds the database login string and runs the queries that the model writes. The agent framework itself does not parse SQL or block delete commands before they run. Instead, you must enforce rules inside the database engine using logins and database users.
A database user is the identity of a login when it connects to a database. For access to many databases on one instance, a SQL user with a main login works well. For one or a few databases, you can use a contained database user with a password. An admin must enable contained databases on the server and the database first.
Once you create the user, you assign roles to control what the agent can do. Fixed database roles have set permissions that you cannot change. The data reader role lets the user read all data from all user tables and views. The data writer role lets a user add, delete, or change data in all user tables. To block all writes and deletes, add the user to the deny data writer role. If the agent needs to add rows or update records, do not use fixed writer roles. Instead, create a custom role that grants read, insert, and update rights while denying delete rights.
Why database roles leave a runtime gap for AI agents
Native database roles decide who logs in and which broad actions that account can take. They stop an agent from running a delete statement when the user lacks delete rights. Still, static roles do not inspect individual queries or check the context of a request in flight.
An agent with update rights can still overwrite every row in a table if a filter fails. A read-only agent can still pull millions of sensitive rows into model memory at once. Database roles also cannot mask sensitive fields like emails, phone numbers, card numbers, or national IDs. When the database returns raw results, those fields go straight into the agent prompt history.
SQL Injection Prevention + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing separate database users for each agent task also creates extra work for engineering teams. Every time an agent needs a temporary write action, an admin must alter role memberships by hand. Teams also have to rotate static passwords stored inside agent environment files across every host. Native roles solve basic table access, but they cannot govern live query traffic or protect sensitive fields.
How to test your agent database permissions
Before you put an agent into production, you should test the database user account directly. Log in with the agent credentials and try to run a delete statement on a test table. The database engine should reject the command and return a permission error right away.
Next, run your agent workflow and ask the model to remove a test record. Make sure your tool function catches the database error and returns a clear message to the model. Without clear error handling, the agent might retry the blocked delete command in a loop. Good error messages help the agent stop and report that the action is not allowed. You should also check your database logs to confirm that failed delete attempts appear with the agent user name.
Check SQL Server batches and results on the wire
SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server. It reads plain batches and parameterized queries on the TDS wire while passing Windows login through untouched.
Before a batch hits the server, hoop.dev guardrails check the statement against your rules. Disallowed actions get a native TDS error with your message. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns that match your rules. Every query and decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Can the fixed data writer role block delete commands in SQL Server?
No, the fixed data writer role lets a user add, change, and delete data across all tables. You cannot change the permissions of a fixed role, so you must deny delete rights separately.
Does the OpenAI Agents SDK block destructive SQL queries on its own?
No, the framework only runs the Python tool functions or servers that you give to the agent. It does not inspect SQL text, so your database user or runtime tools must block bad queries.
What happens if I add an agent user to the database owner role?
The database owner role can run all setup and maintenance tasks and can even drop the whole database. Never give this role to an AI agent because a bad prompt could destroy your data.
Related guides
In this post