How to Configure OpenAI Agents SDK MariaDB Read Only Access
You set up openai agents sdk mariadb read only access with a restricted database user. Then you pass those login keys to a custom tool function in your agent app. Many teams start by reusing a shared admin account to test their agent fast. That broad role lets a model mistake alter or delete live rows in seconds. A dedicated read role stops write queries at the database engine level. How openai agents sdk mariadb read only access works The agent framework does not include a built-in MariaDB c
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 openai agents sdk mariadb read only access with a restricted database user. Then you pass those login keys to a custom tool function in your agent app. Many teams start by reusing a shared admin account to test their agent fast. That broad role lets a model mistake alter or delete live rows in seconds. A dedicated read role stops write queries at the database engine level.
How openai agents sdk mariadb read only access works
The agent framework does not include a built-in MariaDB connector out of the box. Instead, developers write a Python function and register it as a tool for the agent. When a user asks a question, the model picks that tool and writes a query. The Python function opens a database session, runs the query, and returns the rows.
To keep this flow safe, you build a dedicated user inside MariaDB first. You grant that user select privileges on the specific tables the agent needs to read. You leave out insert, update, delete, and drop rights on all schemas. You can also route the agent tool to a read replica instead of the primary database.
Next, you store the database host, user name, and password in your app runtime settings. The tool function reads those values when it starts a new database session. If the model tries to change data, MariaDB blocks the statement right away. The database returns a permission error to the tool, and your tables stay untouched.
Where native MariaDB read roles fall short for AI agents
A native read role solves one big problem by blocking data changes and drops. Still, database user grants only check who logs in and which tables they can read. They do not inspect what individual queries do while they run in flight. Once the agent logs in, it can read every column in an allowed table.
Customer tables often mix safe numbers with sensitive personal data in the same row. A broad select query can pull emails, phone numbers, card numbers, or national IDs. The tool function then sends those raw values straight into the external model context. Data masking is needed to rewrite matched fields in results before they leave the network.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native roles also struggle with bad queries that hurt database speed for other apps. An agent can write a huge join or scan millions of rows without a limit. Without row caps or query timeouts, one bad prompt can lock up CPU and memory. Finally, shared app credentials make audit logs hard to read during a security review. Every query from every user looks like it came from the same bot account.
Steps to harden agent database tools in production
Start by scoping your MariaDB user to the smallest set of tables possible. If the agent only answers billing questions, do not grant select rights on user profiles. Create clean database views that leave out secret columns, and grant access to those views.
Add statement timeouts and resource limits to the MariaDB user account as well. This ensures the database kills slow agent queries before they take down the whole server. You should also validate the query string inside your Python tool before running it. Reject statements that stack multiple queries together or call system functions.
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 the OpenAI Agents SDK query MariaDB without custom code?
No, the SDK requires you to write a Python function that wraps a database driver. You decorate or register that function as a tool so the agent can call it.
Does a MariaDB read-only user stop sensitive data leaks?
No, a read-only grant only stops the agent from changing or deleting data. The agent can still read emails, phone numbers, or card numbers from any allowed table.
Should I connect my AI agent to a MariaDB read replica?
Yes, using a read replica protects your primary database from heavy query loads. You should still combine the replica with strict table grants and field masking.
Related guides
In this post