How to Configure LlamaIndex MariaDB Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up llamaindex mariadb least privilege by creating a read-only database role and naming allowed tables. This stops the AI agent from changing data or reading your whole schema. Many teams start by giving their app an admin database user to move fast. Broad permissions let a bad prompt drop tables, edit rows, or read secret data. LlamaIndex docs warn that running generated SQL brings real security risks. How llamaindex mariadb least privilege works in practice LlamaIndex connects to Mar

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 mariadb least privilege by creating a read-only database role and naming allowed tables. This stops the AI agent from changing data or reading your whole schema. Many teams start by giving their app an admin database user to move fast. Broad permissions let a bad prompt drop tables, edit rows, or read secret data. LlamaIndex docs warn that running generated SQL brings real security risks.

How llamaindex mariadb least privilege works in practice

LlamaIndex connects to MariaDB through a light wrapper around SQLAlchemy. Its text-to-SQL query engine turns plain English questions into live SQL statements. The engine then runs those generated statements against your MariaDB database. If you do not name specific tables, the engine pulls all schema context. That wastes tokens and exposes sensitive tables to the language model.

A proper llamaindex mariadb least privilege setup starts inside the database itself. First, an admin creates a dedicated MariaDB user just for the AI app. Next, you grant that user select privileges only on the few tables it needs. You also leave out insert, update, delete, and drop permissions on every schema. Then, you pass that explicit table list to the LlamaIndex query engine. The framework only reads metadata for those named tables when building prompts. Official LlamaIndex guides also suggest sandboxing and read-only databases to reduce risk.

What native database roles solve and what they miss

Native MariaDB roles do a great job of blocking write commands and schema changes. If the model writes a drop or update query, MariaDB blocks it right away. Naming tables in LlamaIndex also keeps extra table names out of the prompt context. These two steps form a solid base for any text-to-SQL app.

Still, database roles only check who logs in and which tables they can read. A read-only user can still read every row and column inside an allowed table by default. If a customer table holds emails, phone numbers, or card numbers, queries return them. The language model receives those raw values and can repeat them in answers. Native grants also cannot pause a risky select query for human approval in flight. Also, standard database logs only record the shared app user, not the end user.

Least Privilege Principle + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Closing the gap for text-to-SQL workloads

Teams running AI agents in production need controls that work on live queries and results. You should pair restricted MariaDB roles with statement checks and data masking. When a query runs, masking rewrites matched fields like emails or national IDs in results. That way, the app still works, but raw sensitive values do not reach the model. You also want audit logs that tie each generated query to a real identity. Combining database grants with runtime checks gives your team full control over agent queries.

Add wire guardrails and masking beside MySQL

Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev runs beside the database as a sidecar for your MySQL. It keeps your login setup and drivers as they are while checking queries on the wire.

With hoop.dev MySQL support, guardrails refuse bad queries before they run and return a readable MySQL error. Data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.

Frequently asked questions

Why does LlamaIndex pull the whole MariaDB schema by default?

The text-to-SQL engine needs table names and columns so the model can write valid SQL. If you do not pass a table list, it loads every table the user sees.

Is a read-only MariaDB user enough for text-to-SQL safety?

A read-only role stops data changes, which LlamaIndex docs recommend as a key step. Still, it still lets the agent read sensitive columns like card numbers inside allowed tables.

How do I limit which tables LlamaIndex can query in MariaDB?

Grant the MariaDB user select access only on the specific tables the app needs. Then pass that exact same list of table names when you set up the query engine.

The query runs. The emails stay hidden.