How to Configure LangChain ClickHouse Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up langchain clickhouse permissions by creating a limited database user for your agent. Then you grant that user read rights on specific tables or columns. Many teams start by giving the agent a broad admin account to move fast. Broad roles let an agent read private fields or run heavy queries by mistake. A strict setup stops the model from touching tables outside its job. How native langchain clickhouse permissions work ClickHouse manages users, roles, row rules, settings profiles, a

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 langchain clickhouse permissions by creating a limited database user for your agent. Then you grant that user read rights on specific tables or columns. Many teams start by giving the agent a broad admin account to move fast. Broad roles let an agent read private fields or run heavy queries by mistake. A strict setup stops the model from touching tables outside its job.

How native langchain clickhouse permissions work

ClickHouse manages users, roles, row rules, settings profiles, and quotas as SQL objects. You need a storage path on the server to turn on SQL access control. You also need at least one admin user with access management turned on. That admin can create a new user account just for your LangChain app. A user can only grant rights that they hold themselves.

When you create the user, you set how the account logs in. You can also limit which hosts the agent can connect from. Next, you attach default roles and user settings to that account. For a LangChain tool, you should only grant select rights on needed data. ClickHouse lets you grant select rights on single columns in a table.

Suppose you grant select rights on only two columns in a table. The agent can run queries that ask for those two columns alone. If the agent asks for a third column, the database blocks the query. A select all query also fails unless the table holds only those granted columns. You can also grant rights on table groups that share a name prefix.

How LangChain agents run database queries

A LangChain agent combines a chat model with one or more database tools. The agent reads a user prompt and decides which tool to call. It turns natural language questions into SQL queries and sends them to ClickHouse. Then the database runs the query and sends the rows back. Finally, the agent reads the rows and writes an answer for the user.

Every query from the agent uses the same database user account. ClickHouse checks that account against its roles and column grants on each run. If the model writes a drop statement, the read-only role rejects it. If the model asks for blocked columns, the database returns an error. This native setup gives you a solid first line of defense.

Where static database roles fall short for AI

Native roles decide who can log in and which columns they can read. They do not inspect what individual queries do while in flight. An agent Often needs access to customer tables to answer support questions. Those tables might hold emails, phone numbers, card numbers, or national IDs. If you grant column access, every query returns those raw values to the model.

ClickHouse Access Management + AI Agent Permissions: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

If you block the column in ClickHouse, queries using that column will fail. Static roles give you an all or nothing choice on sensitive columns. Also, every prompt through the agent shares one static database login. Your database logs show the app user, not the human who asked the question. You also cannot pause a risky query for human approval before it runs.

What to check before going to production

Start by auditing every table your LangChain tool can see in ClickHouse. Remove select grants on system tables and internal logs right away. List the exact columns the agent needs to answer user prompts. Grant select rights on those columns alone instead of the whole table. Test your agent to make sure it does not run select all queries.

Next, set up quotas and settings profiles on the ClickHouse user account. Quotas stop a confused agent loop from eating all your server memory. Limit the hosts that can use the agent login to your app servers. Check your setup for columns that hold emails, phone numbers, or card numbers. Plan how you will mask those fields so results rewrite matched data.

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 do select all queries from my LangChain agent fail in ClickHouse?

ClickHouse blocks select all queries when a user only has partial column grants. The query only works if the user has rights on every column by default. Update your agent prompt so it asks for granted column names by name.

Can a ClickHouse user grant extra rights to another agent account?

A ClickHouse user can only grant rights that they already hold themselves. They also need the access management flag turned on to manage other accounts. Never give your LangChain database user the right to create users or grants.

How do I handle emails and card numbers in agent query results?

Database column grants either show the whole column or block the query completely. To keep queries working, use data masking that rewrites matched fields in results. This lets the agent process rows while hiding raw emails and card numbers.

The query runs. The emails stay hidden.