How to Configure OpenAI Agents SDK SQL Server Credentials
You set up openai agents sdk sql server credentials by creating a database user. Then you pass those login details to the agent tool that runs queries. Teams often start by reusing a broad admin login to make testing fast. If an agent uses an owner role, a bad prompt can drop the database. Scoping the database user is the first step toward safe agent runs. How openai agents sdk sql server credentials work in practice The agent framework uses Python functions as tools to reach external data sy
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 credentials by creating a database user. Then you pass those login details to the agent tool that runs queries. Teams often start by reusing a broad admin login to make testing fast. If an agent uses an owner role, a bad prompt can drop the database. Scoping the database user is the first step toward safe agent runs.
How openai agents sdk sql server credentials work in practice
The agent framework uses Python functions as tools to reach external data systems. You write a tool function that opens a database session and runs a query. That function reads the database login details from your local secret store. When the model needs data, it calls your tool with a query string.
On the database side, a database user is the identity of a login. SQL Server offers thirteen distinct types of database users for different needs. If an agent needs many databases on one instance, use a standard login. That login lives in the master database and maps to a user per database.
If your agent only needs one database, you can use a contained database user. This user has a password and is not tied to a master login. An admin must first enable contained databases on the server and the database. Both choices let you isolate the identity that the agent tool uses.
After you create the user, you assign it to a fixed database role. The permissions assigned to fixed database roles cannot be changed. Every database role, including the public role, has basic permission to log in. A read-only agent should join the fixed role that only reads user tables. You can also add the role that blocks all data writes for safety. Avoid the owner role, as it can change settings and drop the database.
What native roles solve and what they leave open
Fixed database roles do a good job of stopping unplanned writes or table drops. A read-only role lets the agent read all data from all user tables. If the agent tries to delete rows, the database blocks the command right away. You can also use a deny role to block reads across all user tables.
Still, native database roles decide who logs in, not what each query does. A read-only fixed role grants read access to every user table and view. It does not stop an agent from reading sensitive columns inside those allowed tables. If a table holds emails, phone numbers, card numbers, or national IDs, queries return them.
Ephemeral Credentials + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static credentials also create day-to-day operational work for your engineering team. The agent host must hold the password in memory to open the database session. If someone steals that environment variable, they can run queries from outside your app. Native roles also do not tie a specific SQL statement back to an agent run. Database logs only show the shared user account that ran the text query. Teams need a way to inspect queries in flight and rewrite sensitive fields.
Scoping tables and handling sensitive results
To limit what an agent reads, do not rely on the fixed read role alone. Create a custom role or specific views that only expose safe tables and columns. When you restrict the schema context, the agent only sees the tables it needs. This step also keeps the model from pulling the entire database schema into memory.
Even with clean views, some business workflows need tables that hold private user fields. Data masking rewrites matched fields like emails or card numbers in query results. This approach lets the agent answer questions while keeping private values out of prompts. Combining narrow database roles with runtime controls gives your team a safer setup.
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 I use a master login or a contained user for my agent?
Use a contained user if your agent only reads from one or two databases. It keeps the user password inside the target database instead of the master database. If the agent queries many databases on one server, a master login is simpler.
Why is the default read-only fixed role risky for AI agents?
The fixed read-only role allows reading all data from every user table and view. An agent using that role can pull sensitive rows like card numbers or emails. You must pair role limits with column rules or result masking to protect data.
Can I edit the permissions of a fixed database role in SQL Server?
No, the permissions assigned to fixed database roles cannot be changed by admins. If you need custom table or column rules, create a new user-defined database role. Then grant read permissions only on the specific views or tables your agent needs.
Related guides
In this post