Query rules
A query rule refuses queries that match a description you write, before they reach the database. Your own TypeSafe Jev-compatible model checks each query against the rules for its database, with your API key.
Who can set it up
Only super admins can connect TypeSafe and write query rules. Rules apply to every query on the databases they cover: a member's, a super admin's, a service account's and an AI agent's.
Connect TypeSafe
Open Settings › Integrations, then select Set up on TypeSafe under Notifications and AI.
- Name
Base URL- Type
- https://
- Description
TypeSafe's API is
https://api.typesafe.ai. To go through a gateway, use its TypeSafe base URL, such as LiteLLM's or Vercel AI Gateway's. Devhub sends requests to/v1/systemoneunder it.
- Name
Model- Type
- string
- Description
A pinned Jev version, such as
jev-1.14.0.jev-latestchanges with each TypeSafe release, and your rules' results can change with it.
- Name
API key- Type
- secret
- Description
Stored encrypted. Devhub doesn't show the key again. To change it, select Replace key.
Select Test connection to check the base URL, model and key before you save.
TypeSafe is separate from the AI integration beside it, which powers AI chat and query suggestions.
Write a rule
Open QueryDesk › Query rules and select Add rule.
- Name
Instructions- Type
- string
- Description
The queries to refuse, as one condition. Write it as a statement that is true of those queries, such as
The statement calls pg_terminate_backend.For two conditions, add two rules.
- Name
Refuse at- Type
- 1 to 99, default 70
- Description
The minimum confidence that refuses a query. TypeSafe recommends 70%. Raise it to refuse fewer queries, or lower it to catch more.
- Name
Applies to- Type
- All databases, Engines, Database groups or Databases
- Description
The databases this rule checks queries on.
- Name
When TypeSafe is unavailable- Type
- Refuse the query (default) or Run the query
- Description
What happens when TypeSafe times out, rejects the API key, or returns a response QueryDesk can't read.
Try a rule before saving
Select Try it under the rule's instructions. Try it opens beside the rule, so you can change the instructions and check again while it stays open. Choose a database, paste a query and select Check query. TypeSafe answers with its confidence, and the drawer shows whether this rule would refuse the query. The query doesn't run, and no query is recorded. Each check is one request to your provider.
What QueryDesk sends to your provider
One request per query, holding:
- the database's engine
- the query's statements, as written
- the columns, types, keys and indexes of the tables the query names, from the database's stored schema
- one yes/no question for each enabled rule that applies to the database
QueryDesk never sends rows or credentials. A query on a database no enabled rule applies to isn't sent at all.
QueryDesk keeps an answer for 10 minutes, so the same query on the same database isn't sent again in that time. Editing a rule, changing the TypeSafe settings or syncing the database's schema sends it again.
What members see
A refused query doesn't run. The query editor shows it in the result window, titled with the rule's name and showing TypeSafe's confidence and the rule's Refuse at. A super admin also gets a link to the rule. The audit log shows the query as failed with this message:
Query rule No backend signals refused this query at 97% confidence. Edit the query, or ask a super admin about the rule.
When TypeSafe is unavailable
Each rule decides. If any rule that applies is set to Refuse the query, the query doesn't run. The query editor titles it Not checked by query rule and the rule's name, with the reason, and the audit log message names that rule and the reason. If every rule that applies is set to Run the query, the query runs, and Devhub logs a warning. QueryDesk waits 10 seconds for TypeSafe and doesn't retry during a run.
To remove TypeSafe, delete your query rules first.
Limits
TypeSafe reads the query's SQL, including its comments. A comment can try to argue a query out of a match. Use query rules to catch mistakes and known-bad queries, not as a security boundary against a member set on getting around them.