How to Configure OpenAI Agents SDK SQL Server Read Only Access
You set up openai agents sdk sql server read only access by making a restricted database user. Then you give that user a read role and pass its login to the agent tool. Many teams start by giving their agent a broad admin role during tests. That quick shortcut lets a model change rows or drop tables by mistake. A safer path uses strict database roles from day one. How openai agents sdk sql server read only access works An agent needs a database tool to run queries against your data. When the
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 read only access by making a restricted database user. Then you give that user a read role and pass its login to the agent tool. Many teams start by giving their agent a broad admin role during tests. That quick shortcut lets a model change rows or drop tables by mistake. A safer path uses strict database roles from day one.
How openai agents sdk sql server read only access works
An agent needs a database tool to run queries against your data. When the agent runs a task, it calls a function that connects to SQL Server. That function uses a login string that holds a user name and a password. SQL Server checks who the user is before any query runs.
In SQL Server, a database user is the identity of a login inside a database. Teams that need access to many databases on an instance often use a login in master. Teams that need access to just one database can use a contained database user instead. A contained user has a password and does not tie back to a master login. An admin must turn on contained databases on the server and database first. SQL Server supports thirteen types of database users in total.
Once you create the user, you assign it to a fixed database role. You cannot change the permissions that belong to fixed database roles. The built-in reader role lets a user read all data from all user tables and views. You can also add the deny writer role for extra safety. That role stops the user from adding, changing, or deleting data in any table. By contrast, the owner role can do all maintenance tasks and can even drop the database. Every role in the database, including the public role, has permission to connect.
How to scope table permissions for agent tools
The fixed reader role is simple to set up, but it is still very wide. A member of that role can read every user table and view in the database. That includes tables with billing records, secret keys, or private team notes. If your agent only needs order status, the fixed reader role gives too much reach.
To tighten this, database admins skip the fixed reader role for agent accounts. Instead, they make a custom role and grant select rights on a few safe views. They can also apply the deny reader role to block table reads across the board. A user in the deny reader role cannot read data or metadata from user tables. For clear tables, admins grant read rights on specific views that expose only safe columns. This keeps the agent tool focused on the exact tables it needs to answer questions.
Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles solve and what they miss
Native SQL Server roles do a great job of blocking direct write commands. If the agent tries to delete rows or change a table, the database says no. This stops bad prompts from wiping out your core records. It also keeps the agent from creating new tables or changing server settings.
Still, a database role only checks who logs in and which tables they can read. It does not check what an individual select statement does while it runs. An agent with read rights can still pull thousands of rows in a single query. If a user table holds emails, phone numbers, card numbers, or national IDs, the query reads them. Those raw fields then flow straight into the model prompt and your app logs. Masking is needed to rewrite matched fields in results before the agent processes them. Also, every agent call shares the same static login string on the app host. When ten people use the agent, the database log shows only one generic user name. You cannot tell which person or task triggered a slow or risky query.
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 reader role still read sensitive columns?
Yes, the built-in reader role can read all data from all user tables and views. It does not hide columns that hold emails, phone numbers, card numbers, or national IDs. You must use custom views or masking to rewrite matched fields in results.
Should I use a master login or a contained user for an agent?
Use a contained database user if the agent only needs one or a few databases. A contained user stays inside that database and does not need a login in master. An admin must enable contained databases on the server and database before you make one.
How do I make sure an agent can never write data in SQL Server?
Do not put the agent user in the writer role or the owner role. Assign the user to the deny writer role as an extra safeguard. Members of the deny writer role cannot add, change, or delete data in tables.
Related guides
In this post