Skip to content

Run test cases against a policy

POST
/v1/policies/test
curl --request POST \
--url http://127.0.0.1:8080/v1/policies/test \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Deedglass-Version: 2026-10-01' \
--data '{ "policy": "postgres-safe", "version": 3, "cases": [ { "name": "deletes never run", "input": { "tool": "postgres.execute", "sql": "DELETE FROM public.orders" }, "expect": { "decision": "deny", "rule": "block-destructive-sql" } } ] }'

Runs a cases file against a source, or against a stored version (policy and version), and reports each case and the rule coverage. Send source or policy with version, not both. It never reserves usage and writes nothing. Limited to 60 requests a minute per person or key (429 rate_limited), with a 2 s timeout and bodies up to 2 MiB. Idempotency-Key is ignored. A Console session (viewer and up, with the Deedglass-CSRF header) or an org admin key (admin scope); agent keys get 403 insufficient_scope (“Agents cannot read or test policies. Use the Console or an admin key.”).

Deedglass-Version
string
/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/

The API version (YYYY-MM-DD). Leave it out to use your org’s pinned version (public routes use the latest). An unknown version is 400 api_version_invalid.

Deedglass-CSRF
string

Needed when the request uses a Console session (it changes state); without it the answer is 403 csrf_failed. Not sent with an API key.

Media typeapplication/json
object
source

A policy YAML. Not with policy.

string
policy

A stored policy

string
version

The stored version’s number

integer
>= 1
cases
required
One of:
string
Example
{
"policy": "postgres-safe",
"version": 3,
"cases": [
{
"name": "deletes never run",
"input": {
"tool": "postgres.execute",
"sql": "DELETE FROM public.orders"
},
"expect": {
"decision": "deny",
"rule": "block-destructive-sql"
}
}
]
}

The test result.

Media typeapplication/json

The result of a test run. ok is true when every case passed.

object
object
required
string
Allowed value: policy_test_result
policy
required

The policy’s name.

string
file
string
cases_file
string
version_hash
required

“sha256:” + lowercase hex of SHA-256.

string
/^sha256:[0-9a-f]{64}$/
ok
required
boolean
passed
required
integer
failed
required
integer
skipped
required
integer
cases
required
Array<object>

One test case, what it expected and what the policy decided. The full PolicyCaseResult schema is in openapi.yaml.

object
coverage
required

Which rules and budgets the cases reached.

object
rules
required
Array<object>

How many cases a rule or budget decided. The full PolicyRuleCoverage schema is in openapi.yaml.

object
covered
required

Rules that decided at least one case.

integer
total
required
integer
uncovered
required
Array<string>
default
required

Cases the default decided.

integer
budgets
required
Array<object>

How many cases a rule or budget decided. The full PolicyRuleCoverage schema is in openapi.yaml.

object
elapsed_us
required
integer
Example
{
"object": "policy_test_result"
}
Deedglass-Request-Id
string
/^req_[0-7][0-9a-hjkmnp-tv-z]{25}$/

This request’s id. Quote it to support; it matches error.request_id.

An error. Every error has this envelope; doc_url explains the code.

Media typeapplication/json
object
error
required
object
type
required
string
Allowed values: invalid_request_error authentication_error permission_error policy_error rate_limit_error api_error
code
required
string
Allowed values: invalid_api_key api_key_revoked api_key_expired agent_suspended agent_stopped org_stopped insufficient_scope policy_denied approval_required approval_expired budget_exceeded intent_required intent_invalid intent_replay tool_unknown connector_unavailable upstream_error timeout rate_limited idempotency_conflict validation_failed not_found conflict internal_error authentication_required method_not_allowed request_too_large unsupported_media_type invalid_json api_version_invalid idempotency_key_invalid idempotency_key_in_use service_unavailable session_expired csrf_failed insufficient_role login_link_invalid login_code_invalid last_owner policy_unavailable policy_invalid credentials_missing destination_blocked vault_unavailable upstream_auth_failed upstream_not_found upstream_rate_limited response_too_large statement_refused row_limit_exceeded database_role_unsafe database_not_ready witness_not_configured approval_decided already_countersigned approver_not_eligible self_approval approval_needs_person context_changed approval_unsatisfiable approval_link_invalid approval_link_review_only approver_unmapped stripe_live_key_refused stripe_livemode_detected upstream_approval_pending schedule_needs_approval action_executing from_denied undo_unavailable undo_plan_stale already_undone undo_conflict replay_too_large replay_window_invalid suggestion_stale shadow_slot_taken suggestion_decided observe_not_enabled pro_required
message
required

One or more calm sentences with the next step.

string
param
required

The request field, query parameter or header the error is about.

string | null
request_id
required
string
/^req_[0-7][0-9a-hjkmnp-tv-z]{25}$/
doc_url
required
string format: uri
diagnostics

On policy_invalid only. Each problem with its line, code and hint.

Array<object>

One finding about a policy file, with its position and the next step. Codes are stable and listed in docs/POLICY_ERRORS.md. In the policy_invalid error envelope each diagnostic also carries object: policy_diagnostic. The full PolicyDiagnostic schema is in openapi.yaml.

object
action

One agent action. Its sections mirror the deed’s. status is the one field an agent needs; state is the exact lifecycle state (docs/GATE.md). The Gate’s own responses (POST /v1/actions and its result report) add execution.result and witness.reasons; lists leave both out. The full Action schema is in openapi.yaml.

object
checks

On undo_unavailable only. Every check of the undo, each with its fix. Additive (S23).

Array<object>

One of the twelve safety checks (S23 §3.3). Available means no check failed. The full UndoCheck schema is in openapi.yaml.

object
Example
{
"error": {
"type": "invalid_request_error",
"code": "not_found",
"message": "There's no endpoint at GET /v1/helth. Did you mean /v1/health?",
"param": null,
"request_id": "req_01j9zr3m5k8q2w7x4t6v0b1c9d",
"doc_url": "https://docs.deedglass.com/errors/not_found"
}
}
Deedglass-Request-Id
string
/^req_[0-7][0-9a-hjkmnp-tv-z]{25}$/

This request’s id. Quote it to support; it matches error.request_id.

Deedglass-Version
string

The API version this response follows.