How to Configure OpenAI Agents SDK ClickHouse Audit Log
You set up an openai agents sdk clickhouse audit log by pairing agent tracing with database query logs. Your agent app records tool calls while ClickHouse logs the SQL statements that run. Many teams start by giving their agent a single shared database user. When that role is too broad, one bad prompt can pull every table. How the openai agents sdk clickhouse audit log works in practice The OpenAI Agents SDK runs tasks by calling Python functions that you define as tools. When an agent needs
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 audit log by pairing agent tracing with database query logs. Your agent app records tool calls while ClickHouse logs the SQL statements that run. Many teams start by giving their agent a single shared database user. When that role is too broad, one bad prompt can pull every table.
How the openai agents sdk clickhouse audit log works in practice
The OpenAI Agents SDK runs tasks by calling Python functions that you define as tools. When an agent needs data, it builds a query and calls your database tool. That tool opens a client session to ClickHouse and sends the SQL statement. You can track this flow in two places at the same time.
First, the agent framework records the model prompt, the tool call, and the arguments. Second, ClickHouse records the incoming query, the database user, and the execution details. To keep the database side clean, you should create a dedicated user for the agent. ClickHouse manages users, roles, row policies, settings profiles, and quotas through SQL statements. A user who creates roles can only grant privileges that they already hold themselves.
You can lock down the agent role by granting read rights on specific columns only. When you grant select rights on just two columns, queries for other columns fail. A wildcard select query on that table also fails and returns no data at all. It only works if the table holds just the granted columns. This setup makes your database logs much easier to read and audit.
What native logging solves and what it leaves open
Native database roles and agent traces solve the basic problem of who logged in. You can see that the agent service account ran a query at a specific time. Column grants also stop the agent from reading tables or columns outside its scope. This is a strong first step for any team running automated queries.
Still, native setup rules only check permissions when the session starts or when a table loads. They do not inspect what individual statements do in flight before reaching the database. Also, your agent logs and database logs live in two separate systems. The database log shows the SQL statement, but it lacks the user prompt that caused it. The agent trace shows the prompt, but it may miss database errors or row counts.
Audit Log Integrity + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Allowed columns can also hold sensitive fields like emails, phone numbers, or card numbers. If an agent queries those columns, the raw values return straight to the model context. Native column grants are all or nothing, so they do not mask fields in results. If a prompt tricks the agent into running a heavy query, native logs only record the damage after it happens.
Why shared service accounts break audit trails
Most teams give the agent app one static database user and password. Every human user who talks to the agent ends up sharing that single database identity. When you check the ClickHouse log, every query looks like it came from the same bot. You cannot tell which team member or customer session triggered a specific query.
To fix this, teams try to pass user IDs inside SQL comments or app logs. Joining those two log streams by hand takes hours during a security review. If a developer also uses that same database key for testing, the audit trail breaks completely. You need a way to tie every single query back to a real identity and mask sensitive fields in results.
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 ClickHouse restrict an agent to specific columns?
Yes, ClickHouse lets you grant select rights on specific columns of a table. If the agent runs a wildcard select query on a restricted table, the database refuses it and returns no data.
Why are agent traces not enough for a full database audit?
Agent traces show what the model tried to call inside your app code. They do not prove what SQL actually ran on the database server or which rows came back.
How do we stop sensitive fields from reaching the OpenAI model?
Start by revoking select rights on columns the agent never needs to read. For columns the agent must query, use data masking to rewrite emails, phone numbers, and national IDs in results.
Related guides
In this post