How to Configure Pydantic AI MariaDB Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a pydantic ai mariadb prevent delete workflow by using strict database roles. You also write clear Python tool rules that block row removal commands. Teams often give an AI agent a broad database user account to save time. This shortcut lets a bad model prompt wipe out live tables in seconds. How to set up pydantic ai mariadb prevent delete rules Start inside your MariaDB server before you touch any Python code. Create a new database user built just for your AI agent. Grant this us

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 pydantic ai mariadb prevent delete workflow by using strict database roles. You also write clear Python tool rules that block row removal commands. Teams often give an AI agent a broad database user account to save time. This shortcut lets a bad model prompt wipe out live tables in seconds.

How to set up pydantic ai mariadb prevent delete rules

Start inside your MariaDB server before you touch any Python code. Create a new database user built just for your AI agent. Grant this user permission to read tables and insert or update rows. Do not grant permission to delete rows or drop tables.

Next, build the tool functions inside your Pydantic AI agent app. Give the agent specific tools for each task instead of one raw query tool. For example, build one tool to look up orders and another to add notes. Use Pydantic schemas to check every input before the tool builds a query. This setup stops the model from slipping a delete statement into the call.

You can also add a check inside the Python tool function itself. Have the function scan the query string for drop, truncate, or delete words. If the function spots those words, it returns a simple error to the model. The agent then knows it cannot run that action and tries another path.

What native MariaDB roles solve and what they miss

Database grants and Pydantic tool checks solve the biggest problem right away. The MariaDB engine will reject any delete command from the agent user account. Even if a prompt trick bypasses your Python code, the database blocks the delete.

Still, static database roles only decide who can log in and run broad command types. They do not inspect what individual statements do while they run in flight. An agent with update permissions can still overwrite every row with blank values by default. That bad update destroys your data just like a delete command would.

Native roles also leave your sensitive columns wide open to read queries. When the agent runs a select query, it pulls full customer records into memory. It sends emails, phone numbers, card numbers, and national IDs straight to the model. Database grants alone cannot rewrite those fields in query results or pause risky updates.

AI Data Exfiltration Prevention: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to protect agent queries in live environments

To close this gap, teams need controls that inspect each query in flight. First, split your agent tools by risk level. Give read-only tasks their own database account with only select rights. Give write tasks a separate account scoped to one or two safe tables.

Second, set row limits on every query the agent runs. An update or select query should always require a strict filter clause. If an agent tries to update a table without a filter, block the call.

Third, keep a full log of every query the agent tries to run. Tie each database call back to the specific agent run and user prompt. Good logs help your team spot bad tool habits and fix prompts fast.

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

Can Pydantic AI block delete queries on its own?

Pydantic AI checks data shapes and runs the Python tool functions you write. It does not parse SQL grammar or block database commands by itself. You must write checks in your tool code and lock down the MariaDB role.

Why is a read and update role still risky for MariaDB?

A role that allows updates can still ruin a table if a query lacks filters. The agent could set every customer email or phone number to null at once. You need query checks that block broad updates before they hit the server.

How do I stop the agent from reading private user data?

Standard MariaDB table grants return all rows that match a select query by default. You can create restricted database views that leave out card numbers and national IDs. You can also use data masking to rewrite those matched fields in query results.

The query runs. The emails stay hidden.