How to Configure OpenHands ClickHouse Guardrails
You set up openhands clickhouse guardrails by creating restricted SQL roles for your agent. You also add column grants, row policies, and quotas inside the database. Engineering teams often give AI coding agents broad admin keys during initial testing. When an autonomous agent holds wide permissions, one bad prompt can drop tables. It can also pull sensitive customer records into external model logs. Setting up native openhands clickhouse guardrails ClickHouse manages users, roles, row polici
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 openhands clickhouse guardrails by creating restricted SQL roles for your agent. You also add column grants, row policies, and quotas inside the database. Engineering teams often give AI coding agents broad admin keys during initial testing. When an autonomous agent holds wide permissions, one bad prompt can drop tables. It can also pull sensitive customer records into external model logs.
Setting up native openhands clickhouse guardrails
ClickHouse manages users, roles, row policies, settings profiles, and quotas as SQL objects. Before you create these rules, you must turn on SQL-driven access control. This step needs a storage folder defined in the server settings. You also need at least one admin account with user management rights enabled. An admin can only hand out permissions that they already hold themselves.
Once you turn on SQL management, you create a dedicated user for OpenHands. Creating this account requires user creation privileges on the database server. During user setup, you pick the login method and limit allowed source hosts. You also attach default roles and custom settings to the agent profile.
Next, you limit what data the agent can read during a task. You can grant read rights on specific columns rather than whole tables. If the agent queries allowed columns, the database returns the data as usual. If the agent asks for a restricted column, the database blocks the query. A wildcard query across all columns also fails and returns no data. That wildcard query only works if the table holds just the allowed columns. Recent database versions also let you grant permissions using a table name prefix. You place an asterisk at the end of the prefix to match tables.
How row policies and settings profiles limit agent queries
Column grants block whole fields, but tables often mix safe and private rows. ClickHouse lets you create row policies as SQL access objects to filter data. A row policy acts like a filter on every query the agent runs. This keeps the agent inside one tenant or one test dataset at all times.
AI agents can also write heavy queries that eat up server memory. You prevent this by attaching settings profiles and quotas to the agent user. Quotas cap how many queries or resources a role can use over time. Settings profiles lock down execution limits so the agent cannot change them.
ClickHouse Access Management + AI Guardrails: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database rules solve and what they miss
Native roles, column grants, and quotas do a great job of limiting login rights. They decide who can log in and which tables or columns stay off limits. They also stop a single user account from using all server memory.
Still, database roles only check permissions at login and table level. They do not inspect what individual statements or requests do in flight. If an agent needs a column that holds emails or phone numbers, native grants are binary. You must either block the whole column or expose raw values in results. Static credentials also sit on the machine where the OpenHands container runs. If the agent reads its own environment, it can read those database keys. Native settings also cannot pause a risky command to ask a human first. When an agent holds write access to fix schemas, every valid query runs right away.
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
What happens if OpenHands runs a wildcard query on a column-restricted ClickHouse table?
ClickHouse refuses a wildcard select query and returns no data at all. The wildcard query only succeeds if the user has grants for every single column.
How do you turn on SQL access control for ClickHouse agent roles?
You must configure a storage directory path in the server settings file. You also need at least one user account with access management privileges turned on.
Can native ClickHouse grants mask card numbers or national IDs in query results?
No, native column grants only allow or block access to an entire column. To rewrite emails, phone numbers, card numbers, or national IDs in results, you need dynamic data masking.
Related guides
In this post