How to Configure Pydantic AI CockroachDB Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up pydantic ai cockroachdb prevent delete rules, restrict database roles and limit agent tools. You can block drop or remove commands by granting read and insert privileges only. Many teams start by giving their AI agents a single broad database user role. When an agent holds full table rights, one bad prompt can wipe out production rows. A solid setup separates what the agent can read from what it can change. How to set up pydantic ai cockroachdb prevent delete rules Start inside your

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 pydantic ai cockroachdb prevent delete rules, restrict database roles and limit agent tools. You can block drop or remove commands by granting read and insert privileges only. Many teams start by giving their AI agents a single broad database user role. When an agent holds full table rights, one bad prompt can wipe out production rows. A solid setup separates what the agent can read from what it can change.

How to set up pydantic ai cockroachdb prevent delete rules

Start inside your database by building a custom role just for your agent app. Do not use the default admin account for any automated tool runs. Grant this new role permission to read tables and add new rows. Leave out the permission to remove rows or drop tables from the role setup. Next, create a dedicated database user and assign it to this restricted role.

On the app side, build clear tool functions for your agent to call. Pydantic AI uses strict schemas to check the inputs before a function runs. Instead of giving the agent a raw query tool, build narrow task functions. Give the agent one tool to fetch records and another tool to add records. Each tool runs a fixed query template that never includes a delete action. The agent picks the right tool and fills in the typed fields. Then the app sends that safe command to the database using the restricted user role.

Why native role setup leaves a gap

Database roles and typed agent tools stop many basic mistakes before they happen. The database blocks direct delete commands from the restricted user role right away. Typed tool inputs also stop the model from making up random query structures.

Still, static roles only check who logs in at the start of a session. They do not inspect what individual statements try to do while in flight. Many agent workflows still need a raw query tool for complex data analysis. If that user role has update rights, an agent can still blank out rows. A bad update without a filter can overwrite an entire table with empty values. Static database roles also cannot hide sensitive fields inside the query results. If a table holds emails, phone numbers, card numbers, or national IDs, the query returns them. Native roles cannot rewrite matched fields in results before the agent reads the output.

AI Data Exfiltration Prevention: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Adding safer guardrails to agent workflows

Teams get better safety when they combine narrow tools with query inspection in flight. First, split your agent tools by risk level so read tasks stay separate. Give the analysis agent a read-only database user that cannot change any data. Give the write agent fixed templates that require a specific row key every time.

Second, check every statement before it reaches the database cluster. Blocking destructive commands at the statement level catches bad updates as well as deletes. You should also mask sensitive data like emails and card numbers in query results. When masking rewrites matched fields in results, the model processes safe text during the run. Finally, keep a clear log of every prompt and query tied to the user. This log helps your team review what the agent ran and fix bad prompts fast.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can a database role block deletes while allowing updates in CockroachDB?

Yes, you can grant read, insert, and update rights without granting delete rights. The database will reject any delete statement sent by that user role.

Why should I avoid giving Pydantic AI a raw SQL execution tool?

A raw SQL tool lets the model write any query structure it wants. If a prompt confuses the model, it might run a broad update or drop command.

How can I protect sensitive fields when the agent reads tables?

Use data masking to rewrite emails, phone numbers, card numbers, and national IDs in results. This step replaces real values in the output before the agent processes the response.

The query runs. The emails stay hidden.