How to Configure Vercel AI SDK Bigquery Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up vercel ai sdk bigquery read only access by pairing a restricted Google Cloud service account with a custom tool definition. This setup lets your AI agent run analytical queries while blocking any data changes or table drops. Many engineering teams start by giving their app a standard project editor role to test features fast. Broad roles create huge risks when an AI model writes and runs its own SQL queries. A single bad prompt can cause the model to alter production tables 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 vercel ai sdk bigquery read only access by pairing a restricted Google Cloud service account with a custom tool definition. This setup lets your AI agent run analytical queries while blocking any data changes or table drops. Many engineering teams start by giving their app a standard project editor role to test features fast. Broad roles create huge risks when an AI model writes and runs its own SQL queries. A single bad prompt can cause the model to alter production tables or delete critical records.

How to set up vercel ai sdk bigquery read only access

First, you create a dedicated service account inside your Google Cloud project for your AI app. Next, you assign two basic roles to this new account. The account needs permission to create query jobs and permission to read table data. Without job creation rights, the client library cannot run any SQL statements at all. Without data viewer rights, the job runs but fails to read the underlying rows.

You can scope the data viewer role to a single dataset instead of the whole project. This step keeps the AI agent away from internal billing tables or private user logs. Once the roles are set, you connect your backend app to Google Cloud. Teams running on cloud platforms can use workload identity federation to avoid static JSON keys. If you use a key file, store it in your secret manager and load it at runtime.

Inside your app code, you initialize the database client with these read-only credentials. Then you define a tool within the SDK that accepts a SQL query string from the model. The model generates a query based on the user prompt and passes it to your tool. Your backend function runs the query against the database and returns the rows to the model.

Why native cloud roles are not enough for AI agents

Native cloud roles do a great job of stopping writes, updates, and table drops at the database level. Still, a read-only role only checks who logs in and which tables they can open. It does not inspect the actual SQL statements or filter the data inside permitted tables.

An AI agent with read access to a customer table can still pull sensitive records. If a table holds emails, phone numbers, card numbers, or national IDs, the query returns them in plain text. Those raw fields then flow straight into the language model context window and external logs. Data masking is needed to rewrite matched fields in results before the model processes them.

Auditor Read-Only Access + AI Model Access Control: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Read-only permissions also fail to stop expensive full-table scans on massive analytical datasets. A model might write a poorly joined query that scans terabytes of data in seconds. You need query limits and dry-run checks inside your tool logic to cap bytes billed per request.

Best practices for safe AI database tools

Do not let the language model query raw production tables directly if you can avoid it. Instead, build curated database views that expose only the specific columns the AI feature needs. Grant your service account read access to that single dataset of views and nothing else.

You should also add a dry-run check inside your tool function before running the real query. The database client can estimate how many bytes a query will read without actually running it. If the estimate exceeds your cost limit, your code can reject the query and ask the model to try again.

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

Which Google Cloud roles give read-only query access?

You need to combine a role that allows running query jobs with a role that reads table data. Granting the job role at the project level and the viewer role on one dataset is safest.

Can the AI model still read sensitive columns with a read-only role?

Yes, a standard viewer role lets the query read every column in an allowed table by default. You must use authorized views, column-level security, or data masking to hide sensitive fields like emails or card numbers.

How do I stop the AI agent from running expensive queries?

You can set a maximum bytes billed limit on every query job your backend sends. You can also run a dry-run check first to inspect the estimated scan size before execution.

The query runs. The emails stay hidden.