How to Configure Vercel AI SDK ClickHouse Permissions
You set up vercel ai sdk clickhouse permissions by making a dedicated database user with strict read grants. Then you pass that user key into your AI tool definition. Many teams start by giving their AI app the default admin database account. That shortcut lets a bad model prompt read secret tables or drop live data. A scoped database user stops the model from touching tables outside its job. How vercel ai sdk clickhouse permissions work in practice The Vercel AI SDK lets language models call
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 permissions by making a dedicated database user with strict read grants. Then you pass that user key into your AI tool definition. Many teams start by giving their AI app the default admin database account. That shortcut lets a bad model prompt read secret tables or drop live data. A scoped database user stops the model from touching tables outside its job.
How vercel ai sdk clickhouse permissions work in practice
The Vercel AI SDK lets language models call custom tools during a chat. You write a tool that takes inputs and runs a database query. The database checks the user account attached to that tool call. ClickHouse handles users, roles, row rules, settings profiles, and quotas through SQL. To turn on SQL access control, you set a storage folder on the server. You also need an admin user with access management turned on. That admin can only grant rights that they already hold themselves.
When you create a new user for your AI app, you need the create user right. The user setup step lets you pick how the account logs in. You can also lock down which host addresses the app can call from. You can assign default roles and custom settings to that user right away. This ensures the AI tool only logs in from your app server.
Scoping tables and columns for AI tool calls
Once the user exists, you grant read rights on specific tables and columns. ClickHouse lets you grant read access on single columns instead of full tables. If you grant read access on two columns, the AI tool can query only those two. Any query that asks for a third column will fail right away. A wildcard query that asks for all columns will also fail and return nothing. It only works if the table holds just the allowed columns.
Since ClickHouse version 24.10, you can also use a star at the end of a table name. That lets you grant read rights across a group of tables that share a name prefix. This helps when your AI app reads daily log tables that share a common start name. You do not need to update grants each time a new table appears. You can also attach row rules and quotas to the AI role. Quotas help stop a bad loop from burning through server memory.
AI Agent Permissions + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native grants solve and what keeps the session active
Native database roles and column grants solve the first big problem. They decide who can log in and which columns they can read. If the model tries to read a forbidden table, the database blocks it. If someone steals the app key, host limits help block outside calls.
Still, static database grants leave a large gap open during live runs. Once a column is allowed, the database returns every value inside it. An allowed text column or log field might still hold emails, phone numbers, card numbers, or national IDs. Native grants cannot rewrite those fields inside the query results before the model reads them. Also, every end user of your AI app shares the same database account. Database logs show the shared app user, not which person or prompt triggered a bad query. Teams also have to store and rotate the database secret inside their app platform.
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 did my AI tool wildcard query fail after adding column grants?
ClickHouse blocks wildcard queries when a user only has grants on a few columns. Change the tool query to name the exact allowed columns instead of using a star.
How do I let my AI app read new daily tables without manual grants?
Starting in ClickHouse version 24.10, you can add a trailing star to a table prefix in your grant statement. Any new table that starts with that prefix will match the grant.
Can native ClickHouse grants hide emails or card numbers inside a text column?
No, native column grants are all or nothing for each column. If a user can read the column, the database returns all raw text in that column.
Related guides
In this post