How to Configure Pydantic AI MariaDB Read Only Access
You set up pydantic ai mariadb read only access with a select-only database user. Then you pass that user into your agent dependency setup. Many teams start by giving the agent a broad admin database account. That shortcut lets a bad model prompt alter tables or drop rows. A strict read-only role stops the agent from changing your data. How pydantic ai mariadb read only access works in your app The setup starts inside your MariaDB server. A database admin creates a dedicated user account just
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 pydantic ai mariadb read only access with a select-only database user. Then you pass that user into your agent dependency setup. Many teams start by giving the agent a broad admin database account. That shortcut lets a bad model prompt alter tables or drop rows. A strict read-only role stops the agent from changing your data.
How pydantic ai mariadb read only access works in your app
The setup starts inside your MariaDB server. A database admin creates a dedicated user account just for the agent. The admin grants only select rights on specific tables or views. Next, the admin locks the account from running insert, update, or delete statements. The admin also removes rights to create tables or change schemas.
On the app side, you build a dependency object for your agent. This object holds the MariaDB client session and passes it to agent tools. When a user asks a question, the model picks the query tool. The tool takes the SQL string from the model and runs it. Because the database user only has read rights, MariaDB blocks any write attempts. The tool then validates the output rows and sends them back to the model.
How to tighten agent tool rules and session limits
A read-only user is a strong first step for your team. You should also set session limits inside the database. MariaDB lets you cap how long a single query can run. This stops a slow agent query from locking up your server CPU. You can also limit how many connections the agent account can open at once.
Inside your Python code, keep your agent tools narrow. Do not give the model a single open SQL tool if you can avoid it. Instead, build small tools that fetch one type of record at a time. Each tool can take typed inputs and plug them into a safe query template. This approach lowers the chance of bad syntax or wide table scans.
Auditor Read-Only Access + AI Model Access Control: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles solve and what they miss
Native MariaDB permissions do a great job of blocking data changes. Once the user logs in, the database engine checks every statement against the role. If the model tries to drop a table, the database rejects the command right away. Your core records stay safe from accidental edits or deletions.
Still, database roles only decide who can log in and which tables they can read. They do not inspect what individual statements do in flight. A read-only user can still pull every row from a customer table by default. If that table holds emails, phone numbers, card numbers, or national IDs, the query returns all of them. Data masking rewrites matched fields in results so sensitive values do not flow into model prompts. Native roles also hold static keys in app settings and lack a unified audit log across databases.
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
Can a MariaDB read-only user still slow down the database?
Yes, a read-only user can run heavy joins or full table scans. You should set query timeout limits on the MariaDB account to stop slow queries.
Should the agent have read rights on the whole database?
No, you should only grant select rights on the exact tables the agent needs. You can also create database views to hide sensitive columns from the agent.
How do I stop raw PII from reaching the language model?
Granting select access on a table returns every column the user queries by default. You must use views that drop sensitive columns or apply data masking to rewrite emails and card numbers in results.
Related guides
In this post