How to Configure OpenAI Agents SDK ClickHouse Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openai agents sdk clickhouse prevent delete rule with database roles. You give the agent user read grants and leave out delete permissions. Teams often wire an AI agent to ClickHouse with a shared admin login. That shortcut lets the agent run any query it writes. A bad prompt or a model mistake can wipe out key tables fast. Giving the agent its own locked-down database user stops those drops at the database level. How to set up openai agents sdk clickhouse prevent delete The Ope

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 prevent delete rule with database roles. You give the agent user read grants and leave out delete permissions. Teams often wire an AI agent to ClickHouse with a shared admin login. That shortcut lets the agent run any query it writes. A bad prompt or a model mistake can wipe out key tables fast. Giving the agent its own locked-down database user stops those drops at the database level.

How to set up openai agents sdk clickhouse prevent delete

The OpenAI Agents SDK runs Python functions as tools when a model asks for data. When you build a ClickHouse tool, your Python code holds the database login keys. The agent picks the tool, passes a query string, and runs it on ClickHouse. The SDK itself does not parse SQL or block bad commands by default. It trusts the database account to enforce what the tool can and cannot do.

ClickHouse controls what a user can do through SQL access rules. First, an admin turns on SQL access control on the ClickHouse server. That setup needs a storage folder and an admin account with user management rights. Next, the admin creates a new user account just for the OpenAI agent. During creation, the admin sets the login method, allowed host addresses, and default roles. A user in ClickHouse can only hand out rights that they already hold.

To stop deletes, you assign only read rights to the agent role. You grant select rights on the specific tables the agent needs to read. ClickHouse also lets you grant select rights on single columns in a table. If you only allow two columns, the agent cannot read a third column. Even a full star query fails and returns nothing unless all columns are allowed. You can also use a trailing star to grant read rights across matching table names. Because you never grant delete or alter rights, ClickHouse rejects any delete command the agent sends.

What native roles solve and what they miss

Native ClickHouse roles do a great job of blocking full table deletes. If the OpenAI agent writes a delete statement, the database refuses to run it. Column grants also keep the agent away from columns it should never query. This setup gives you a strong baseline for read-only agent workflows.

Still, static database roles only check who logs in and which tables they touch. They cannot check the context of a query while it runs in flight. Many agent workflows need to write new rows or update state without deleting records. Once you give an agent write rights for one task, it holds them for all tasks. A static role cannot pause a risky command and ask a human for approval first.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native column grants are also all or nothing for each query. If an agent queries a table with emails, phone numbers, or card numbers, it gets raw text. If you block that column, a broad query from the agent fails right away. Static roles cannot rewrite emails or national IDs in the results on the fly. They also do not tie a specific database query back to the user who ran the agent.

Why agent tool calls need runtime checks

AI agents do not behave like fixed backend apps with pre-written queries. An agent builds a fresh SQL query each time a user asks a new question. Two users can talk to the same OpenAI agent and trigger very different queries. Yet the database sees every query coming from the same static agent account.

Teams need a way to inspect each statement before it reaches the ClickHouse server. When you check queries in flight, you can block deletes even on accounts with write rights. You can also mask emails, phone numbers, and card numbers in query results before the model reads them. That keeps raw sensitive fields out of OpenAI logs while letting queries finish without errors.

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

Can the OpenAI Agents SDK block SQL delete statements by itself?

No, the SDK just runs the Python tool function that the model calls. Unless you inspect the SQL string or restrict the database role, the query runs as written.

What happens when an agent runs a star query on a column-restricted ClickHouse table?

ClickHouse blocks the star query and returns no data at all. The query only works if the user has read rights on every column in that table, or picks allowed columns by default.

How can an agent read ClickHouse tables that hold emails or card numbers?

You can grant column access to only safe columns, or rewrite matched fields like emails and card numbers in results before the agent gets the data.

The query runs. The emails stay hidden.