How to Configure LlamaIndex ClickHouse Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a llamaindex clickhouse sandbox by creating a restricted database user with narrow table rights. Then you point your natural language query engine to that restricted user account. Many teams start by linking their AI app to a broad admin account for quick testing. That shortcut lets generated SQL read every table or alter data across the whole cluster. How a llamaindex clickhouse sandbox works LlamaIndex connects to relational and analytical databases through a light wrapper around

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 a llamaindex clickhouse sandbox by creating a restricted database user with narrow table rights. Then you point your natural language query engine to that restricted user account. Many teams start by linking their AI app to a broad admin account for quick testing. That shortcut lets generated SQL read every table or alter data across the whole cluster.

How a llamaindex clickhouse sandbox works

LlamaIndex connects to relational and analytical databases through a light wrapper around SQLAlchemy. Its table query engine turns plain English questions into SQL queries and runs them right away. If you do not pass a specific list of tables, the engine pulls all schema context. That behavior wastes tokens and exposes internal tables to the language model.

Official LlamaIndex guides warn that running generated SQL brings real security risks. The authors suggest using restricted roles, read-only databases, and sandboxing to limit potential damage. In ClickHouse, you build this boundary using SQL-driven access control. You first set up a local storage path on the server to hold access entities. An admin account with access management rights can then create users, roles, quotas, and row policies.

When you create the sandbox user, you set the login method and allowed client hosts. You also attach default roles and user settings to lock down the account. ClickHouse lets you grant read rights on specific columns instead of the whole table. If a user only has rights on two columns, a wildcard query on the table fails. You can also grant read rights across a group of tables using a name prefix. This setup keeps the query engine inside a small, safe corner of your warehouse.

What native database roles solve and what they miss

Native database roles and column grants stop an AI agent from dropping tables or reading secret columns. They also let you cap resource usage through ClickHouse quotas and settings profiles. This native setup decides which account can log in and which objects it can see.

ClickHouse Access Management + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static database privileges cannot inspect what an individual query does in flight. Once the agent logs in, it can run any statement allowed by its static role. If an allowed table holds customer emails, phone numbers, or card numbers, the query returns them raw. Those raw values then flow straight into the model prompt and external logs. Native roles also require you to store static database credentials inside your app settings. Also, native roles do not pause a risky query to ask a human for approval.

Why runtime query checks matter for AI agents

Text-to-SQL engines write new queries on the fly based on user prompts. Even with a small table list, a prompt can trick the model into pulling bulk rows. A good sandbox pairs native ClickHouse permissions with controls that check each statement before it runs. Dynamic data masking rewrites matched fields like emails or national IDs in the query results. That step keeps sensitive values out of the language model context while preserving analytical value. Statement-level logs also show teams which agent prompt triggered each database query.

Check ClickHouse queries and results before execution

Access control in ClickHouse is essential setup. Setup alone does not check single queries for risk or rewrite sensitive strings in returned rows. By design, hoop.dev sits beside the server as a sidecar for your ClickHouse and parses every statement before execution.

First, hoop.dev guardrails block disallowed deletes, drops, and alter mutations. Then hoop.dev data masking rewrites sensitive string columns in responses and logs each decision per resource. Read the docs and source on GitHub.

Frequently asked questions

Why does my wildcard query fail in a restricted ClickHouse account?

ClickHouse blocks wildcard queries when a user only has read grants on specific columns. You must list the allowed column names in the query or grant rights on every column by default.

How do I stop LlamaIndex from reading my entire database schema?

Pass an explicit list of target tables when you set up the table query engine. Without that list, the wrapper pulls schema details from every table the database user can see.

Can ClickHouse users grant permissions to other sandbox accounts?

No, a ClickHouse user can only grant privileges that they already hold themselves. They also need explicit access management rights enabled by an admin to create users or grant roles.

The query runs. The emails stay hidden.