How to Configure Pydantic AI Bigquery Read Only Access
You set up pydantic ai bigquery read only access by pairing two cloud roles. Your service account needs both a job runner role and a data viewer role. Many teams start by giving their agent a broad project editor role to test queries fast. That shortcut lets an automated agent alter tables or delete production datasets by mistake. How to set up pydantic ai bigquery read only access First, create a dedicated cloud service account just for your AI agent. Do not reuse a service account that runs
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 read only access by pairing two cloud roles. Your service account needs both a job runner role and a data viewer role. Many teams start by giving their agent a broad project editor role to test queries fast. That shortcut lets an automated agent alter tables or delete production datasets by mistake.
How to set up pydantic ai bigquery read only access
First, create a dedicated cloud service account just for your AI agent. Do not reuse a service account that runs your backend apps or data pipelines. Giving the agent its own identity makes audit logs much easier to read later.
Next, grant that service account the role that lets it run query jobs. In BigQuery, reading data requires running a query job inside a project. A viewer role alone cannot start a job, so the agent will fail right away.
Then, grant the data viewer role on the specific dataset or table you want to read. Avoid granting the viewer role at the top project level if you have sensitive tables nearby. Dataset-level roles keep the agent away from tables it does not need for its task.
After you set the cloud roles, build a query tool inside your Pydantic AI agent. Define a clear schema for the tool inputs so the model sends valid query strings. Inside the tool function, use the standard cloud client library to run the query job.
You can also add a dry run step inside your Python tool function before execution. The client library can check how many bytes a query will scan before it runs. If the byte count is too high, your code can reject the query and return an error.
What native cloud roles solve and what they miss
Native cloud roles do a great job of blocking write and delete actions at the storage layer. Even if a prompt trick tells the agent to drop a table, the cloud API blocks it. The service account simply lacks the permission to change data or schema definitions.
Auditor Read-Only Access + AI Model Access Control: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, cloud roles only check who logs in and which dataset they touch. They do not inspect the actual SQL statement or the rows coming back in flight. A read-only agent can still select columns that hold sensitive user details.
If a table holds customer emails, phone numbers, or card numbers, the viewer role returns them all. Those raw values flow right into the model context window and out to your model provider. Native roles cannot rewrite matched fields in query results on the fly.
Static service account keys also create a secret management task for your engineering team. Developers often download key files to their laptops to test the agent locally. Those static files can leak in code repos or sit on machines for months without rotation.
Scoping agent queries and handling sensitive fields
To reduce risk with native tools, teams often build Authorized Views in their data warehouse. An Authorized View lets you share a filtered subset of columns with the agent service account. You leave out columns with emails, phone numbers, or national IDs when you define the view.
This approach works well for a few tables, but it creates maintenance work as schemas change. Every time an engineer adds a new table, someone must update the view definitions too. Teams also have to manage query quotas so a runaway agent loop does not spike cloud bills.
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
Why does my read-only service account get an access denied error when running a query?
BigQuery separates the right to read table data from the right to run a query job. Your service account needs both the data viewer role and the job user role to run SELECT statements.
How can I stop a Pydantic AI agent from running expensive full-table scans?
You can set a maximum bytes billed limit in your query job settings within the Python client. You can also set daily query usage quotas on the cloud project or user level.
Does a read-only role hide sensitive columns like emails or card numbers from the LLM?
No, a standard data viewer role allows the agent to read every column in the permitted table by default. To restrict columns natively, you must configure column-level security tags or create separate Authorized Views.
Related guides
In this post