How to Configure OpenAI Agents SDK Bigquery Prevent Delete
To set up an openai agents sdk bigquery prevent delete rule, restrict the service account role and add input checks. You must strip write and delete rights from the cloud identity the agent uses. Most teams start by giving their agent a broad project role for fast testing. That wide role lets a bad prompt drop tables or erase rows in seconds. A safe setup pairs strict cloud roles with clear checks inside the agent tool. How openai agents sdk bigquery prevent delete works in practice The agent
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 bigquery prevent delete rule, restrict the service account role and add input checks. You must strip write and delete rights from the cloud identity the agent uses. Most teams start by giving their agent a broad project role for fast testing. That wide role lets a bad prompt drop tables or erase rows in seconds. A safe setup pairs strict cloud roles with clear checks inside the agent tool.
How openai agents sdk bigquery prevent delete works in practice
The agent framework uses Python functions as tools to talk to outside data systems. You wrap the cloud database client inside one of these custom tool functions. When the model needs data, it writes a query and calls your tool. The tool sends that query string to the data warehouse using a service account key.
To block deletes at the cloud level, you change the service account role. You remove editor or owner rights and assign a read-only viewer role instead. You also grant a basic job user role so the agent can run queries. With these two roles, the database blocks any command that tries to remove rows. Even if the model writes a drop command, the cloud engine rejects the run.
Teams also add a second check inside the Python tool function itself. Before the function sends the query, it checks the text for unsafe words. If the string holds words like delete, drop, or truncate, the function stops right there. It returns an error message to the model instead of calling the database.
What native roles solve and what they leave open
Native cloud roles are great for stopping table drops when an agent only needs read access. They enforce a hard wall at the database level that no prompt can trick. If a service account lacks delete rights, the warehouse will never erase a row.
The trouble starts when your agent needs to write new rows or update records. In the cloud permission model, data change rights often bundle insert, update, and delete together. If you give the agent a role that can update rows, it can often delete them too. Native roles decide who can log in and use a table, not what each query does in flight.
BigQuery IAM + OpenAI API Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Text checks inside your Python tool try to close this gap, but they are fragile. Models can write complex queries or multi-statement blocks that slip past basic word filters. Also, keeping database keys on the agent host creates a risk if the app breaks. And when five different agents share one service account, your cloud logs cannot show which agent ran a bad query. You also have to watch out for private data like emails, phone numbers, or card numbers coming back in results.
Separating read and write tools for safer agent runs
A clean way to lower risk is to split your agent tools by task. Do not give the model one giant tool that runs raw SQL for every job. Build one tool that only reads data using a read-only service account. Then build a second tool for writes that does not take raw SQL from the model.
Instead of raw queries, the write tool should only accept fixed values like a status or date. Your Python code then places those values into a safe, pre-written insert or update statement. This pattern keeps the model from ever choosing the verb in a write query. The agent can add records all day, and it still cannot run a delete command.
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 a prompt guard alone stop an agent from deleting data?
No, a system prompt is just advice to the model and is not a hard wall. A clever user prompt or a model mistake can still produce a delete statement. Always enforce limits in your database roles and tool code.
What happens when an agent hits a permission error in BigQuery?
The database client raises an access denied error inside your Python tool function. You can catch that error and return a short text message back to the agent. The agent then reads the error and tells the user it cannot delete data.
How should we handle agents that must remove old temp tables?
Do not give the agent delete rights on your main data sets. Put temp tables in a separate scratch dataset with a built-in table expiration timer. Let the cloud platform clean up old temp tables on a set schedule instead.
Related guides
In this post