How to Configure Vercel AI SDK CockroachDB Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a vercel ai sdk cockroachdb prevent delete workflow, restrict database roles first. You must remove drop and delete rights from the role your AI app uses. Many teams build AI features that query databases straight from tool calls. Developers often reuse a broad app role for these new AI tasks. If an AI model gets a bad prompt, that broad role lets it wipe rows. A single bad tool call can remove whole tables in seconds. How a vercel ai sdk cockroachdb prevent delete setup works The A

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 vercel ai sdk cockroachdb prevent delete workflow, restrict database roles first. You must remove drop and delete rights from the role your AI app uses. Many teams build AI features that query databases straight from tool calls. Developers often reuse a broad app role for these new AI tasks. If an AI model gets a bad prompt, that broad role lets it wipe rows. A single bad tool call can remove whole tables in seconds.

How a vercel ai sdk cockroachdb prevent delete setup works

The AI SDK lets language models run functions based on user prompts. Teams often give the model a tool that runs SQL against CockroachDB. To stop data loss, you must change how the database role works. Start by making a new SQL user just for your AI tool calls. Do not give this user admin rights or broad write powers. Grant only select, insert, and update rights on the specific tables the app needs. Leave out the delete privilege and the drop privilege on every schema. When the AI app logs in, CockroachDB checks the role rules on each run. If the model tries to remove a row, the database engine blocks the statement. The database returns an error to the SDK tool call instead of wiping data. You can also wrap the tool logic in a read-only database transaction. This native setup gives you a strong first line of defense against bad queries.

What native database roles solve and what they miss

Native database roles do a good job of stopping basic row deletions. They decide which user can log in and which tables that user can touch. Still, static role rules cannot check what an individual statement does in flight. An AI agent might still need update rights to change a task status. With update rights, a confused model can overwrite every row with blank values. That ruins your data just as fast as a real delete statement. Static roles also cannot stop a model from reading every row at once by default. If a table holds emails, phone numbers, or card numbers, the model gets them. Masking is needed to rewrite matched fields in results before they reach the model. Native roles also lack a clear log that links AI prompts to SQL runs. You see the shared app user in the database log, not the real caller. Teams end up managing dozens of tiny roles across every cluster they run.

Why runtime query checks protect AI database workflows

Teams need a way to inspect every query right before the database runs it. Runtime checks look at the exact SQL text and the user context together. You can block dangerous updates or large table scans even when the role allows writes. You can also pause risky commands and ask a human to approve them first. This approach keeps your database roles simple while stopping bad AI actions in real time. It also rewrites sensitive fields like national IDs in query results on the fly.

AI Data Exfiltration Prevention: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Can I block delete queries inside the Vercel AI SDK tool code?

You can parse strings in your app code, but attackers can bypass text checks. SQL syntax is tricky, and a model can hide commands inside complex statements. Checking rules at the database or network level is much safer for your data.

How do I let the AI mark rows as removed without delete rights?

Use a soft delete pattern by adding a status column to your table. Give the AI database role permission to update only that specific status column. This lets the app hide old records while keeping the raw data safe.

What happens when CockroachDB blocks a delete from an AI tool call?

CockroachDB stops the query right away and sends back a permission error message. Your SDK tool function catches that error and returns the text to the model. The model can then tell the user that the action is not allowed.

The query runs. The emails stay hidden.