How to Configure LangChain ClickHouse Prevent Delete
To set up a langchain clickhouse prevent delete workflow, create a restricted database user. Then, grant that user only read privileges before the agent connects. Many engineering teams start by giving their AI agents a shared database account. Those shared accounts often carry broad write or admin rights for convenience. If an agent misinterprets a prompt, it can drop tables or remove production rows. A single bad query from a language model can wipe out analytics data. How to set up a langch
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 langchain clickhouse prevent delete workflow, create a restricted database user. Then, grant that user only read privileges before the agent connects. Many engineering teams start by giving their AI agents a shared database account. Those shared accounts often carry broad write or admin rights for convenience. If an agent misinterprets a prompt, it can drop tables or remove production rows. A single bad query from a language model can wipe out analytics data.
How to set up a langchain clickhouse prevent delete role
ClickHouse manages users, roles, row policies, settings profiles, and quotas as access entities. Admins create and change these entities using standard SQL statements. Before you create a restricted user, you must enable SQL-driven access control. This setup requires a dedicated storage directory on the database server. It also needs at least one initial account with access management turned on. Once enabled, a user with the create user privilege can make the agent account. Remember that a user can only grant privileges that they already hold themselves.
When you create the user, you set its login method and allowed client hosts. You also assign default roles and specific per-user settings during account creation. To stop the agent from removing data, do not grant delete or alter privileges. Instead, grant only select rights on the specific tables the agent needs to read. You can even grant select rights on individual columns within a table. When you restrict a user to specific columns, queries for other columns fail. Wildcard queries that ask for all columns will also fail and return no data. Those wildcard queries only work if the table holds just the permitted columns. In recent versions, a trailing asterisk lets you grant access by table name prefix.
How LangChain agents run database queries
In a typical setup, a chat model connects to one or more database tools. The agent reads a natural language question from a user or system prompt. Then, the agent decides which tool to call to finish the task. It converts the plain text question into a raw SQL query on its own. Next, the tool runs that generated query against the database using the configured account. Finally, the agent reads the returned rows and writes an answer for the user.
Because the model writes the SQL itself, prompt text cannot stop destructive commands. System instructions that tell a model not to delete data are just polite suggestions. A confused model or a clever prompt injection can ignore those instructions right away. That is why database-level user grants are essential for every AI agent workflow. When the database user lacks delete rights, the server rejects any delete command.
ClickHouse Access Management + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native grants solve and what they leave open
Native ClickHouse roles and column grants solve the main problem of accidental table deletion. They decide who can log in and which tables or columns they can read. If an agent tries to run a delete statement, the database blocks the query. This native setup is a solid first step for any production data team.
Still, static database grants leave several operational gaps open during live agent runs. First, the agent app still holds a long-lived password or key in its config. Anyone who gets that key from the app server can read your analytics data. Second, column grants are all-or-nothing and cannot mask sensitive fields on the fly. If an agent needs a column that holds emails or phone numbers, it gets everything. Native grants cannot rewrite card numbers or national IDs inside query results. Third, some agents need write access for valid tasks, such as logging results. Once you grant write or delete rights for one task, the agent has them everywhere. Static roles cannot pause a dangerous delete command and ask a human for approval.
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
Can prompt rules alone stop a LangChain agent from deleting ClickHouse data?
No, prompt instructions cannot block an agent from sending delete queries to your database. You must remove delete and drop privileges from the ClickHouse user account itself.
What happens if an agent runs a wildcard query on a column-restricted table?
ClickHouse refuses a wildcard select query unless the user has grants for every column. The agent must list only the exact allowed columns in its select statement.
How do I let an agent run occasional deletes without giving full delete rights?
Static database roles cannot tell safe deletes apart from bad ones during a session. You need an approval workflow that checks each statement before the database runs it.
Related guides
In this post