How to Configure LlamaIndex MySQL Approval

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a llamaindex mysql approval workflow by adding human review before running queries. You also restrict the database user role to read-only permissions. Teams often connect AI apps straight to a live database with a shared account. This broad setup lets the model read every table and run risky statements. A bad prompt can trigger slow queries or expose private customer rows. How native llamaindex mysql approval and database roles work LlamaIndex connects to relational databases throu

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 a llamaindex mysql approval workflow by adding human review before running queries. You also restrict the database user role to read-only permissions. Teams often connect AI apps straight to a live database with a shared account. This broad setup lets the model read every table and run risky statements. A bad prompt can trigger slow queries or expose private customer rows.

How native llamaindex mysql approval and database roles work

LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. Its natural language query engine turns user questions into SQL statements. You can pass a list of allowed tables to the query engine. If you skip this list, the engine pulls all schema context from the database. Pulling the whole schema eats up token limits and exposes internal table names.

The engine does not just draft SQL text for you to read. It runs the generated SQL query against your MySQL server and returns the answer. Official LlamaIndex docs warn that running arbitrary SQL queries is a security risk. The docs advise teams to use restricted roles, read-only databases, and sandboxing. Native MySQL does not have a built-in pause button for single queries. Teams must build custom Python callbacks to hold a query for human sign-off. A reviewer checks the drafted statement and clicks approve in a chat app. Only then does the app send the query to the SQLAlchemy engine.

What native controls solve and what they miss

Setting up a read-only MySQL user stops the agent from dropping tables. It also blocks the app from changing rows or deleting records. Limiting the table list in LlamaIndex keeps the model focused on safe schemas. Custom callback steps let a human check the query text before it runs. Together, these steps cut down the risk of accidental data loss.

Yet database roles only check who logs in at the start of a session. They do not inspect what individual statements do in flight. A read-only user can still run a huge join that locks up MySQL. An approved select query can still pull thousands of emails, phone numbers, or card numbers. Custom app callbacks are also hard to keep consistent across many agent projects. If a developer forgets to add the review step, queries run without a check. App-level checks also leave audit logs scattered across different services and chat rooms.

Approval Chains & Escalation + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Designing a safer workflow for agent queries

A strong setup separates query drafting from query execution. First, give the LlamaIndex engine a MySQL user with select grants on safe tables. Never let the agent read system tables or password hashes. Second, route risky queries to a human reviewer before they touch the database. Routine lookups on public tables can run right away. Queries that touch customer tables or lack row limits should wait for approval.

Third, plan for how the database returns sensitive fields to the language model. Even when a human approves a query, the result might hold private data. Masking rules that rewrite matched fields in results help protect national IDs and emails. Finally, keep a single log of every prompt, generated SQL statement, and approval decision. Central logs help security teams audit what the agent asked and who approved it.

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

Does LlamaIndex run SQL queries automatically by default?

Yes, the natural language SQL query engine generates the SQL and runs it right away. You must change your workflow or database setup to pause queries for human approval.

How do I limit which MySQL tables LlamaIndex can see?

You can specify a table list when you set up the query engine. You should also restrict the MySQL user role so it only sees those exact tables.

Why is a read-only MySQL role not enough for AI agents?

A read-only role stops data changes, but it cannot stop heavy queries or data leaks. An agent can still pull sensitive emails and card numbers or slow down the server.

The query runs. The emails stay hidden.