How to Configure Mastra Neon Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a mastra neon prevent delete rule by limiting database roles. You also turn on branch safety settings inside your Postgres project. Many teams connect AI agents to Postgres using a single default owner key. That owner key holds full rights to drop tables or erase rows. When an agent makes a bad call, it can wipe out live data. How to set up a mastra neon prevent delete workflow A safe setup starts by splitting database keys by task. Your AI framework runs tools that read and write

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 mastra neon prevent delete rule by limiting database roles. You also turn on branch safety settings inside your Postgres project. Many teams connect AI agents to Postgres using a single default owner key. That owner key holds full rights to drop tables or erase rows. When an agent makes a bad call, it can wipe out live data.

How to set up a mastra neon prevent delete workflow

A safe setup starts by splitting database keys by task. Your AI framework runs tools that read and write state in Postgres. By default, a new Neon project gives you a role with full rights. You should not give this top role to your AI app. Instead, you create a new Postgres role with strict limits.

You grant this new role rights to read, add, and update rows. You leave out the right to delete rows or drop tables. Next, you place this restricted connection string into your app environment. The AI agent now uses this limited role for every tool call. If the agent tries to run a delete command, Postgres blocks it.

You also turn on protected branch rules in your database account. Neon lets you mark your main branch as protected. This setting stops users and scripts from deleting the branch itself. It also stops anyone from resetting the main branch to an older state. Together, role limits and branch rules block both row and branch loss.

Why database roles and branch rules are not enough

Database roles and branch rules are a strong first step for safety. They stop an agent from running a raw delete command on protected tables. They also stop a script from wiping out an entire database branch. Still, static Postgres roles only check who logs in at the start. They do not inspect what each query does while it runs.

An AI agent often needs to update records as part of its job. A role with update rights can still blank out columns across every row by default. If a prompt goes wrong, an update query without a filter overwrites everything. Postgres sees a valid update command from an allowed role and runs it. Static grants cannot tell a safe one-row update from a bulk wipe.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static database roles also do not handle sensitive data in query results. When an agent reads a table, it pulls back every column it asks for. This result can include emails, phone numbers, card numbers, or national IDs. Without query checks, those fields flow straight into the model context.

What to check before your agent goes live

Before you push your agent to users, test your database role limits. Run a test tool call that tries to delete a single test row. Check your logs to confirm that Postgres rejects the action right away. Make sure the error message does not crash your whole agent loop. Your app should catch the block and return a clean message.

Next, review every tool you give to your AI agent. Remove any general SQL tool that lets the model write raw queries. Give the agent small, fixed tools that only touch the tables it needs. Keep your main branch locked, and run all dev tests on child branches. This habit keeps mistakes away from your real user data.

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

Can Neon protected branches stop SQL delete commands?

No, protected branches only stop users from deleting or resetting the branch itself. You must use Postgres role permissions or runtime checks to block SQL delete statements.

How do I let Mastra update state without delete rights?

Create a custom Postgres role that only has select, insert, and update rights. Use that role key in your app so the agent cannot delete rows.

What happens when an agent hits a blocked delete query?

Postgres returns a permission denied error to the calling tool right away. You should set up your tool code to catch this error and move on.

The query runs. The emails stay hidden.