How to Configure AutoGen ClickHouse Connect

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an autogen clickhouse connect workflow by giving your agent a database client and a scoped SQL user. First, you register a Python tool function in your agent group and pass it a read-only database role. Many teams start by handing the agent a broad admin account to test fast. That shortcut creates big risks when an agent writes and runs its own queries. A bad prompt can make the agent read secret tables or drop live data. How to set up autogen clickhouse connect A safe setup starts

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 an autogen clickhouse connect workflow by giving your agent a database client and a scoped SQL user. First, you register a Python tool function in your agent group and pass it a read-only database role. Many teams start by handing the agent a broad admin account to test fast. That shortcut creates big risks when an agent writes and runs its own queries. A bad prompt can make the agent read secret tables or drop live data.

How to set up autogen clickhouse connect

A safe setup starts inside the database before you write any agent code. ClickHouse manages users, roles, row policies, settings profiles, and quotas through SQL commands. To turn on SQL access control, you set a storage path on the server. You also need an admin user with access management turned on. Remember that a database user can only grant rights that they already hold.

With SQL access turned on, an admin can create a dedicated user for the agent. Making this user requires the create user privilege on the server. The user creation statement sets how the agent logs in and which hosts it can use. It also sets default roles and custom settings for that specific agent account.

Next, you restrict what tables and columns that agent role can read. You can grant read rights on specific columns instead of the whole table. When you grant access to just two columns, the agent can only query those two. If the agent tries to query a third column, the database blocks the query. A wildcard query for all columns also fails and returns no data at all. It only works if the table holds just the allowed columns. Since version 24.10, you can also use a trailing asterisk to grant rights by table name prefix.

Once the database user is ready, you build the tool function for your agent. Your Python function opens a client session using the scoped user credentials. It takes a SQL string from the agent, runs the query, and returns the rows. You then register this function with your assistant agent and your executor agent.

What native database roles solve and what keeps the session active

Native database roles and column grants solve the first layer of agent safety. They decide who can log in and which columns they can touch. If an agent tries to read a blocked table, the server rejects the run. Host rules also stop someone from using the agent key from an unknown network.

ClickHouse Access Management + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static database grants leave a wide gap during live agent runs. A database role checks who logs in, not what each query does in flight. Allowed columns might still hold raw emails, phone numbers, card numbers, or national IDs. If an agent queries those allowed columns, raw personal data flows right into the model prompt. Static grants also cannot pause a risky query to ask a human for approval. Plus, shared agent keys make it hard to tie a bad query to one person.

How to manage agent queries and sensitive fields

To close these gaps, teams put runtime checks between the agent and the database. Before a query runs, you should check the statement structure and who asked for it. Good workflows tie every agent session back to the human who started the task. That way, audit logs show the real person behind every single database read.

You also need a way to handle sensitive text inside allowed columns. Data masking rewrites matched fields like emails or card numbers in the query results. The agent gets the structure it needs to finish the job, while private details stay masked. For high-risk tasks, you can require a quick peer check before the query hits the server.

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 wildcard queries fail for my ClickHouse agent user?

When you grant read access on specific columns only, the database blocks wildcard queries. The agent must name the allowed columns in every query, unless the table holds only those columns.

Since version 24.10, you can put a trailing asterisk at the end of a table prefix. This grants the agent read rights on all tables that start with that exact name prefix.

What happens if an agent queries allowed columns that hold personal data?

Native column grants return the full text stored in any allowed column. To protect emails, phone numbers, or card numbers inside those columns, you must apply data masking to rewrite matched fields in results.

The query runs. The emails stay hidden.