AI Governance
AI access to QueryDesk is off by default and opt-in per database. When you enable it, the AI runs as a real user and is bound by the same permissions, data protection, approval rules, and audit trail as a person — plus a set of AI-specific caps you control. This page covers the admin settings and the guardrails behind them.
These controls apply to every AI surface — the MCP server and the in-app AI assistant both go through the same governed pipeline, so there is nothing to configure twice.
Enabling AI per database
AI access is configured on each database's edit page, under AI Configuration. It is disabled by default: while it's off, the AI cannot see or query the database at all — it won't even appear in the AI's list of databases.
- Name
AI access- Type
- Off, Read only, or Read and write
- Description
How much the AI agent may do on this database. Off hides the database from the agent. Read only lets it run only statements that read data: QueryDesk refuses any write, and the database enforces read-only where it supports it. Read and write lets it write too, and each write still needs the reviews its credential requires. A new database starts with AI access off and its read-only setting on, so turning AI access on through the API or Terraform without
ai_read_onlymakes it Read only. A database added before AI read-only existed shows Read and write if AI access was on, so its agents work as they did. Choosing Off keeps the level you had chosen, ready for when you turn access back on. Only a super admin can change it, and the API and the Terraform provider set it asai_enabledandai_read_only.
- Name
Max rows AI may request- Type
- default: 500
- Description
The AI agent's queries are capped to at most this many rows. Applies to every AI query and sample against this database.
- Name
AI timeout (seconds)- Type
- default: 10
- Description
How long an AI query on this database may run, whichever credential it uses. It is a whole number of seconds, 1 or more, and is kept while AI access is off. Only a super admin can set it, and the AI agent cannot change it.
- Name
Allowed credentials- Type
- allowlist
- Description
Only the credentials you check here may be used by the AI. The AI picks one of them to run as; a credential that isn't allowed is invisible to it.
Choose Read only to refuse the AI's writes, whatever the credential could do. The allowed-credentials allowlist then scopes what it can read. A read-only database user adds a third check, and on SQL Server and MongoDB it is the only one beyond the parser. Allow a credential with elevated rights only if you also want the AI to be able to use them, under Read and write and the approval gate below.
What Read only enforces
Under Read only, an AI query runs only when every statement is a read. Two checks enforce it:
- QueryDesk's parser. Any statement that isn't provably a read is refused before anything reaches the database or asks for a review:
INSERT,UPDATE,DELETE, a data-modifying CTE, DDL,SELECT … FOR UPDATEand other row locks, session and transaction control such asSETandCOMMIT, and named functions with side effects such aspg_terminate_backend,set_config,dblink_exec,lo_import,pg_advisory_lockand MySQL'sGET_LOCK. It refuses PostgreSQL's replication slot, WAL, backup and statistics reset functions such aspg_drop_replication_slot,pg_switch_walandpg_stat_reset, SQL Server'sOPENQUERY,OPENROWSETandOPENDATASOURCE, which run SQL on another server, and Oracle'sutl_httpand the other network packages (utl_tcp,utl_smtp,utl_mail,utl_inaddr,dbms_ldap), andhttpuritypeandurifactory, which fetch a URL, StarRocks'FILES(), and Doris'ss3(),hdfs(),local()andhttp(), which read files and URLs, andquery(), which runs SQL on a catalog's source. On AlloyDB it refuses AlloyDB AI's model calls, any function inaiorgoogle_mlandembedding()andml_predict_row(), which send what they're given to a model, and the columnar engine's and index advisor's functions. On ClickHouse it refuses every table function, fromnumbers()tourl(),s3()andremote(). On MongoDB a statement is a read only when it is a read command such asfind,countDocumentsordistinct, or anaggregatewhose stages all read, so$outand$mergeare refused, and so is every other command. SQL the parser can't read is refused too. The agent gets an error saying the database is read-only for AI, there is no pending query and nothing is posted to Slack, and the audit log shows the query as blocked by AI read-only. - Your database. A query that passes the parser runs where the database refuses writes itself, so a function the parser can't see into fails if it writes:
| Database | How the database enforces it |
|---|---|
| PostgreSQL | The statements run in a read-only transaction that is always rolled back. |
| Google AlloyDB | The statements run in a read-only transaction that is always rolled back, as on PostgreSQL. That doesn't stop AlloyDB AI's model calls or the columnar engine, so the parser refuses those. |
| CockroachDB | The statements run in a read-only transaction that is always rolled back, which also refuses a function's write. |
| TimescaleDB | The statements run in a read-only transaction that is always rolled back, as on PostgreSQL. |
| MySQL | The statements run in a read-only transaction that is always rolled back. |
| MariaDB | The statements run in a read-only transaction that is always rolled back, as on MySQL. |
| OceanBase (MySQL mode) | The statements run in a read-only transaction that is always rolled back, which also refuses a function's write. |
| Oracle | The statements share one read-only transaction that is always rolled back. Oracle also refuses DML from a function called in a query. |
| Amazon Redshift | The statements share one transaction opened with BEGIN READ ONLY that is always rolled back. |
| ClickHouse | Every request carries the readonly setting, which refuses writes and any settings change. With the parser refusing table functions, an agent reads tables, plain views and system tables only. |
| TiDB | The statements run in a read-only stale-read transaction one second in the past, which is always rolled back. TiDB refuses a plain read-only transaction. |
| SQL Server | Nothing. SQL Server has no read-only transaction, so the parser is the only check. The parser refuses the linked-server calls OPENQUERY, OPENROWSET and OPENDATASOURCE. Allow only credentials whose login has nothing beyond db_datareader. |
| MongoDB | Nothing. MongoDB has no read-only transaction, so the parser is the only check. Allow only credentials whose user has MongoDB's read role. |
| StarRocks | Nothing. StarRocks accepts SET TRANSACTION READ ONLY and transaction_read_only but enforces neither, so the parser is the only check. The parser refuses FILES(), which reads object storage. Allow only credentials whose user has nothing beyond SELECT. |
| Apache Doris | Nothing. Doris accepts SET TRANSACTION READ ONLY and tx_read_only but enforces neither, so the parser is the only check. The parser refuses s3(), hdfs(), local(), http() and query(). Allow only credentials whose user has nothing beyond SELECT_PRIV. |
Read only applies to AI queries alone. A person's own queries on the same database run, or wait for their review, exactly as before. It applies as the database is set when a query runs: an AI write that was waiting for review when you chose Read only is refused when the agent reruns it or it is run from pending queries, even if it was approved. Out of reach: writes a function makes through a connection or transaction of its own (PostgreSQL dblink called inside a function, and Oracle autonomous transactions), and a function of your own that calls a PostgreSQL server-control function or an Oracle network package, which the parser can't see and the read-only transaction allows.
Per-query caps
Beyond the row cap, two more limits protect your system automatically:
- Result size. An AI query result that is too large to hold in memory fails with an error rather than being returned, so a single oversized result can never destabilize the instance. On a self-hosted install the ceiling is an organization-wide setting: a super admin sets it under Max result memory (MB) in any database's settings, and it applies to every database. On the shared cloud it is fixed at 100 MB.
- Timeout. Every AI query runs at the database's AI timeout, which starts at 10 seconds. The agent cannot ask for more or less time, and
list_databasesshows it the value for each database. A query held for peer review runs at the AI timeout in force when it runs, not the one in force when it was submitted. A credential's Timeout (seconds) caps users' queries only and does not apply to AI queries. Left blank, it means no cap for users and has no bearing on AI queries.
Peer-review approval
QueryDesk's existing peer-review model applies to AI queries unchanged. Each database credential has a reviews required count:
reviews_required = 0— queries run immediately and return results.reviews_required = N(N > 0) — a query must collect N approvals from other users with approve permission before it can execute. Self-review does not count — the person (or AI acting as them) who submitted the query cannot approve their own.
Because the AI acts as a user, an AI query against a credential that requires review follows the standard pending queries flow:
- The AI submits a query; because review is required, no rows are returned. Instead the AI gets back a
query_idwith statuspending_approval, and the query appears in the pending-queries list for a reviewer to approve. - A reviewer approves the exact SQL. Approval only unlocks execution — for AI queries it does not auto-run.
- The AI re-requests the approved query by its
query_id. The stored SQL is immutable, so the AI cannot smuggle in different SQL after approval, and results are returned to it live.
If the AI decides a pending query is no longer wanted, it can withdraw it (the cancel_query tool) as long as it hasn't executed yet.
While a query is awaiting peer review, its SQL is shown to the reviewer exactly as written — data-protection redaction is applied to results, not to the SQL a reviewer must approve.
Data protection
AI queries are redacted per the user's data-protection policies, exactly like queries that user runs by hand. A direct grant's policy applies first. Otherwise the policy on every one of the user's role grants is combined, the stricter action wins per column, and a role with no policy lifts nothing. The database's AI data protection policy is then combined on top. get_database_schema and search_schema mark which columns are hidden for the current user, so the AI knows before it queries what it will never be shown, and run_query reports how many referenced columns were masked.
When the database has an AI data protection policy, an AI query gets the stricter of that policy and the user's own policies, combined as above, on every column. A peer review does not change this: an AI query that was approved on a credential requiring review is redacted the same way as one that needed no review. An AI query cannot be run unredacted, and the AI cannot run a member's approved unredacted run for them.
Service accounts
A service account is not a privileged account. An unattended agent that connects with one is governed like this:
- Tools. It can call only the tools turned on for it. None is on by default.
- Database access. It reaches a database that is open to all users, one that grants it directly, or one granted to a role it is assigned. It has no super admin bypass, and a role's super admin, manager and billing admin permissions do not apply to it.
- Credentials. On a database it reaches it runs only as an AI-allowed credential, and only while AI access is on for that database.
- Caps. The row cap, the result size limit and the database's AI timeout apply as they do to every AI query.
- Data protection. The policy on its direct grant applies first. Otherwise the policies on its roles' Run Queries grants are combined, the stricter action wins per column, and a role with no policy lifts nothing. The result combines with the database's AI data protection policy the same way.
- Peer review. A credential that requires review holds its query until members approve it. A service account never approves a query, its own or anyone else's.
- Audit log. Its queries carry the AI badge and its name in place of a user, also after it is revoked.
- Reading the audit log. With the
search_audit_logtool on, it reads only the queries it ran. Turn on Audit log viewer for it, or assign it a role that carries Audit log viewer, and it reads every query on the databases it reaches.
Where a tool is limited to the caller's own things, such as retained results and private saved queries, the service account is the caller. It never gets a member's.
AI labeling and the audit log
Every query records how it originated, so AI activity is never indistinguishable from human activity:
- Queries run by a person are labeled as human.
- Queries run through the in-app AI assistant or the MCP server are marked as AI-originated and carry a blue AI badge.
- An AI write refused by Read only carries a red Blocked badge, reads "query blocked at", and says under the entry that nothing was sent to the database.
The AI badge appears everywhere queries are listed, including the pending-queries list and the audit log, so reviewers can tell at a glance that a query came from the AI, and every AI query is attributed to the user who authorized it, or to the service account that ran it. AI queries that originated from an in-app conversation are also linked back to that conversation for traceability.