How to Configure LlamaIndex MariaDB Data Masking

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up llamaindex mariadb data masking by pairing restricted database roles with masking rules. You also pass an explicit table list to the query engine at setup time. Teams often link their agent framework to MariaDB with one shared database login. If that role has broad permissions, the query engine pulls all schema context. Then generated SQL can return raw emails, phone numbers, card numbers, and national IDs. How llamaindex mariadb data masking works in practice LlamaIndex uses its S

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 data masking by pairing restricted database roles with masking rules. You also pass an explicit table list to the query engine at setup time. Teams often link their agent framework to MariaDB with one shared database login. If that role has broad permissions, the query engine pulls all schema context. Then generated SQL can return raw emails, phone numbers, card numbers, and national IDs.

How llamaindex mariadb data masking works in practice

LlamaIndex uses its SQLDatabase class as a light wrapper around SQLAlchemy to reach MariaDB. The NLSQLTableQueryEngine turns plain text questions into SQL queries over the tables you name. If you omit that table list, the query engine pulls all the schema context. The framework then runs the generated SQL against MariaDB and reads the returned rows. Those rows go straight into the model prompt so the agent can write answers.

Official LlamaIndex docs warn that running arbitrary SQL queries is a real security risk. The docs recommend precautions like restricted roles, read-only databases, and sandboxing for text-to-SQL apps. In MariaDB, teams create a read-only database user for the SQLAlchemy engine to use. Admins also create database views that rewrite sensitive columns before the agent reads them. Masking rewrites matched fields in results, such as emails, phone numbers, and card numbers. The agent queries those views instead of the base tables during each run.

What native database roles solve and what they leave open

Read-only MariaDB roles stop the agent from dropping tables or changing stored rows. Naming specific tables in LlamaIndex also keeps extra table schemas out of the prompt. Database views can redact fixed columns when every caller uses the exact same view. These native steps control which account logs in and which tables it can read.

Still, static database logins cannot inspect individual SQL statements while they run in flight. Every user asking questions through the app shares the same underlying SQLAlchemy database role. If a table list includes a mixed table, the agent reads every column inside. Views also take constant manual work whenever teams add new tables or columns. Also, static views cannot mask unstructured text blobs that contain emails or national IDs. Database logs only show the shared app user, not which person asked the question.

Data Masking (Static) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why query-level masking matters for text-to-SQL agents

Text-to-SQL engines build new queries on the fly based on user prompts. A user might ask a broad question that pulls thousands of customer records at once. Even with a read-only role, the database still sends back every matched field. When those rows contain card numbers or phone numbers, the model processes that data.

Teams need a way to rewrite sensitive fields in results before the app reads them. Checking results in flight catches emails, phone numbers, card numbers, and national IDs anywhere. This works even when a column name changes or a query joins unexpected tables. It also keeps schema changes from breaking static views across multiple MariaDB instances.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev is an open-source proxy that runs as a sidecar for your MySQL. It reads plain queries, prepared statements, and cursors on the wire.

First, hoop.dev guardrails block banned actions before MySQL runs them. An AI Analyzer you configure can score intent, and hoop.dev data masking rewrites sensitive string columns in results. Every query and verdict goes to the resource audit trail. Find the open-source binary on GitHub.

Frequently asked questions

What happens if I do not pass a table list to NLSQLTableQueryEngine?

Without a table list, the LlamaIndex query engine pulls all schema context from MariaDB. This exposes every table that the SQLAlchemy database role has permission to read.

How does LlamaIndex recommend securing text-to-SQL connections?

LlamaIndex docs state that running arbitrary SQL queries carries a clear security risk. They advise teams to use restricted roles, read-only databases, and sandboxing for text-to-SQL apps.

Which fields can data masking rewrite in MariaDB query results?

Data masking rewrites matched fields in results, including emails, phone numbers, and card numbers. It also rewrites national IDs before the query engine sends rows to the model.

The query runs. The emails stay hidden.