How to Configure Pydantic AI Bigquery Permissions
You set up pydantic ai bigquery permissions by tying an agent tool to a cloud role. That role must grant job run rights and read rights on specific datasets. Most teams start by giving the agent a broad project role to move fast. Broad roles let an agent read sensitive tables or change live data by mistake. How pydantic ai bigquery permissions work in practice Pydantic AI agents use custom Python functions as tools to interact with outside data. The agent does not hold database rules inside i
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 pydantic ai bigquery permissions by tying an agent tool to a cloud role. That role must grant job run rights and read rights on specific datasets. Most teams start by giving the agent a broad project role to move fast. Broad roles let an agent read sensitive tables or change live data by mistake.
How pydantic ai bigquery permissions work in practice
Pydantic AI agents use custom Python functions as tools to interact with outside data. The agent does not hold database rules inside its own framework code. Instead, the tool uses the official Google Cloud client library to run SQL queries. That client library looks for cloud credentials on the host machine or container.
In Google Cloud, two distinct permission types control every single query run. First, the identity needs permission to start a query job within the project. Second, the identity needs permission to read the tables referenced in that SQL query. If either permission is missing, the cloud platform rejects the request right away.
To set this up, you create a dedicated service account for the agent app. Do not share this account with other backend workloads or human engineers. Next, you grant the job user role at the project level. This role lets the agent spend compute budget to run queries.
After that, you grant the data viewer role on one dataset, not the whole project. This stops the agent from querying unrelated tables across your cloud account. Finally, you attach the service account to the workload identity of your app host. The client library picks up these credentials without needing a static key file on disk.
Why static cloud roles leave a gap for AI agents
Native cloud roles do a great job of verifying who can log in. They also draw a clear boundary around which datasets an agent can touch. Still, cloud roles only check access at the resource level before a query runs. They do not inspect the actual SQL statement or the rows coming back.
Once an agent has read rights on a table, it can read every row. If that table holds customer emails or phone numbers, the agent pulls them into memory. Those raw fields then travel straight to the external language model provider in the prompt. Native dataset roles have no way to rewrite matched fields in results during a query.
AI Agent Permissions + BigQuery IAM: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Cloud roles also struggle with dynamic human context in multi-user apps. Every user talking to the agent shares the same backend service account. In the database logs, every query looks like it came from the same bot. Security teams cannot see which human prompt triggered a specific database read.
Scoping dataset and table rules for agent tools
You can narrow the blast radius by moving permissions down to the table level. Google Cloud lets you attach data viewer roles to individual tables or authorized views. An authorized view runs a preset SQL query and hides the base table from the agent. This setup lets you filter out columns that hold card numbers or national IDs.
You should also set up cost controls on the project or user level. AI agents can write bad joins that scan terabytes of data in seconds. Setting a maximum bytes billed limit on the client tool prevents runaway cloud bills. Combine this limit with read-only dataset roles to keep your warehouse safe during agent runs.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
Should I use a service account key file for my agent?
Avoid static JSON key files whenever you can. Use workload identity federation or attached service accounts so credentials rotate on their own.
Can BigQuery roles stop an agent from reading customer emails?
Standard dataset roles cannot filter individual text values inside a column. You must use column-level security tags or external data masking to hide emails and phone numbers.
Why does my agent fail with a job creation error?
Granting read access to a dataset is not enough to run a query. The service account also needs the role that allows creating jobs in the project.
Related guides
In this post