How to Configure OpenAI Agents SDK Bigquery Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openai agents sdk bigquery read only access by pairing a viewer role with a query tool. The agent uses a cloud identity that can run select queries and read table data. Many teams start by giving their agent a broad admin role during tests. That shortcut lets a bad model prompt alter tables, drop datasets, or scan huge tables. How openai agents sdk bigquery read only access works The agent framework runs Python functions as tools when the model needs data. You write a tool function

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 openai agents sdk bigquery read only access by pairing a viewer role with a query tool. The agent uses a cloud identity that can run select queries and read table data. Many teams start by giving their agent a broad admin role during tests. That shortcut lets a bad model prompt alter tables, drop datasets, or scan huge tables.

How openai agents sdk bigquery read only access works

The agent framework runs Python functions as tools when the model needs data. You write a tool function that takes a SQL string from the model. Inside that function, the standard Google Cloud client library sends the query to the data warehouse. The warehouse checks the identity attached to that client before it runs the job.

To lock this down, you create a dedicated cloud service account for the agent. That account needs two distinct rights in your cloud project to work well. First, it needs the right to create and run query jobs in the project. Second, it needs the right to read table metadata and rows in specific datasets.

You grant data viewer rights on the target dataset rather than the whole project. This step keeps the agent away from billing tables, user logs, or other restricted datasets. When the model writes an insert, update, or delete statement, the warehouse rejects the job. The agent gets an error message back and cannot change any stored records.

What native roles solve and what they leave open

Native cloud roles do a great job of stopping writes and schema changes. They make sure the agent identity can only read the datasets you pick. Even if a user tricks the model, the warehouse will block any drop table command. This setup forms the baseline for safe agent database work.

Still, cloud roles only check who logs in and which dataset they touch. They do not inspect what individual statements do while the query is in flight. A read role still lets the agent pull every row from a allowed table by default. If that table holds emails, phone numbers, card numbers, or national IDs, the model gets them.

Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Once raw sensitive fields enter the model context, they can leak into chat replies. They also show up in agent trace logs and third-party model host records. Native roles also cannot require a human to approve a high-cost query before it runs. Finally, shared service accounts hide which specific app user or agent task triggered a bad scan.

Adding query limits and safer tool design

You can close part of this gap by tightening how you build the agent tools. Instead of giving the model a raw SQL tool, give it fixed query templates. Each tool function takes simple inputs like a date range or an account number. The code then fills those inputs into a safe, pre-written select statement.

When the agent must write custom SQL, set a maximum bytes billed limit on each job. The warehouse will cancel any query that tries to scan more data than your cap. You can also build authorized views that leave out columns with emails or card numbers. Grant the agent viewer rights on those safe views instead of the base tables.

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

Why does my read-only agent fail to run a select query in BigQuery?

Reading data in this warehouse requires both table read rights and job creation rights. If the service account only has data viewer rights, it cannot start a query job. Add a role that allows running jobs in the project while keeping dataset access restricted.

Can a read-only cloud role stop an agent from reading sensitive columns?

Standard dataset viewer roles give access to all columns inside the allowed tables by default. To block specific columns natively, you must set up policy tags or use authorized views. You can also use a runtime layer that rewrites matched fields in results like phone numbers.

How do I stop an AI agent from running huge, costly warehouse scans?

Set a maximum bytes billed limit in the query job settings inside your tool function. The warehouse estimates the scan size before running and blocks jobs that pass your limit. You should also require partition filters on large tables so the agent must narrow its search.

The query runs. The emails stay hidden.