/policies/validateValidate Policy
Validates a candidate policy bundle body against all schema and operator rules without persisting any state.
Returns the validation outcome — pass, fail with error codes, or warnings — including specific errors for unknown operators (K9O_POLICY_UNKNOWN_OPERATOR), exceeded nesting depth (K9O_POLICY_NESTING_TOO_DEEP), unknown context fields (K9O_POLICY_UNKNOWN_CONTEXT_FIELD), and bundle invalidity (K9O_POLICY_BUNDLE_INVALID).
Requires PROJECT_ADMIN.
| projectSlug * | path | The project's slug: the path segment after It is unique within the org. |
| policy * | object | The policy document. Every block is optional. A key other than these seven is refused with 422 |
| collections | any | Row-level rules per collection, keyed by collection name. Each collection holds An action with no rule is denied. Publishing compiles these rules into the database's row-level security. |
| One of: object | ||
| or: null | ||
| storage | any | Storage rules per bucket, keyed by bucket name. They are checked on each storage request. |
| One of: object | ||
| or: null | ||
| tools | any | Rules for tool calls, keyed by the tool's platform name or Each tool takes Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| functions | any | Rules for functions, keyed by function name, Each function takes Each verb takes a rule list: a rule name from Only |
| One of: object | ||
| or: null | ||
| secrets | any | Rules for secrets: Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| streams | any | Rules for streams, keyed by stream name or Each stream takes Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| analytics | any | Rules for analytics datasets, keyed by dataset slug or Each dataset takes Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| rules | any | The named-rule catalogue, an array of rule objects that the unit surfaces refer to by name. Each rule has a With
Omit it or send null for no catalogue. |
| HTTP | K9O Code | Description |
|---|---|---|
| 200 | Success | |
| 400 | K9O_POLICY_NESTING_TOO_DEEP | The candidate policy rule exceeds the maximum nesting depth of 20; reduce the rule nesting before re-validating. |
| 400 | K9O_POLICY_UNKNOWN_OPERATOR | The candidate bundle contains a policy rule with an operator name not in the supported vocabulary. |
| 400 | K9O_POLICY_UNKNOWN_CONTEXT_FIELD | A subject or resource operand path in the candidate bundle does not resolve to a known field. |
| 401 | K9O_SESSION_EXPIRED | The caller's session token is expired or invalid; re-authenticate to continue. |
| 403 | K9O_ACCESS_DENIED | The caller does not hold PROJECT_ADMIN role, which is required to run policy validation. |
| 422 | K9O_POLICY_BUNDLE_INVALID | The candidate bundle is structurally valid but fails domain-level validation such as a referential schema mismatch. |
| data * | object | The result of a validation that passed. Nothing is saved. |
| valid * | true | Always true. A bundle that fails validation gets an error response instead, naming the problem. |
| meta * | any |
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.policies.validate({
policy: {
collections: {},
storage: {}
}
})Showing example in TypeScript
{
"policy": {
"collections": {},
"storage": {}
}
}{
"data": {
"valid": true
}
}