How to Configure LlamaIndex SQL Server Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up llamaindex sql server credentials by passing a database login to the SQLAlchemy wrapper. You then map that login to a read-only database user inside SQL Server. Many teams start by reusing an admin account during early tests. That choice gives the AI agent power to change or drop tables. A safer plan uses a dedicated user with strict read permissions. How llamaindex sql server credentials work LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. It

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 llamaindex sql server credentials by passing a database login to the SQLAlchemy wrapper. You then map that login to a read-only database user inside SQL Server. Many teams start by reusing an admin account during early tests. That choice gives the AI agent power to change or drop tables. A safer plan uses a dedicated user with strict read permissions.

How llamaindex sql server credentials work

LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. Its natural language query engine turns plain questions into SQL queries over your tables. If you do not name specific tables, the engine pulls all schema context. The framework then runs those generated SQL statements using your database login.

In SQL Server, a login lets an app reach the server instance. A database user is the identity of that login inside one database. For access to many databases, teams create a login in the master database. For one or a few databases, admins can use a contained database user. A contained user has its own password and does not need a master login. An admin must first enable contained databases on the server and database.

Setting up read-only database roles

LlamaIndex docs note that running arbitrary SQL queries is a security risk. They suggest using restricted roles, read-only databases, and sandboxing to lower this risk. SQL Server offers fixed database roles to help you limit what an agent does. You cannot change the permissions assigned to these fixed database roles.

Admins often add the agent user to the fixed data reader role. Members of this role can read all data from all user tables and views. You can also add the user to the deny data writer role. That role stops the user from adding, changing, or deleting table data. Never put an AI agent in the database owner role. The owner role can change settings, run maintenance, and drop the whole database.

What native database roles leave open

Database logins and roles control who can log in to the server. They do not inspect what individual queries do while they run. A member of the fixed data reader role can still read every user table. If you forget to list allowed tables in LlamaIndex, the engine reads all schemas.

Ephemeral Credentials + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Even with a table list in code, the database user still has broad read rights. A bad prompt can trick the query engine into joining sensitive tables. The query might return customer emails, phone numbers, card numbers, or national IDs. Standard database roles cannot rewrite matched fields in results before the model reads them.

Static passwords in app settings also create ongoing work for your team. Someone must rotate those keys and update every app server by hand. If a developer copies the connection string to a laptop, the key spreads. Native roles also do not require human approval before a heavy query runs. A poor text-to-SQL query can scan millions of rows and slow the server.

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 runs beside the database as a sidecar for your SQL Server and checks TDS traffic without changing how clients log in.

With hoop.dev SQL Server controls, rules refuse banned statements before they run and can hold risky queries for human review. Matched sensitive values in supported result columns are masked before they reach the client. 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

Should I use a master login or a contained user for LlamaIndex?

Use a contained database user if the agent only needs one database. It keeps the account inside that database and skips the master database login. If the agent must read across many databases, use a standard master login.

Does the SQL Server data reader role hide sensitive columns?

No, the fixed data reader role lets the user read all user tables and views. You cannot change the permissions of a fixed role to block specific columns. To hide emails or card numbers, you need separate views or row-level rules.

What happens if I do not specify tables in the LlamaIndex query engine?

If you leave out the table list, the engine pulls all schema context. This sends extra table details to the model and widens what queries it writes. Always name the exact tables the agent needs for its task.

The query runs. The emails stay hidden.