How to Configure Pydantic AI MariaDB Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a pydantic ai mariadb sandbox by linking an agent tool to a test database. You give the database user strict read or write grants and check inputs with schema rules. Most teams start by spinning up a local or staging database instance. They often pass root database keys to the agent code to save time. When roles are too broad, a bad prompt can wipe tables or pull customer emails. How a pydantic ai mariadb sandbox works in practice The agent framework uses Python type hints to check

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 sandbox by linking an agent tool to a test database. You give the database user strict read or write grants and check inputs with schema rules. Most teams start by spinning up a local or staging database instance. They often pass root database keys to the agent code to save time. When roles are too broad, a bad prompt can wipe tables or pull customer emails.

How a pydantic ai mariadb sandbox works in practice

The agent framework uses Python type hints to check every tool input before running. You build a dependency object that holds the database session and passes it to the agent. The agent reads the user prompt and decides when to call the database tool. Your tool function takes the structured arguments from the model and runs a SQL query. Inside the database, native role rules decide which tables the agent account can read.

A good test setup keeps the agent away from live production tables. You create a separate database user just for the agent workflow. You grant that user access to one specific test schema. If the agent needs to test writes, you give it insert rights on safe tables. You also set limits on how many queries the account can run per hour. This stops a loop in the model from locking up the database server.

Where native database roles fall short for agents

Native database grants solve the basic problem of who can log in. They also control which tables and views that single account can touch. Still, static database grants do not check what each query does in flight. Once the agent logs in, it has the exact same rights for every user request. If a table holds mixed data, a standard select grant returns every column and row by default.

The database does not know if a specific query is safe to run right now. An agent might pull phone numbers, card numbers, or national IDs into the model context. Data masking rewrites matched fields in results so raw values do not reach the prompt. Also, native database logs only show the shared agent user name, not the human user. Teams need a way to inspect queries in flight and approve risky statements before execution.

AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Steps to harden your agent database workflow

Start by splitting your agent tools into separate read and write functions. Do not give the model a single tool that runs raw SQL strings. Instead, build narrow tools that accept typed values and fill in fixed query templates. Check every output with a response model before sending data back to the user. Reset the test database state after each test run so bad data does not linger.

Next, review how your team stores and rotates the database login keys. Developers should not keep plain text database passwords in local config files on their laptops. Keep test data clean by stripping real emails and card numbers before loading your dumps. Even in a test space, good habits stop bad queries before they reach production.

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

Why should an AI agent use a separate database user?

A separate user lets you restrict the agent to specific tables and read-only actions. It also helps you spot agent queries in your database logs right away.

Can schema checks alone stop bad SQL queries?

Schema checks make sure the tool inputs match the right data types and formats. They do not stop an allowed query from reading sensitive rows or dropping test tables.

How do you handle sensitive fields in a test database?

You should scrub real emails, phone numbers, and card numbers before loading test data. You can also use masking rules that rewrite matched fields in query results.

The query runs. The emails stay hidden.