How to Configure Pydantic AI Supabase Prevent Delete
To set up a pydantic ai supabase prevent delete rule, create a custom database role. Grant that role only read or insert rights, and leave out delete rights. Many teams start by giving their AI agent the default admin role password. Every Supabase project includes a default postgres role with full admin rights. If your agent uses this role, a bad prompt can wipe out production rows. Broad database roles let an agent run destructive commands across every table. How to set up pydantic ai supabas
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.
To set up a pydantic ai supabase prevent delete rule, create a custom database role. Grant that role only read or insert rights, and leave out delete rights. Many teams start by giving their AI agent the default admin role password. Every Supabase project includes a default postgres role with full admin rights. If your agent uses this role, a bad prompt can wipe out production rows. Broad database roles let an agent run destructive commands across every table.
How to set up pydantic ai supabase prevent delete roles
Supabase does not grant full superuser rights because those allow destructive database actions. Still, the default postgres role still holds broad admin rights over your tables. The password you set at project creation belongs to this default postgres role. Queries run in the dashboard also run as this admin role.
Supabase warns that you should never give the default password to an outside service. Instead, Supabase advises creating a new database user for every separate service. This rule applies directly when you wire a Pydantic AI agent to your database.
Start by creating a dedicated database role just for your Pydantic AI tools. Do not grant delete permissions on any table to this new role. Give the agent role only the rights to read rows or add new data. When the agent tries to remove rows, the database rejects the command right away.
You should also review how your agent tools are built in code. Give the agent narrow tools that run fixed queries instead of raw database text. When you combine fixed tools with a role that lacks delete rights, you reduce risk.
Where native database roles fall short for AI agents
A custom database role stops an agent from deleting rows on protected tables. It decides who can log in and which table actions are allowed at rest. Still, static database roles cannot check what individual queries do in flight.
An agent that needs update rights can still overwrite critical data with blank values. A role with read rights can still pull whole tables full of private user data. Native roles do not rewrite sensitive fields like emails or phone numbers in query results. They also do not block bad update statements or require human approval for risky actions.
AI Data Exfiltration Prevention: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing many custom roles across several databases also creates extra work for your team. Each new agent tool might need a different mix of table and column rights. When a developer changes a table, they must remember to update every agent role. One missed grant can break the app or open a path for data loss.
Why agent tool design matters alongside database rules
Pydantic AI lets developers define structured tools that models call during a task. If a developer gives the model a tool that runs open queries, risk goes up. The model might try to clean up old data by running a delete command. Even if the database blocks the delete, the failed call can break the workflow.
Instead, build separate tools for reading records and adding new entries. Never expose a delete function to the model unless the workflow demands it. Keep your prompts clear so the model knows it can only read or append data. Still, prompt rules and code checks are not enough on their own. You must back them up with strict controls between the agent and the database.
Add query and result controls beside Postgres
Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.
When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.
Frequently asked questions
Why should I not use the default postgres password for Pydantic AI?
The default postgres role has admin rights and can remove tables or rows. Supabase advises creating a separate user for each service to limit damage.
Does stopping delete commands protect against all agent data loss?
No, an agent with update rights can still overwrite existing rows with bad values. You also need controls that inspect queries in flight and mask sensitive fields.
Can Pydantic AI tool rules replace database role limits?
No, app code and prompts can change or fail when a user sends tricky input. Enforcing limits at the database and query level stops bad commands before they run.
Related guides
In this post