How to Configure Vercel AI SDK SQL Server Connect

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a vercel ai sdk sql server connect flow, link a tool call to a database driver. Next, bind that driver to a restricted database user with read-only permissions. Many teams start by reusing an admin account from local testing. When an AI model uses a broad account, one bad query can change or delete rows. How the native vercel ai sdk sql server connect flow works The AI framework runs on your app server and handles tool calls from the model. When a user asks a question, the model pic

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 a vercel ai sdk sql server connect flow, link a tool call to a database driver. Next, bind that driver to a restricted database user with read-only permissions. Many teams start by reusing an admin account from local testing. When an AI model uses a broad account, one bad query can change or delete rows.

How the native vercel ai sdk sql server connect flow works

The AI framework runs on your app server and handles tool calls from the model. When a user asks a question, the model picks a database tool and writes a query. Your server takes that query string and passes it to a SQL Server driver. The driver opens a session using a login or a contained database user.

In SQL Server, a database user is the identity of a login inside a specific database. When an app needs one or a few databases, teams can use a contained database user. This user has a password and is not tied to a login in the master database. An admin must turn on contained databases on the server and database first. SQL Server supports thirteen types of database users in total.

Once the user is set up, you assign a role to limit what the model can do. All roles in SQL Server, including the public role, have permission to connect. To keep the AI agent from changing rows, teams add the user to the fixed reader role. Members of this role can read all data from all user tables and views. You can also add the user to a deny writer role to block data changes.

Where native database roles fall short for AI agents

Native roles are a good first step for locking down an AI tool call. They stop the model from dropping tables or running admin tasks reserved for the owner role. Members of the owner role can do all maintenance tasks and even drop the database. Keeping your AI app out of the owner and writer roles stops destructive writes.

Still, fixed database roles have rules that cannot be changed. The fixed reader role grants read rights across every single user table and view. If a table holds emails, phone numbers, card numbers, or national IDs, the query reads them. The database checks who logs in at the start of the session. It does not inspect what individual queries ask for while they run.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can add a deny reader role, which blocks reads across all user tables and views. Yet this blocks the whole database instead of specific sensitive columns inside one table. Teams also have to manage secret rotation across their app hosts. If multiple AI tools share one SQL login, the database logs show one user name. You cannot tell which user prompt or tool call ran a risky query.

How to scope permissions for AI tool calls

Before you put an AI database tool into production, map out which tables the model needs. Avoid giving the app a login in the master database unless it queries many databases. Create a dedicated user for the AI app and block write actions with the deny writer role. Test your tool definitions to ensure the model only sends select statements.

Even with strict roles, database admins still need visibility into every query the model runs. Standard database setups validate the user at login time and then trust the session. Protecting live data requires checking statements in flight and rewriting sensitive fields in results.

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

What role should I use for a read-only AI database user?

Add the database user to the fixed data reader role and the deny data writer role. This setup lets the user read user tables and views while blocking all data changes.

Should I use a standard login or a contained database user?

Use a contained database user if your AI app only needs one or a few databases. It keeps the user inside the target database without needing a login in the master database.

Can I edit the permissions of a fixed database role in SQL Server?

No, the permissions assigned to fixed database roles in SQL Server cannot be changed. If you need custom table rules, you must create a custom role or filter queries in flight.

The query runs. The emails stay hidden.