How to Configure Vercel AI SDK SQL Server Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up vercel ai sdk sql server permissions, create a dedicated database user. Then assign that user a restricted read role instead of full owner rights. Engineering teams often connect AI tools to databases using shared admin accounts. This shortcut helps developers test text-to-SQL features fast. Still, broad permissions let a language model change records or drop whole tables. A bad prompt can also expose private customer data to the user. Scoping the database account is the first step to

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 vercel ai sdk sql server permissions, create a dedicated database user. Then assign that user a restricted read role instead of full owner rights. Engineering teams often connect AI tools to databases using shared admin accounts. This shortcut helps developers test text-to-SQL features fast. Still, broad permissions let a language model change records or drop whole tables. A bad prompt can also expose private customer data to the user. Scoping the database account is the first step to safe AI queries.

How vercel ai sdk sql server permissions work

The Vercel AI SDK runs tool calls on your backend server. Your app takes a user prompt and asks the model to write SQL. The backend then sends that SQL query to your database using a connection string. The database checks the identity in that string before it runs the query. SQL Server uses logins and database users to manage this access.

A database user is the identity of a login inside a single database. If your app needs many databases on one server, use a standard login. This login lives in the master database and maps to a user. If the app needs just one database, use a contained database user. A contained user has a password and does not need a master login. An admin must turn on contained databases on the server and database first. Note that SQL Server offers 13 different types of database users.

Once you create the user, you must assign permissions through roles. All database roles, including the default public role, allow basic database connections. Many teams use the built-in data reader fixed role for AI apps. Members of this reader role can read all data from all user tables. They can also read data from all views in that database. You can also add the deny data writer role for extra safety. That role stops the user from adding, changing, or deleting any table data.

Why native roles are not enough for AI agents

Native database roles solve the basic problem of who can log in. They also stop an AI tool from running write commands or dropping databases. You should never give the database owner role to an AI app. A database owner can change settings, run maintenance, and drop the whole database. You also cannot change the rules assigned to fixed database roles.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, fixed read roles still leave a major gap during live queries. The built-in data reader role lets the app read every single user table. If the AI model writes a wide select query, the database runs it. The role does not check what individual queries do in flight. It cannot tell a safe summary query from a dump of user records.

Sensitive fields like emails, phone numbers, card numbers, and national IDs sit in tables. A standard read role returns all of those columns in plain text. To block specific tables, you must build custom roles and manage grants by hand. Even then, static database grants cannot mask sensitive fields inside allowed rows. Database roles check the user at login, not the data moving in results.

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 use a contained user for my AI app?

Use a contained user if your AI app only reads from one database. It keeps the user account inside that single database without a master login. An admin must enable contained databases on the server and database first.

Does the fixed data reader role block sensitive columns?

No, the built-in data reader role grants read access to all user tables. It also lets the user read all views in the database. To hide specific columns, you must create custom roles or mask data in results.

Can I edit the permissions of a fixed database role?

No, SQL Server does not let you change permissions on fixed database roles. If the built-in reader role is too broad, create a custom role instead. You can also combine roles with deny rules to block specific tables.

The query runs. The emails stay hidden.