How to Configure LangChain ClickHouse Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up langchain clickhouse credentials by making a limited database user and passing its login details to your agent. This setup lets your AI tool read analytical tables while blocking bad writes. Most teams start by putting a shared admin login into their app settings. That quick fix gives the language model full power over every table. If an agent gets a bad prompt, wide permissions let it drop data or read secret rows. How to set up langchain clickhouse credentials in your database Cl

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 credentials by making a limited database user and passing its login details to your agent. This setup lets your AI tool read analytical tables while blocking bad writes. Most teams start by putting a shared admin login into their app settings. That quick fix gives the language model full power over every table. If an agent gets a bad prompt, wide permissions let it drop data or read secret rows.

How to set up langchain clickhouse credentials in your database

ClickHouse handles users, roles, row rules, settings profiles, and quotas as SQL objects. To turn on SQL access control, an admin sets a storage folder on the server. You also need at least one user account with access management turned on. An admin can only hand out rights that they already hold themselves.

Making a new user takes the create user right on the server. When you make the account for your agent, you pick how it logs in. You can also lock down which host addresses the user can log in from. After that, you attach default roles and user settings to the new account.

Next, you give the agent read rights on specific tables or columns. ClickHouse lets you grant select rights on single columns inside a table. If an agent only has rights on two columns, it can query just those two. A query for any other column will fail right away. A wildcard select query also fails unless the table holds only those granted columns. If your tables share a naming pattern, you can grant rights using a prefix and an asterisk.

How the agent uses database logins at runtime

On the app side, an AI agent pairs a chat model with one or more tools. The agent reads the user prompt and picks which tool to call to finish the job. In a SQL workflow, the agent turns plain questions into SQL queries. It runs those queries against the data source and sends back the answer.

To run those queries, the database tool holds the ClickHouse login details in its settings. Every time the model writes a query, the tool logs in as that same database user. The database checks the user login and host rules before running the SQL text.

Ephemeral Credentials + ClickHouse Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native database roles solve and what they miss

Native ClickHouse users and column grants solve the first layer of access control. They decide which host can log in and which columns the agent can read. Quotas and settings profiles also help cap how much compute a single user can burn.

Still, static database logins leave a big gap during live agent runs. The database checks who logs in, not whether a specific query is safe right now. If a column holds emails, phone numbers, card numbers, or national IDs, a valid select grant returns them in plain text. Data masking rewrites matched fields in results so raw values do not reach the model. Also, a static user cannot ask a human for approval before running a heavy query. When five agents share one login, your audit logs only show one shared username.

Check ClickHouse queries and result columns on the wire

ClickHouse users and row policies decide who connects. They do not check each statement on the wire or redact sensitive string columns in query results. With hoop.dev, you run an open-source proxy, a sidecar for your ClickHouse. It reads ClickHouse's native TCP protocol before queries run while ClickHouse stays in charge of login and grants.

Multi-statement queries and table mutations are split and checked by hoop.dev guardrails. Banned actions are refused with a native ClickHouse error. On returned rows, hoop.dev data masking rewrites String and FixedString columns that match your rules. The audit trail logs each query, table, and verdict. See the MIT-licensed source on GitHub.

Frequently asked questions

Why did my agent wildcard query fail on ClickHouse?

ClickHouse blocks wildcard select queries when a user only has rights on specific columns. Your agent must name the allowed columns in its select query, or the table must hold only those columns.

How do I turn on SQL user management in ClickHouse?

You must set the access control path in the server settings folder. You also need to enable the access management flag on at least one admin user account.

Can I limit which hosts use my langchain clickhouse credentials?

Yes, the create user command in ClickHouse lets you set allowed client hosts. The database will reject login attempts that come from any other network address.

The query runs. The emails stay hidden.