How to Configure OpenAI Agents SDK ClickHouse Connect

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openai agents sdk clickhouse connect workflow by wrapping the Python driver inside an agent tool function. That function logs in with a restricted database role and runs read queries for the model. Many engineering teams start this setup with a broad admin user to move fast during early testing. Broad database permissions let a single bad prompt read private columns or overload your cluster. How the native openai agents sdk clickhouse connect workflow runs In the agent framework

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 openai agents sdk clickhouse connect workflow by wrapping the Python driver inside an agent tool function. That function logs in with a restricted database role and runs read queries for the model. Many engineering teams start this setup with a broad admin user to move fast during early testing. Broad database permissions let a single bad prompt read private columns or overload your cluster.

How the native openai agents sdk clickhouse connect workflow runs

In the agent framework, you define a Python function that the model can call as a tool. The model reads the user prompt and decides when to call that function. Your tool code uses the Python driver to open a session to the database server. The driver sends the query string from the agent and brings back the result rows.

To keep this setup safe, you should create a dedicated database user for the agent. ClickHouse manages users, roles, row policies, settings profiles, and quotas through SQL statements. Turning on SQL-driven access control requires a storage folder and an admin user with access management rights. When you create the agent user, you set its login method and allowed client hosts.

You also assign default roles and per-user settings when you create that database account. An admin user can only grant privileges that they already hold themselves. Instead of giving full table rights, you can grant read rights on specific columns only. When a user only has rights on two columns, queries asking for other columns fail.

A query that selects all columns with a star also fails and returns no data. It only works if the table contains nothing but those exact granted columns. In newer database versions, a trailing star lets you grant access by table name prefix. This native setup keeps the agent inside a strict set of tables and columns.

What native database roles solve and what they leave open

Native database roles and column grants solve the first part of the security problem. They decide which account can log in and which columns that account can read. If an agent tries to drop a table or read a blocked column, the database stops it. Quotas and settings profiles also help limit how much memory or time a user spends.

Still, static roles do not inspect what individual queries do while they run in flight. Once the driver logs in, every query from that agent shares the same database identity. You cannot tell which end user or which prompt triggered a heavy analytical scan. If an allowed table holds emails, phone numbers, or card numbers, the query returns them in full.

ClickHouse Access Management + OpenAI API Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Column grants block whole columns, but they cannot rewrite sensitive values inside allowed text columns. Static roles also require your app to hold long-lived database keys in its runtime memory. If a prompt tricks the agent into dumping thousands of rows, static grants will allow it. Teams need a way to inspect queries and mask sensitive fields before results reach the model.

Steps to harden your agent database tool

Start by creating a read-only role that only covers the exact tables your agent needs. Grant select rights on safe columns and leave out columns with national IDs or secrets. Bind the agent user to the specific IP addresses where your agent app runs. Set strict query timeouts and row limits on the user profile to stop runaway scans.

Next, limit how the agent builds its queries inside your Python tool code. Do not let the model pass multiple statements or raw admin commands into the driver. Log every prompt alongside the SQL statement so your team can review agent actions later. Combine these native database rules with runtime checks that mask emails and card numbers in results.

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 does a select star query fail for my restricted agent user?

When you grant read rights on specific columns only, the database blocks select star queries. The query returns no data unless the table holds only the columns you granted.

Can I restrict which hosts the agent driver uses to log in?

Yes, the user creation statement lets you set the exact client hosts allowed to log in. Requests coming from any other IP address or host name will fail right away.

Do database column grants hide sensitive text inside allowed columns?

No, column grants are all or nothing for each column you permit the agent to read. To hide emails, phone numbers, or card numbers inside returned rows, you need data masking in flight.

The query runs. The emails stay hidden.