How to Configure OpenAI Agents SDK Bigquery Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openai agents sdk bigquery credentials by giving your agent tool a cloud identity. This identity uses a service account key or a local login token to run queries. Most engineering teams start by creating one shared service account for their new agent app. They load that secret key into the host machine so the agent can read tables. When that role has broad permissions, the agent can touch sensitive tables or change data. A single bad prompt can then trigger a huge table scan or delete

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 credentials by giving your agent tool a cloud identity. This identity uses a service account key or a local login token to run queries. Most engineering teams start by creating one shared service account for their new agent app. They load that secret key into the host machine so the agent can read tables. When that role has broad permissions, the agent can touch sensitive tables or change data. A single bad prompt can then trigger a huge table scan or delete rows.

How openai agents sdk bigquery credentials work in practice

The agent framework does not hold database keys inside its own core logic. Instead, you write a custom Python function and register it as a tool for the model. Inside that function, the standard Google client library looks for your login keys. It checks the host machine for a key file path or uses the default cloud identity. Once the client logs in, the model can call your tool with a SQL string. The tool sends that SQL string straight to the data warehouse using the active account.

You control what the agent can do by setting cloud roles on that service account. A safe setup uses a read-only role scoped to one dataset or a few specific tables. You should avoid project-wide editor or owner roles for any automated agent tool. Scoped roles stop the agent from dropping tables or reading private finance datasets. You can also set query size limits on the project to stop runaway cloud bills.

What native roles solve and what they leave open

Cloud roles do a great job of deciding which service account can log in. They also decide which datasets and tables that account can see at a basic level. If an agent tries to read a blocked dataset, the cloud platform rejects the request. This blocks outsider access and keeps the agent inside its assigned project folder.

Still, static cloud roles cannot inspect the actual SQL statement while it runs in flight. Once an account has read access to a table, it can pull every column and row. If a table holds customer emails, phone numbers, or card numbers, the query returns them. Those raw values go right into the model context window and to the model provider. Also, server logs only show that the shared service account ran a query. They do not show which human user or agent task asked for that data.

Ephemeral Credentials + BigQuery IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Steps to tighten agent database access

Start by removing static JSON key files from developer laptops and app servers. Use workload identity where your cloud host binds a short-lived token to the app container. Next, build a clean dataset that only holds the exact views your agent needs. Leave sensitive columns like national IDs or card numbers out of those views when possible. Finally, check your query logs every week to spot odd query patterns from your agent tools. Adding query inspection and field masking in the path rewrites matched fields in results before they reach the model.

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

Where does the agent store database keys?

The agent framework does not store database keys itself. Your custom tool code reads keys from the host machine or cloud metadata server at runtime.

Should an AI agent use a personal user account for BigQuery?

No, an agent should never use a human engineer's personal login token. Always create a dedicated service account with read-only permissions on the exact tables the agent needs.

Can cloud roles stop an agent from reading customer emails in a shared table?

Standard table roles grant access to the whole table, though you can set up column tags. Without column controls or result masking, any allowed query returns all emails and phone numbers in that table.

The query runs. The emails stay hidden.