SQL Server LLM Integration

Published
Length
4 min read

Luis Felipe Dias

All posts

A sql server llm integration links an AI model to your Microsoft database so it can run queries. You set this up with a tool bridge, a scoped database user, and query rules. Teams use this setup to answer data questions in plain text. They also use it to debug slow queries and check table structures fast. Still, giving a language model direct access to live data brings real risk. You must control how the model logs in, what it reads, and what it changes. How sql server llm integration works i

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.

A sql server llm integration links an AI model to your Microsoft database so it can run queries. You set this up with a tool bridge, a scoped database user, and query rules.

Teams use this setup to answer data questions in plain text. They also use it to debug slow queries and check table structures fast. Still, giving a language model direct access to live data brings real risk. You must control how the model logs in, what it reads, and what it changes.

How sql server llm integration works in practice

Language models cannot talk to a database network socket on their own. Instead, an agent app sits between the model and your SQL Server instance. The user asks a question in plain words. The model writes a SQL query based on the database schema it knows. Next, the agent app sends that query to the database and returns the rows.

To make this work, an admin creates a database user for the agent. In SQL Server, a database user is the identity of a login for a database. When an agent needs many databases on one instance, admins create a login in master. When an agent needs one or a few databases, a contained database user works well. A contained user has a password and does not tie to a login in master. An admin must enable contained databases on the server and database first.

Once the user exists, the admin assigns a role. SQL Server offers fixed database roles that you cannot change. Every role, including the public role, has basic connect rights. Most teams put their AI agent into the built-in data reader role. Members of this role can read all data from all user tables and views. Admins also add the deny data writer role so the agent cannot change data.

Security tradeoffs of static roles and credentials

Fixed database roles give you a fast way to set up basic rules. Yet they are too broad for most AI agents in production. The built-in data reader role lets the user read every single user table and view. You cannot edit the rights inside a fixed role. If your database holds customer emails or card numbers, the model can read them all.

Admins can block all reads with the deny data reader role. That role stops the user from reading any user tables, views, or metadata. Still, blocking all tables makes the AI agent useless for data tasks. Building custom roles for hundreds of tables takes a lot of time and care.

Kubernetes API Server Access + LLM Access Control: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static passwords also create a big problem for engineering teams. When you store a database password in an agent app, that key stays active all day. If a bad prompt tricks the agent, the attacker gets full read access right away. Even worse, if someone assigns the owner role by mistake, the agent can drop the database.

Database logs also lose track of who asked the first question. The database only sees the shared agent login, not the person using the chat app. To stay safe, teams need a way to check queries before they run. They also need a way to mask sensitive fields like phone numbers and national IDs in results. Masking rewrites matched fields in results before the agent or user processes the response.

Control AI database queries at the wire level

A safer design puts a proxy layer between the AI agent and the database. The agent no longer holds a static password for the database server. Instead, each request ties back to a real user identity from your login provider. You can approve or block specific SQL statements before they touch the database engine.

This setup also fixes the broad table problem of fixed roles. Even if the database user can read all tables, the proxy inspects the data stream. When a query returns emails, card numbers, or phone numbers, masking rewrites matched fields in results. Your team gets clear audit logs that show every query and the person behind it.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

Can an AI agent use a read-only role in SQL Server?

Yes, admins can add the database user to the fixed data reader role. This role lets the agent read all user tables and views without changing data. You can also add the deny data writer role to block all edits.

Should I use a standard login or a contained user for an LLM?

Use a contained database user if the agent only needs one or a few databases. It keeps the user inside that database without a login in the master database. Use a standard login in master if the agent must query many databases on the instance.

How do I stop an LLM from reading sensitive columns in SQL Server?

The fixed data reader role reads all user tables, so it will expose sensitive columns. You must either grant custom table rights or use a proxy that applies data masking. Masking rewrites matched fields like emails and card numbers in results on the fly.

The query runs. The emails stay hidden.