How to Configure Vercel AI SDK ClickHouse Guardrails

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up vercel ai sdk clickhouse guardrails by pairing strict tool schemas with database roles. This setup stops AI models from running bad queries or reading secret tables. Many teams connect their AI app to the database with one broad admin account. That choice puts every table at risk when a prompt goes wrong. A model might pull raw emails or run a heavy query that slows the server. How to set up vercel ai sdk clickhouse guardrails Start by locking down what the AI tool can ask for in y

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 vercel ai sdk clickhouse guardrails by pairing strict tool schemas with database roles. This setup stops AI models from running bad queries or reading secret tables. Many teams connect their AI app to the database with one broad admin account. That choice puts every table at risk when a prompt goes wrong. A model might pull raw emails or run a heavy query that slows the server.

How to set up vercel ai sdk clickhouse guardrails

Start by locking down what the AI tool can ask for in your app code. In the Vercel AI SDK, you define tools with strict input rules. Instead of letting the model write raw SQL, give it fixed parameters. The model picks a date range or a metric name from an allowed list. Your app code then builds a safe query from those checked inputs.

Next, set up SQL-driven access control inside ClickHouse to back up your app rules. ClickHouse stores users, roles, row policies, settings profiles, and quotas as access entities. You turn this on by setting a storage directory 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.

Create a dedicated database user just for your AI app. When you create the user, set the login method and allowed client hosts. Assign default roles and per-user settings to keep resource use low. Then, grant read access only to the exact columns the AI needs. If a user only has grants for two columns, ClickHouse blocks a full table read. The query fails and returns no data unless the table has only those two columns. Since version 24.10, you can also grant read rights across tables using a name prefix.

What native database rules solve and what they miss

Native database roles and column grants stop unauthorized table reads at the source. Even if an app bug lets a model write a broad query, ClickHouse blocks it. Host limits and user quotas also stop a runaway loop from taking down your cluster. These native rules form a strong base for your AI app.

AI Guardrails + ClickHouse Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static database roles only check who logs in to run the query. They cannot inspect what individual statements or results do in flight. Suppose your AI tool needs to read a customer table to answer support questions. If you grant access to that table, the query returns everything in those allowed columns. Native grants do not mask emails, phone numbers, card numbers, or national IDs in results. Every AI request also shares the same static app user in the database logs. When a strange query runs, your team cannot tie it back to a specific user.

Adding runtime checks for AI database queries

To close this gap, teams pair native database roles with runtime query checks. Runtime checks look at each query and its output before the AI model gets the data. Data masking rewrites matched fields like emails or card numbers in the query results. This lets the AI answer questions without pulling raw personal data into the prompt context. You also get clear logs that show which app request triggered each database read.

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 does my AI tool fail when running a select all query?

ClickHouse blocks full table selects when a user only has grants on specific columns. Update your AI tool code to ask for the exact allowed column names instead.

How do I stop the AI model from changing or deleting ClickHouse data?

Create a separate ClickHouse user for your AI app and grant only read rights. Never share your main app writer account with your AI tool functions.

Can native ClickHouse grants hide sensitive text inside an allowed column?

No, column grants are all or nothing for each column you allow. To hide card numbers or emails inside a column, you need runtime data masking.

The query runs. The emails stay hidden.