Policy Engine
The policy module decides whether a request should be:
allowapproval_requireddeny
How decisions are evaluated
Policies are created in the dashboard with a simple rule builder. The API stores each policy as a JSON rule object.
This module sits inside the Governance Decisions part of the product architecture.
How it works
A request to /v1/evaluate or /v1/proxy/evaluate passes through these stages in order. The Console playground (/v1/playground/decision) runs a subset, described in Playground differences.
- Request validation.
versionmust bev1,operation_idmust be present,transport.kindmust behttp,grpc, ormcp, exactly one ofasset.idorasset.keymust be set, andapproval_idandpayload_hashmust be sent together. A failure returns HTTP400. - Module entitlement. MCP transport requires the
mcp.enabledentitlement;/v1/proxy/evaluaterequiresproxy.enabled. A missing entitlement returns HTTP403. Entitlement decides whether the organization may use the module. It never changes how policies are matched. - Metadata checks. Application metadata is sanitized (see Metadata limits).
- Quota and rate-limit resolution. The organization's plan limits are resolved. See Limits and Configuration.
- Asset resolution. An unknown
asset.idreturns HTTP404withcode: asset_not_found. An unknownasset.keyis allowed with reasonasset_not_registered; the key is queued for discovery, and the call is not recorded as a decision or billed. A user session that may not access the asset sees the sameasset_not_foundas a missing asset. - Schema validation. If the asset defines a metadata schema, metadata is validated against it. A failure returns HTTP
400before any policy is evaluated and before decision quota is consumed. This also applies when no policies are assigned. - Approval retry check. If the request carries an
approval_id, or is a proxy retry of an existing operation, the approval retry path runs instead of a fresh evaluation. See Approvals. - Policy evaluation. Only the asset's published, active policies are evaluated. An asset with no such policies is allowed with reason
no_policies_assigned; that decision is recorded but not billed. - Aggregation and recording. The most restrictive matching outcome wins, the decision is stored in decision history, and an audit event is written. See Audit.
Governance is opt-in: an asset with no policies attached allows every request. Add a policy for any workflow you want restricted or reviewed. Before you author a policy, define the assets and groups that describe the workflow you want to govern.
Where this module fits
- Identity and workspace provides the user and organization context.
- Inventory provides the assets and groups used by policies.
- Approvals and delivery records the result when a request needs review, and covers how customers choose sync, retry, or webhook delivery.
Policy lifecycle and previews
| Status | Enforcement | Editing and transitions |
|---|---|---|
draft | Never evaluated; inactive | Edit, validate and simulate before publishing. |
published | Evaluated only while active | Existing edits and rollbacks take effect immediately. Deactivate to pause, or archive to remove from enforcement. |
archived | Never evaluated; inactive | Read-only except deletion or cloning. Cannot be activated or published in place. |
New Console policies start as drafts. For compatibility, existing policies and
API creates that omit status remain published. Request "status": "draft"
explicitly when preparing a policy through the API. Status is not an arbitrary
PATCH field; use the lifecycle operations.
Drafts do not reserve or block traffic. If an asset has only draft, archived or
inactive policies, the existing no-policy ALLOW behavior still applies.
Publishing validates the saved draft against the current rules and asset schema,
records a new revision, and activates it immediately. Unsaved Console edits are
not included. Only published policies can use activation controls. A published
policy cannot be published again, and nonpublished policies cannot be activated;
invalid state transitions return HTTP 409 with code: invalid_policy_state.
Editing a published policy is not an isolated draft edit: it changes live
policy behavior. Prepare a separate draft when a change must remain outside
enforcement until publication. Rollback preserves the current lifecycle:
rolling back a draft does not publish it. Archived policies are read-only.
The existing clone operation creates a published, active policy, even when
the source is draft or archived; it requires policy.clone. It is not a draft
copy operation. The Console asks for confirmation before publishing, archiving,
or cloning a live policy.
Validation checks a proposed definition against the current asset schema
without saving it. Simulation evaluates proposed policies with metadata and
optional transport context (HTTP when omitted); principal fields come from the authenticated
caller. All simulation outcomes are previews, including approval_required.
They are not execution permission and do not create an approval ID.
Validate and simulate create no decision history, audit records, operation or
outcome state, and do not charge usage or consume approvals. A simulation
returns HTTP 200 with its preview decision and trace; invalid definitions or
context return coded HTTP 400. Policy management access is required, and
simulation additionally requires playground access. Tenant and asset access
restrictions still apply.
The Console validates or simulates the current editor definition, not the saved policy set. Metadata is entered separately for simulation. Results become stale and are hidden when the definition or simulation metadata changes. See the API request and response examples.
Publishing or archiving a live policy can invalidate approval retries; see approval bindings. Adding the lifecycle status alone does not change existing approval-hash encoding.
Rule model
Simple rule
{
"field": "metadata.amount",
"operator": ">",
"value": 5000
}
Composite rule
{
"all": [
{
"field": "metadata.amount",
"operator": ">",
"value": 5000
},
{
"field": "metadata.environment",
"operator": "=",
"value": "production"
}
]
}
Supported operators:
=!=>>=<<=innot_incontainsexistsnot_existsstarts_withany
Request context fields
Policy conditions can address distinct namespaces so rules can tell trusted identity from application-supplied data:
asset.id,asset.key,asset.application,asset.service, andasset.environmentidentify the governed asset.principal.kind,principal.id, andprincipal.rolecome from authenticated server or adapter context, not frommetadata.principal.attributes.*is not supported because no trusted attribute source populates it.transport.http.method,transport.http.path,transport.http.host,transport.http.scheme,transport.http.route_id, and allowlistedtransport.http.headers.<name>describe HTTP requests.transport.grpc.full_method,transport.grpc.service,transport.grpc.method,transport.grpc.rpc_type,transport.grpc.route_id, and allowlistedtransport.grpc.metadata.<name>describe gRPC calls.transport.mcp.operation,transport.mcp.server, andtransport.mcp.tooldescribe MCP calls. Arguments, request IDs, and session IDs are not policy fields.metadata.<path>addresses application context supplied with the authorization request.
Use an explicit supported namespace. Bare names such as amount, legacy
asset or asset_id aliases, and unknown namespaces are rejected. Conditions
must be JSON rule objects; legacy expression strings are not supported.
A transport-specific field is nonmatching when the request uses another transport. For example, an HTTP request cannot match a transport.grpc.* condition. Principal fields are populated only from trusted authentication context; values in metadata.actor or similar application fields are not authenticated identities.
Authoring validation and warnings
Create, update, clone, activation, and rollback validate the policy against
current rules and the asset's current metadata schema. Invalid conditions
return HTTP 400 with code: invalid_policy_condition; the policy and its
revisions are unchanged. Deactivation does not require a valid condition.
For a nonempty metadata schema, every referenced metadata.<path> must be
declared at that full path. Declaring an object parent does not implicitly
declare the types of its descendants. Equality operands must match the declared
type, ordering requires a numeric field and operand, and in/not_in require
compatible list elements. contains is available for strings and lists;
starts_with requires a string field and operand, and any requires a list
field and a string, number or boolean scalar operand. Presence tests are
available for every declared field type and do not have a value operand.
Typed fields do not accept null operands merely because they are optional.
With no effective schema, generic operator and value validation still applies;
the API does not invent a field type.
For deny and approval_required, rule_field_optional in the response's
warnings string array means a referenced metadata leaf is not explicitly
required. The Console displays the warning. It is informational: saving is not
blocked, and policy matching is unchanged. If omission must prevent execution,
mark the field required in the asset schema or use an explicit absence test.
A policy on an asset without a schema can also receive this warning. Presence
tests express omission intentionally; do not infer their matching behavior
from an optional-field warning.
The Console blocks unsupported or lossy edits instead of silently changing a saved rule. Some structured list/object conditions and ambiguous values on assets without a schema, such as a string that looks like a number, require an API client. A policy whose asset is unavailable is not automatically moved to another asset when loaded into the editor.
Current-schema validation also applies when active policies are evaluated. Changing a schema can therefore invalidate active policies and restorable revisions. Such definitions fail closed; they are not silently treated as nonmatching rules.
Compatibility before upgrading
Review active policies and restorable revisions for bare paths, legacy expression strings, undeclared metadata paths, and incompatible operands before deployment. There is no legacy parsing fallback or automatic conversion. Legacy expression strings may no longer be inspectable through the policy API after upgrading. Do not assume a clean deployment inventory, or rewrite audit history to repair policy definitions. Review approval bindings as part of the coordinated upgrade procedure below.
Matching reference
Operators and value types
| Operator | Meaning | Value and type rules |
|---|---|---|
= | Equal | Decimal numbers are compared exactly, so 5 equals 5.0. Incompatible kinds, including "5" versus 5, are invalid context rather than a non-match. |
!= | Not equal | Same comparison as =, negated. |
>, >=, <, <= | Numeric comparison | Both values must be numbers. Numeric strings are not coerced; an incompatible request value is invalid context. |
in | Exact membership in the policy value | The policy value must be a homogeneous, non-null list. Strings are invalid policy operands; there is no substring matching. |
not_in | Request value is not within the policy value | Same value rules as in. |
contains | Request value contains the policy value | The request value must be a string (substring) or a list (element equality). Any other request value is an evaluation error. |
exists | Field key is present | Omit value entirely. Explicit null counts as present; empty strings, objects and lists are present too. |
not_exists | Field key is absent | Omit value entirely. An explicitly present null does not match. |
starts_with | Request string begins with the policy string | Both values must be strings. Matching is case-sensitive; an empty prefix matches every present string. |
any | A request list contains the policy scalar | Operand must be a string, number or boolean. The list must be homogeneous and compatible with the operand; numeric equality is exact. Empty lists do not match. Incompatible kinds fail with invalid_context, even after an earlier matching member. |
A leaf condition must have a field and an operator. Except for exists
and not_exists, it must also have an explicit value. Presence tests reject
a supplied value, including null; do not send "value": null as a placeholder.
Null is meaningful only for equality and inequality. Membership lists must not
mix incompatible kinds; request values of an incompatible kind are invalid context.
Invalid policy operands are rejected when you save or restore the policy.
Historical string-valued in/not_in conditions fail closed as policy-definition
errors and cannot be reactivated or restored. They remain inspectable,
deactivatable, and deletable. Do not convert a string to a singleton list
automatically: substring matching and exact membership express different intent.
Unsupported principal.attributes.* conditions are rejected too. An existing
policy using unsupported principal attributes fails closed as an invalid
definition; it is not silently ignored.
Existing policies with numeric values outside the current supported domain remain inspectable, deactivatable, and deletable through the policy API, but cannot be reactivated or restored without meeting current validation. Clients with narrower numeric support, including the Console and TypeScript SDK, may reject such responses; use an API client that preserves the original JSON number text for inspection and remediation.
Composite conditions
A composite uses all, which is a logical AND of its children. Every child is
validated even when an earlier child does not match; an invalid definition or
incompatible runtime value cannot hide behind a non-match. There is no logical
any or or form: any is a leaf operator for list membership. To express OR,
create separate policies on the same asset; the most restrictive matching
outcome then wins.
The unary not wrapper negates exactly one permitted leaf:
{
"not": {
"field": "metadata.region",
"operator": "=",
"value": "EU"
}
}
For this example, the current asset schema must declare metadata.region as
required. Negation permits ordinary comparisons only on required metadata or
supported asset/principal fields. Metadata exists and not_exists may also
be negated, even when the field is optional. All transport fields and ordinary
optional or schemaless metadata comparisons are excluded. not cannot wrap
all or another not, or share an object with leaf properties. An all
group may contain separate negated leaves. Invalid context still fails rather
than becoming a successful negated match.
Presence example, with no value operand:
{
"field": "metadata.review",
"operator": "not_exists"
}
Declaring a presence rule does not bypass the asset schema: undeclared paths are rejected when the schema is nonempty, and required/type validation still runs before matching.
Missing and null fields
If a field is not present in the request, ordinary comparisons do not match,
including !=, not_in, starts_with and any. For example,
metadata.region != "eu" does not match a request without metadata.region.
Presence tests are explicit exceptions: exists is false and not_exists is
true for an absent key. Negating an ordinary missing field does not turn it
into a match. Missing fields are not evaluation errors by themselves, but a
required-metadata schema rejects omission before matching.
A transport field for another transport kind is nonmatching for ordinary
comparisons; presence tests inspect whether that field is available.
An explicitly present null differs from an absent field. Subject to the asset's schema, null equals only null; comparing null to a non-null value is invalid context, not a non-match.
For a present field, in [] never matches and not_in [] matches, including
null: an empty list provides no element type to compare. Missing fields still
do not match either operator. Nonempty lists enforce compatible kinds across
all elements, even after finding a match.
Exact numbers and client precision
Numbers are compared as exact decimals, without conversion to binary
floating-point for policy comparison. The supported range is at most 128
significant digits and a normalized decimal exponent from -308 through 308.
Values outside these fixed limits are rejected without rounding; customers
cannot increase the limits through configuration. Equivalent metadata values
such as 100, 100.0, and 1e2 have the same canonical approval binding.
Negative zero is equivalent to zero. MCP's separate complete-arguments digest
still preserves number text, so changing argument spelling can still change
that digest.
The normalized coefficient excludes leading and trailing zeroes. For nonzero
values, the normalized exponent is the scientific-notation exponent: 1.23e2
has exponent 2. Thus 1e-308 and 9.99e308 are within the server's domain;
9.99e-309 and 1e309 are not. Zero has exponent 0 and no sign.
Each numeric token is limited to 4,096 characters, including sign, decimal point, and exponent. Metadata and individual policy values have maximum traversal depth 64: the metadata/value root is depth 0, and each property or array element adds one, including scalar leaves. These fixed limits are not customer-configurable. They do not impose a separate 64-level limit on the entire request envelope or composite-policy tree. Invalid values fail closed without rounding or truncation.
JavaScript numbers cannot represent every supported decimal or large integer.
The Console and TypeScript SDK reject unsupported precision rather than
silently round it. Do not convert an exact large value through a native
floating-point number before sending it: a server cannot recover digits already
lost by the caller. Use Go json.Number or Python Decimal when constructing
exact values beyond native floating-point precision. The TypeScript client
supports a narrower native-number subset; integer values must be safe integers.
Native floats are interpreted using their serialized decimal representation,
not as a promise to reconstruct the caller's original decimal text.
Changing numeric approval canonicalization requires a coordinated upgrade. Before upgrading or rolling back, pause approval-bearing traffic, finish, explicitly revoke, or let old redeemable approvals expire, and verify none remain. Upgrade the coordinated API, SDK, and enforcement components together before resuming traffic. Do not modify stored hashes, use old-hash fallbacks, or replay consumed or ambiguous operations to bypass a mismatch.
Normalization
- HTTP header and gRPC metadata names are matched case-insensitively and their values are trimmed. Only allowlisted headers and metadata are available to policies.
transport.http.methodis uppercased.transport.http.host,transport.http.scheme, andtransport.grpc.rpc_typeare lowercased.- MCP policies can use
transport.mcp.operation,transport.mcp.server, andtransport.mcp.tool. Tool arguments, request IDs, and session IDs are not available to policies. Pass the values a policy needs as mappedmetadatainstead. - Field paths must use an explicit supported namespace; bare metadata paths are rejected.
Precedence, ties, and conflicts
All of the asset's published, active policies are evaluated. The outcome with the highest precedence wins: deny, then approval_required, then allow. When two matching policies have the same outcome, the first one in evaluation order is reported as the winning policyId. The reason is policy_aggregate_matched when at least one policy matched, and no_matching_policy (outcome allow) when none did.
Errors fail closed
Malformed JSON, invalid evaluation envelopes or transport combinations, and
invalid playground asset selection return HTTP 400 with
code: invalid_request. Invalid outcome reports use the same code. Every 400
on the evaluation, proxy evaluation, outcome, operation-status and playground
routes includes a stable code plus human-readable error; see the
error registry. Branch on the code, not text.
Invalid metadata, schema violations, or incompatible runtime kinds stop the
evaluation with HTTP 400 and code: invalid_context. The call is not allowed,
no decision-history row is recorded, no decision usage is charged, and no
approval is consumed. Correct the caller's context before retrying; changing
approval-bound context may require a new approval.
An invalid policy definition or other policy-evaluation failure remains HTTP
503 with code: policy_evaluation_failed, the decisionId, and the failing
policyId. A deny decision with reason evaluation_error is recorded, an
audit event decision.evaluation_failed is written, and the attempt counts
toward decision usage. Neither error falls back to remaining policies or
permits upstream execution.
Outcome summary
| Situation | Outcome | Reason | Recorded as decision | Billed |
|---|---|---|---|---|
Unknown asset.key | allow | asset_not_registered | No (queued as discovery) | No |
Unknown asset.id | HTTP 404 | asset_not_found | No | No |
| Asset has no policies | allow | no_policies_assigned | Yes | No |
| Policies exist, none match | allow | no_matching_policy | Yes | Yes |
| One or more match | Most restrictive outcome | policy_aggregate_matched | Yes | Yes |
| Policy evaluation error | HTTP 503 (denied) | policy_evaluation_failed | Yes | Yes |
| Metadata, schema, or runtime kind error | HTTP 400 | invalid_context | No | No |
| Quota exhausted | HTTP 402 | decision_quota_exceeded | No | No |
Authorization, entitlement, and policy are separate
Three checks are independent and run in this order:
- Authentication and scope. The API key or user session must be valid and carry the scope for the endpoint. A user session may also be limited to assets it owns.
- Entitlement. The organization's plan must enable the module (
mcp.enabled,proxy.enabled,decision.run,approvals.enabled). A failure is HTTP403and no policy runs. - Policy. Only then are policies matched against the request.
A policy cannot grant a module the plan does not include, and an entitlement does not allow a request that a policy denies. approvals_disabled is returned when a policy requires approval but the organization lacks approvals.enabled.
Metadata limits
- Serialized metadata is limited to 8 KiB of JSON. Larger values return HTTP
400. - These keys must be strings of at most 256 characters when present:
provider,model,operation,environment,actor,application. metadata.ai.*accepts onlymessage_count,message_size_bytes,input_tokens,output_token_limit,attachment_count,attachment_size_bytes,tool_count, andrequest_size_bytes. All must be integral numbers within the supported integer range, not fractional values or numeric strings. Overflow is rejected rather than truncated, andattachment_countmust be at most 64.raw_message_contentandattachment_contentare rejected. Duplicate keys after trimming are rejected.- If the asset defines a metadata schema, every metadata key must be declared in it. An undeclared key returns HTTP
400. Declared fields are type-checked as string, number, boolean, list, or object. - The reserved key
outcome_reportingis accepted only with the valuenone. Integrations set it when the operation outcome cannot be reported.
AI counter ranges depend on the caller/runtime. Negative integers remain supported; the separate attachment-count upper bound still applies.
| Component | Supported AI counter range, inclusive |
|---|---|
| API / Go SDK on 64-bit builds | -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 |
| API / Go SDK on 32-bit builds | -2,147,483,648 through 2,147,483,647 |
| Python SDK | -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 |
| TypeScript SDK | -9,007,199,254,740,991 through 9,007,199,254,740,991 |
The API documents no separate limit on total request body size. Do not rely on one; keep requests small.
Debug trace
Send "debug": true to receive an evaluationTrace that lists each policy step, whether it matched, the fallback reason, and the winner. Use it to test policies; do not enable it in production hot paths.
Worked examples
Policies on one asset: P1 amount > 5000 → approval_required; P2 metadata.environment = "production" and metadata.amount > 10000 → deny.
| Request metadata | Result |
|---|---|
{"amount": 12000, "environment": "production"} | P1 and P2 both match. deny wins; winner is P2. |
{"amount": 12000, "environment": "staging"} | Only P1 matches. approval_required. |
{"amount": 100} | Nothing matches. allow with no_matching_policy. |
{"amount": "abc"} | P1 fails with invalid context. HTTP 400, invalid_context; no decision is recorded or charged. P2 is not consulted. |
{"environment": "production"} | P1 does not match (missing field). P2 does not match (missing amount). allow. |
Required metadata
Asset definitions can mark a metadata field as required:
{
"_fieldMetadata": {
"metadata.refund.amount": { "type": "number", "required": true }
}
}
The full path must be present, non-null, and correctly typed. A missing or null
parent also fails validation. Zero, false, and correctly typed empty strings,
lists, and objects satisfy presence. Omit required or set it to false to keep
a field optional.
Invalid metadata is rejected with HTTP 400 before policy evaluation or decision
quota consumption. This also applies when no policies are assigned. Enforcement
is consistent across HTTP, gRPC, MCP, and the Console playground.
Schema edits take effect immediately, including on pending or approved operation retries. An approval does not bypass new required fields. Adding fields to a retry can change its approval binding; start a new operation if its context changes. Configure callers before enabling requirements. Envoy-only HTTP routes that do not send business metadata should use transport conditions instead.
The Console provides a Required checkbox for each field and preserves the flag when editing an asset or applying a preset. Per-asset required and description choices override preset defaults; preset field types remain authoritative during creation. For MCP tools, configure the argument mappings before requiring metadata.
Playground differences
The Console playground validates asset access and metadata against the asset's schema before evaluating policies or consuming decision quota. Principal conditions use the signed-in user or authenticated API key; asset conditions use the resolved asset. Supplying identity values in the request or metadata does not replace authenticated identity.
The playground does not supply an application HTTP, gRPC, or MCP transport context, so transport-specific conditions do not match there. Use an application integration to test those conditions.
Playground calls are not side-effect-free simulations: registered-asset calls
count toward decision usage, including calls to assets without policies, and
are recorded in decision history. An approval_required result may create an
approval, but it does not authorize or execute an upstream operation and cannot
be redeemed through an application approval retry.
Authoring flow
- Choose an asset.
- Confirm the action.
- Choose the decision result.
- Add one or more rule rows.
- Pick a field, operator, and value.
- Save the policy.
You can start from an existing policy if you want a template for a similar workflow.
Example
Policy:
- Name:
Require approval for high-value payments - Action:
payment.execute - Rule:
amount > 5000 - Decision:
approval_required
Request metadata:
{
"amount": 12000,
"environment": "production"
}
Expected result:
decision:approval_requiredreason:policy_aggregate_matched
Best practices
- Start with narrow rules by action.
- Prefer
approval_requiredfor risky operations. - Keep metadata keys consistent, for example
environment,riskLevel, orvendor. - Test new policies in Decision Playground before using them broadly.