How to Configure LangChain ClickHouse Read Only Access
You set up langchain clickhouse read only access by creating a restricted database user. Then you pass those read-only login keys to your AI agent database tool. Many teams start by giving their agent a default admin account to save time. That broad role lets a language model drop tables or change live data by mistake. Setting strict read rules in the database stops bad writes before they happen. How to set up langchain clickhouse read only access in your database ClickHouse manages users, ro
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 read only access by creating a restricted database user. Then you pass those read-only login keys to your AI agent database tool. Many teams start by giving their agent a default admin account to save time. That broad role lets a language model drop tables or change live data by mistake. Setting strict read rules in the database stops bad writes before they happen.
How to set up langchain clickhouse read only access in your database
ClickHouse manages users, roles, row policies, settings profiles, and quotas as access items. You can create and manage all of these items with SQL statements. Before you start, your server needs a storage folder set for access control. You also need an admin user with access management rights turned on. An admin user can only grant rights that they already hold themselves.
Creating a new user takes the create user right on the server. When you make the account, you set the login method and allowed host addresses. You also assign default roles and specific user settings during this step. To keep the agent from writing data, you only grant select rights to this user. You can grant select on a whole table or only on specific columns.
Column grants help when a table holds both public metrics and private columns. If a user only has rights on two columns, they can query those two columns. Any query asking for a third column fails right away. A select all query also fails and returns no data at all. Select all only works if the table holds just the allowed columns. In ClickHouse 24.10 and newer, a trailing asterisk grants rights by table name prefix. Once this user is ready, you hand its login details to your LangChain tool.
What native database roles solve and what they miss
LangChain agents take a plain language question and turn it into a database query. The agent picks which tool to call to finish the user task. Then it runs the query against your data source and reads the output. A native read-only user makes sure those generated queries never alter or delete rows. It acts as a hard wall against data loss from bad model output.
Still, native database permissions only check who logs in and which tables they touch. They do not inspect what individual queries do while they run in flight. An agent with select rights on a customer table can still read every row. If that table holds emails, phone numbers, card numbers, or national IDs, the query returns them. Those sensitive fields flow straight into the language model prompt and chat logs.
Auditor Read-Only Access + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Column grants can block access to known private columns, but setup takes manual work. Every time a schema changes, an admin must update grants across many tables. Also, if a user runs a select all query on a partly restricted table, it fails. That failure breaks many default agent tools that inspect tables with broad queries. Data masking solves this by rewriting matched fields in results without breaking the query.
Why static agent credentials create audit gaps
Storing a static database login inside an agent app creates another big risk. Every person and workflow using that agent shares the exact same database user. When you check the database logs later, every query comes from one shared account. You cannot tell which human user or app call triggered a slow query.
Shared credentials also live in config files or app memory for months. If a developer copies that config file to a test machine, the key spreads. Rotating that password means updating both the database and the agent app at once. Teams need a way to link each query to an identity and mask fields by default.
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 a select all query fail for my read-only ClickHouse user?
ClickHouse blocks select all queries when a user only has grants on specific columns. The query only runs if the table contains just the granted columns or you list allowed columns.
Can a ClickHouse user grant read rights to another agent account?
A ClickHouse user can only grant privileges that they already hold themselves. They also need access management rights enabled on their account to create users or assign grants.
Does a read-only database role stop an AI agent from reading sensitive text?
No, a read-only role only stops data changes and table drops. Any allowed column containing emails, phone numbers, card numbers, or national IDs will still return in query results unless masked.
Related guides
In this post