How to Configure LlamaIndex MySQL Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a llamaindex mysql prevent delete rule, assign a read-only database role. You must also restrict the tables your AI agent can inspect and query. Teams often start by giving the agent a broad database account for testing. If that account stays in production, a bad prompt can wipe out live records. How llamaindex mysql prevent delete setups work LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. Its natural language query engine turns user questions

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 a llamaindex mysql prevent delete rule, assign a read-only database role. You must also restrict the tables your AI agent can inspect and query. Teams often start by giving the agent a broad database account for testing. If that account stays in production, a bad prompt can wipe out live records.

How llamaindex mysql prevent delete setups work

LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. Its natural language query engine turns user questions into SQL statements and runs them. When you do not pass a specific list of tables, the engine pulls all schema context. That wide view lets the language model see and target every table in your database.

The official docs warns that running arbitrary generated SQL is a real security risk. It recommends using restricted roles, read-only databases, and sandboxing to keep data safe. At the database level, admins create a dedicated MySQL user for the AI app. They grant select permissions on chosen tables and withhold delete, drop, and truncate privileges.

When the query engine sends a delete statement, MySQL checks the account grants. The database engine blocks the statement and returns a permission error to the app. You can also point the SQLAlchemy engine at a read-only replica instead of the primary writer. This setup ensures that even a tricked model cannot erase primary business data.

What native database roles solve and what they miss

Database roles and read-only replicas stop an agent from running destructive commands. They decide which account can log in and which tables that account can touch. This works well when your AI app only needs to read public reports.

Still, many workflows need the agent to insert notes or update status rows. Once you grant write access on a table, role privileges become blunt tools. MySQL grants apply to the whole session and the entire table or column. A role cannot tell a safe one-row update apart from a bulk update without a filter.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Also, static database grants do not stop the agent from reading sensitive fields. If a permitted table holds emails, phone numbers, card numbers, or national IDs, select access exposes them. The language model receives those raw values in its prompt context and may repeat them.

Inspecting queries and results in flight

Closing this gap requires checking each SQL statement before the database runs it. Instead of relying only on account login grants, teams inspect the query text in flight. A statement check can reject any delete command or any update missing a strict filter. This allows the agent to add new records while blocking destructive changes.

Runtime checks also help teams protect private customer records during read queries. Data masking rewrites matched fields in results, such as emails, phone numbers, or card numbers. The query still finishes, and the agent gets safe placeholders instead of real personal details. Teams also gain a clear audit log showing which prompt triggered each SQL query.

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

Does LlamaIndex block delete queries on its own?

No, the natural language SQL engine runs whatever SQL statement the model generates. Its docs states that running arbitrary SQL is a security risk and advises external safeguards.

How do I limit which MySQL tables LlamaIndex can see?

Pass an explicit list of allowed tables when you set up the query engine. Without that list, the wrapper pulls all schema context from the database.

Is a read-only MySQL user enough for AI agents?

A read-only user stops delete and drop commands across the whole database session. It does not mask emails or card numbers in results or allow safe, scoped writes.

The query runs. The emails stay hidden.