How to Configure OpenAI Agents SDK MariaDB Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openai agents sdk mariadb prevent delete rule by limiting database grants. You also add input checks inside the function tool that runs SQL. Many teams give an AI agent a standard app user role for fast testing. That broad role lets a bad prompt wipe out rows or whole tables. How openai agents sdk mariadb prevent delete works in practice The OpenAI Agents SDK uses Python functions as tools to talk to external systems. You write a function that takes a SQL string from the model.

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 an openai agents sdk mariadb prevent delete rule by limiting database grants. You also add input checks inside the function tool that runs SQL. Many teams give an AI agent a standard app user role for fast testing. That broad role lets a bad prompt wipe out rows or whole tables.

How openai agents sdk mariadb prevent delete works in practice

The OpenAI Agents SDK uses Python functions as tools to talk to external systems. You write a function that takes a SQL string from the model. That function opens a MariaDB session and runs the query. The SDK itself does not know what a safe or unsafe SQL query looks like. It just passes the text from the model into your Python function.

Your first step happens inside MariaDB. You create a dedicated database user just for the agent. You grant this user select, insert, and update rights on specific tables. You leave out the delete, drop, and truncate privileges on purpose. When the model sends a delete command, the database engine blocks it right away.

Your second step happens inside your Python tool code. Before the function sends the query to MariaDB, it inspects the text. You can add a guard that rejects strings containing destructive words. You can also wrap the tool call in an approval check for write tasks. These two steps work together to stop bad queries before data is lost.

What native MariaDB roles solve and what they miss

Native database grants are strong because the database engine enforces them on every session. Even if a prompt tricks the agent, MariaDB rejects the delete command. This setup stops simple row removal across the tables you protect. It gives your team a solid base layer of safety for agent tasks.

Still, database grants only check who logs in and what command type runs. They do not inspect the deeper logic of a query in flight. An agent with update rights can still set every column in a table to null. That action acts just like a delete even though it uses an update statement.

OpenAI API Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static roles also make life hard when an agent needs to clean up temporary rows. If you grant delete rights for one task, the agent keeps them for all tasks. In-app string checks are also easy for a model to bypass with multi-statement queries. Also, database logs only show the shared agent user, not which end user asked for the action. Lastly, native grants do not mask private fields like emails, phone numbers, or card numbers.

Why agent tool guardrails need deeper query control

Building custom SQL parsers inside every agent tool takes a lot of time. Each new agent project ends up with its own set of fragile text rules. When a developer updates the app, someone might remove a check by mistake. A safer setup moves query checks and data masking out of the app code. This keeps your database safe even when prompts or agent tools change.

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 the OpenAI Agents SDK block SQL delete queries on its own?

No, the SDK only routes text from the model to your Python functions. You must enforce SQL rules in your tool code or at the database layer.

Why is revoking the delete grant in MariaDB not enough for AI agents?

An agent with update rights can still overwrite rows with blank values. It can also read private fields like card numbers or national IDs without extra controls.

How do I let an agent delete only specific rows safely?

Instead of giving the agent a raw SQL tool, build a strict function tool. Make the tool accept only a single record ID and require human approval before it runs.

The query runs. The emails stay hidden.