How to Configure LlamaIndex CockroachDB Read Only Access
You set up llamaindex cockroachdb read only access by creating a restricted database user. Then you pass that user login to the LlamaIndex SQL wrapper. Many engineering teams start by reusing a general app login for AI agents. This shortcut gives the language model full write permissions on live tables. A bad prompt can then trigger an accidental update or delete statement. Limiting the database role stops the agent from changing your data. How llamaindex cockroachdb read only access works Ll
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 llamaindex cockroachdb read only access by creating a restricted database user. Then you pass that user login to the LlamaIndex SQL wrapper. Many engineering teams start by reusing a general app login for AI agents. This shortcut gives the language model full write permissions on live tables. A bad prompt can then trigger an accidental update or delete statement. Limiting the database role stops the agent from changing your data.
How llamaindex cockroachdb read only access works
LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. Its natural language query engine turns user questions into SQL statements. The engine then runs those generated queries directly against your CockroachDB cluster. Official LlamaIndex docs warn that running arbitrary SQL carries a real security risk. The docs urge teams to use restricted roles, read-only databases, and sandboxing.
To lock down the connection, you first build a dedicated role in CockroachDB. You grant this role select privileges only on the specific tables needed. You do not grant insert, update, delete, or schema change rights. Next, you create a dedicated database user and assign it this read-only role. You then pass this user login string into the LlamaIndex SQLDatabase wrapper.
You should also restrict what schema details the query engine can read. When you set up the query engine, you can name specific tables. If you skip this table list, the engine pulls all schema context. Loading every table bloats the prompt and exposes internal table names. Naming only safe tables keeps the context small and focused.
What native roles solve and what they miss
A read-only role in CockroachDB blocks write queries at the database level. If the model generates a drop or delete command, CockroachDB rejects it. This native control protects your data integrity from bad model outputs. It also limits which tables the agent can query during a session.
Still, database roles only decide who logs in and which tables they read. They do not inspect what individual select statements do in flight. A read-only query can still pull sensitive columns from an allowed table. For example, a select query might fetch emails, phone numbers, or card numbers. Once those rows return, the framework sends them straight into the model prompt.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native roles also leave credential management and audit gaps for your team. The LlamaIndex app still holds a static database password or client certificate. Anyone who reads the app environment variables can copy that database key. Also, CockroachDB logs show every query coming from the same shared app user. You cannot tie a specific SQL statement back to the person who asked.
Reducing risk for text to SQL agents
Teams running text-to-SQL apps need controls beyond basic table permissions. First, keep sensitive columns out of the tables your agent can read. If an agent only needs order totals, do not expose customer national IDs. You can create clean database views that omit private fields. Then you grant the read-only role select rights only on those views.
Second, watch out for heavy queries that can slow down your cluster. A language model often writes bad joins or scans millions of rows. Even a read-only query can eat up memory and CPU on CockroachDB. Set query timeouts and row limits on the database role to stop runaway scans. Combining strict database roles with runtime controls keeps your data safe.
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 LlamaIndex warn about arbitrary SQL execution?
Text-to-SQL engines translate user text into database commands on the fly. Without strict limits, a prompt can trick the model into running harmful queries. LlamaIndex recommends read-only roles and sandboxing to lower this risk.
What happens if I do not pass a table list to LlamaIndex?
If you omit the table list, the query engine pulls all schema context. This exposes every accessible table structure to the language model. Naming specific tables keeps unwanted schema details out of the prompt.
Does a CockroachDB read-only role stop sensitive data leaks?
No, a read-only role only stops the agent from changing or deleting data. The agent can still select sensitive fields like emails or card numbers. You need separate views or data masking to rewrite matched fields in results.
Related guides
In this post