How to Configure OpenAI Agents SDK SQL Server Connect

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openai agents sdk sql server connect workflow by giving your agent a database tool. This tool uses a SQL login and a narrow database role to run queries. Many teams start by giving the agent a broad role to save time. That choice lets the agent change or delete rows across every user table. A safer setup pairs a strict SQL Server user with clear query limits. How an openai agents sdk sql server connect workflow works The agent framework uses custom functions or server tools to r

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 an openai agents sdk sql server connect workflow by giving your agent a database tool. This tool uses a SQL login and a narrow database role to run queries. Many teams start by giving the agent a broad role to save time. That choice lets the agent change or delete rows across every user table. A safer setup pairs a strict SQL Server user with clear query limits.

How an openai agents sdk sql server connect workflow works

The agent framework uses custom functions or server tools to reach external data. You write a small function that opens a database session when the agent needs facts. The model decides when to call that function based on the user prompt. Your app then sends the query to SQL Server and returns the rows.

On the database side, SQL Server checks who is logging in first. A database user is the identity of a login inside a specific database. Teams that need access to many databases often create a login in the master database. If the agent only needs one database, you can use a contained database user. This user has its own password and does not need a login in master. An admin must enable contained databases on the server and database first.

After you create the user, you assign a fixed database role. Every database user starts in the public role, which includes the basic permission to connect. To let the agent read tables, admins often add the user to the datareader role. Members of this role can read all data from every user table and view. If you also add the deny datawriter role, the user cannot add, change, or delete rows. Fixed database roles have set permissions that you cannot alter.

Why native roles leave a gap for AI agents

Native SQL Server roles control who can log in and which tables they can read. They do not inspect the specific SQL statements that an agent writes in real time. Even a read-only datareader role lets the agent read every user table and view. You cannot change that fixed role to hide one sensitive table or column.

When an agent can read all tables, it can pull emails, phone numbers, or card numbers. The database returns those raw values straight into the model prompt. An agent can also write a huge join that slows down the whole server. Static database credentials also sit in your app settings where scripts can read them. Native roles solve login checks, but they cannot check or mask individual queries in flight.

Kubernetes API Server Access + OpenAI API Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Steps to tighten native database permissions

You can reduce risk by avoiding the database owner role for any agent workload. A database owner can change server settings, run maintenance, and even drop the database. Instead, create a dedicated user just for your agent app. Do not share human admin accounts with automated agent tools.

If the built-in datareader role is too wide, skip fixed roles for that user. Grant read access only on the specific views or tables the agent needs. You can also create safe views that leave out columns with national IDs or card numbers. This keeps the agent focused on safe data while your team builds out stronger controls.

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

Should I give an AI agent the database owner role in SQL Server?

No, you should never assign the database owner role to an agent. That role lets the user change settings, alter tables, and drop the whole database. Always give the agent a narrow user account that can only read needed tables.

What is the difference between a SQL Server login and a contained user?

A standard login lives in the master database and works across many databases on the server. A contained database user stays inside one database and uses its own password to log in. Contained users work well when an agent only needs data from a single database.

Does the built-in datareader role hide sensitive columns from my agent?

No, the fixed datareader role lets the user read all data in all user tables and views. You cannot change the permissions of a fixed database role to hide specific columns. To hide emails or phone numbers, you must use custom views or mask results in flight.

The query runs. The emails stay hidden.