How to Configure OpenAI Agents SDK CockroachDB Prevent Delete
To set up an openai agents sdk cockroachdb prevent delete rule, use a restricted database role. You must also limit the SQL tools that your agent can call during a run. Most teams start by giving an AI agent a standard app login. That login often holds full read, write, and delete rights across every table. If a prompt confuses the model, the agent can wipe out production rows in seconds. Scoping database privileges before the agent runs is the core defense against bad deletes. How openai agen
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 an openai agents sdk cockroachdb prevent delete rule, use a restricted database role. You must also limit the SQL tools that your agent can call during a run. Most teams start by giving an AI agent a standard app login. That login often holds full read, write, and delete rights across every table. If a prompt confuses the model, the agent can wipe out production rows in seconds. Scoping database privileges before the agent runs is the core defense against bad deletes.
How openai agents sdk cockroachdb prevent delete works
In the OpenAI Agents SDK, an agent uses custom Python functions as tools. Developers wrap a database client inside these functions so the agent can query data. When the model decides it needs data, it calls the tool function. If you give that function a raw SQL string from the model, risks rise fast. Any text-to-SQL app runs a real risk when it executes arbitrary queries. The safe path is to combine strict database roles with narrow tool functions.
On the CockroachDB side, access control relies on role-based privileges. Admins create a dedicated SQL user just for the AI agent workload. They grant select, insert, or update rights on specific tables, and skip the delete privilege. When the agent logs in with this role, the database engine checks every statement. If the agent tries to drop a table or delete rows, CockroachDB blocks the command. The database returns a permission error to the Python tool function instead of removing data.
You can also shape the tool functions inside the OpenAI Agents SDK. Instead of one open query tool, build small functions for single tasks. One function can read order status, and another can insert a support note. Neither function builds a delete statement. This two-step setup pairs code limits in the agent with role limits in the database.
Where native database roles fall short
Native roles in CockroachDB handle table-level rules well, but operational gaps remain. First, static roles apply the same way to every run of the agent. A role decides who logs in, not what a single statement does in flight. Sometimes an agent needs to clean up temporary staging rows without touching customer records. Table grants cannot tell a safe staging cleanup apart from a bad bulk delete.
Second, an update command can cause just as much harm as a delete command. If an agent holds update rights, a bad query can overwrite columns with blank values. A role that only blocks delete statements will let a destructive update pass right through. Also, shared service accounts make audit logs hard to read. When five agents share one database user, the logs only show that single user name. Teams cannot see which prompt, user request, or agent run triggered a blocked query.
OpenAI API Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Third, database roles do not filter sensitive fields inside the rows an agent reads. When an agent runs a select query, the database returns full columns to the model. Those columns might hold emails, phone numbers, card numbers, or national IDs. Without data masking that rewrites matched fields in results, raw user data flows into model prompts.
Adding query checks for agent workloads
To close these gaps, teams inspect SQL statements before they reach the CockroachDB cluster. Checking each query in flight lets you block risky commands based on context. You can allow small updates with a strict filter while stopping broad updates or deletes. You can also tie each query back to the specific person or service that started the agent run. This approach keeps the database safe while giving agents the exact access they need.
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 an OpenAI agent still update rows if delete is blocked?
Yes, CockroachDB separates update privileges from delete privileges at the role level. You can grant select and update rights to the agent role while leaving delete rights off. Be careful, as a bad update without a filter can still overwrite important table data.
Should I give an AI agent a read-only CockroachDB role?
If your agent only answers questions from existing data, a read-only role is the safest choice. Granting only select privileges stops all delete, update, and schema change commands at the database engine. Only add write privileges when the agent must save new records.
How do I stop an agent from reading sensitive columns in CockroachDB?
Database roles usually control access at the table or view level rather than rewriting values on the fly. You can restrict the agent role to specific views, or use dynamic data masking to rewrite emails, phone numbers, and card numbers in query results.
Related guides
In this post