How to Configure LlamaIndex CockroachDB Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a llamaindex cockroachdb prevent delete workflow, restrict the database role permissions. You must remove drop and delete rights from the account your AI agent uses. Many teams connect their AI apps to CockroachDB using a standard app role. This broad role often has full write and delete rights across every table. If a prompt tricks the model, the agent can wipe out production rows. Using a tight role stops the database from running destructive statements. How llamaindex cockroachdb

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 a llamaindex cockroachdb prevent delete workflow, restrict the database role permissions. You must remove drop and delete rights from the account your AI agent uses. Many teams connect their AI apps to CockroachDB using a standard app role. This broad role often has full write and delete rights across every table. If a prompt tricks the model, the agent can wipe out production rows. Using a tight role stops the database from running destructive statements.

How llamaindex cockroachdb prevent delete works

LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. Its natural language query engine turns user questions into raw SQL statements. If you do not specify target tables, the engine pulls all schema context. It then sends the generated SQL statement straight to your CockroachDB cluster. The official LlamaIndex docs warns that running arbitrary SQL carries a real security risk. The authors suggest using restricted roles, read-only databases, or sandboxing to stay safe.

To block row removal in CockroachDB, admins create a dedicated database user. You grant this user select rights on the specific tables the agent needs. If the agent must add new records, you can grant insert rights too. You leave out delete, drop, and truncate privileges on all production tables. When the query engine sends a delete statement, CockroachDB checks the role permissions. The cluster rejects the query right away and returns a permission error.

Why database roles are only half the fix

Native CockroachDB privileges do a great job of blocking destructive commands at rest. They decide who can log in and which table actions a role allows. Still, static database roles cannot inspect what individual statements do in flight. A role with select rights can still dump millions of sensitive rows at once. If an agent needs update rights, a bad query can overwrite every row. Static roles also treat every query from the app pool the same way.

Database roles also lack context about which user or agent triggered the query. Everything shows up in the database logs under one shared service account. Also, select grants do not stop sensitive fields from reaching the language model. Raw emails, phone numbers, card numbers, and national IDs flow back in query results. Teams need a way to check queries and rewrite matched fields in results.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Best practices for safer text-to-SQL agents

Start by naming the exact tables your LlamaIndex query engine is allowed to read. This stops the engine from pulling your entire database schema into the prompt. Next, create a separate CockroachDB role just for your AI query engine. Never share the main backend service account with an automated text-to-SQL workflow. Give this new role read access only to the safe tables you picked.

Test your setup by asking the agent to remove a test row. Check that CockroachDB blocks the action and logs the failed attempt. Review your table grants often as your schema grows and changes over time. New tables might inherit broad default grants if you are not careful. Keep write workflows separate from read workflows whenever you build agent tools. If an agent must change data, use a strict tool instead of raw SQL. This keeps your core records safe from bad prompts and model mistakes.

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

Can LlamaIndex block delete queries on its own?

No, the LlamaIndex SQL query engine does not enforce database security rules by itself. It relies onSQLAlchemy to run whatever SQL statement the language model writes. You must enforce delete blocks at the database or query execution layer.

What happens when you do not list tables in LlamaIndex?

If you do not pass a table list, the engine reads every table schema. This exposes internal tables to the model and raises the risk of bad queries. Always pass a strict list of safe tables when you set up the engine.

Should my AI agent use a read-only CockroachDB role?

Yes, a read-only role is the safest base choice for most text-to-SQL apps. It lets the agent answer questions while blocking delete, update, and drop commands. If the agent must write data, grant insert rights only on one specific table.

The query runs. The emails stay hidden.