How to Configure LlamaIndex Bigquery Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up llamaindex bigquery least privilege, create a dedicated Google Cloud service account. Then bind read-only permissions to only the specific datasets and tables your agent needs. Many teams start by reusing a broad admin or project editor key for testing. When that key goes to production, the AI agent can read or drop any table. Because text-to-SQL engines run model-generated SQL, broad roles turn a bad prompt into a data breach. How to set up llamaindex bigquery least privilege Llama

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.

To set up llamaindex bigquery least privilege, create a dedicated Google Cloud service account. Then bind read-only permissions to only the specific datasets and tables your agent needs. Many teams start by reusing a broad admin or project editor key for testing. When that key goes to production, the AI agent can read or drop any table. Because text-to-SQL engines run model-generated SQL, broad roles turn a bad prompt into a data breach.

How to set up llamaindex bigquery least privilege

LlamaIndex connects to relational and cloud data warehouses through a light wrapper around SQLAlchemy. Its natural language SQL query engine turns user questions into SQL statements and runs them. If you do not specify which tables to include, the engine pulls all schema context. Pulling every table slows down prompts and exposes internal schema details to the language model. You must restrict access in two places: inside the cloud project and inside the app.

First, create a dedicated service account in Google Cloud for this specific LlamaIndex app. Never share this identity with other backend apps, pipelines, or human developers. Do not grant project-wide roles to this service account. Instead, go to the target dataset or the exact tables the agent should read. Grant the service account permission to read table data only on those specific resources. Next, give the service account project-level permission to run query jobs so BigQuery executes the SQL.

Second, lock down the SQL wrapper inside your LlamaIndex code. Pass an explicit list of allowed table names when you initialize the database object. This step stops the query engine from loading the entire dataset schema into the prompt. Also, set a maximum byte limit on your BigQuery jobs in the client setup. That limit stops a bad model query from scanning terabytes of data and spiking your bill.

What native IAM roles solve and what they leave open

Official LlamaIndex docs warns that running arbitrary SQL queries from text-to-SQL apps is a security risk. It recommends using restricted roles, read-only databases, and sandboxing to reduce that danger. Setting up scoped dataset roles and explicit table lists follows this guidance well. It stops the agent from modifying tables, dropping schemas, or reading unrelated finance and HR datasets.

Still, cloud IAM permissions only check who logs in and which tables they can read. They do not inspect what an individual SQL statement does in flight. Every user who talks to the LlamaIndex agent shares that single service account identity. If an allowed customer table contains emails, phone numbers, card numbers, or national IDs, the query reads them. Cloud roles cannot strip those fields out of a select query on the fly.

Least Privilege Principle + BigQuery IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Dataset permissions also cannot pause a risky query for human approval before it runs. And in your warehouse audit logs, every query shows up under the same service account name. You cannot tell which human user or prompt triggered a heavy or sensitive table scan. Closing that gap requires inspecting queries and rewriting sensitive results at the database wire level.

Auditing and scoping agent queries in production

Before you move your text-to-SQL agent into production, review how it handles sensitive columns. If the model only needs aggregate counts or non-sensitive columns, build an authorized view in BigQuery. Point the LlamaIndex table list at the view instead of the raw base table. This setup keeps raw columns out of the schema context that the query engine reads.

You should also track how the agent uses its credentials over time. Rotate keys or use workload identity so static JSON files do not sit on developer laptops. Check your job history often to spot failed queries where the model guessed restricted table names. Those failures show whether your prompt instructions match the actual table permissions you granted.

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

Why does LlamaIndex pull all tables from BigQuery by default?

When you set up the SQL database wrapper without a table list, it inspects the whole schema. Pass an explicit list of table names so the query engine only loads approved tables.

Can a LlamaIndex text-to-SQL engine modify or delete BigQuery data?

Yes, if the underlying service account has write or owner roles on the dataset. Always assign read-only data permissions so the database rejects any generated update, delete, or drop statements.

How do I handle emails or card numbers inside tables that LlamaIndex queries?

Native table roles allow or block the whole table, though you can set up column rules or views. You can also use data masking in flight to rewrite emails, phone numbers, and card numbers in results.

The query runs. The emails stay hidden.