# Policy reference

This page is the canonical reference for policy fields, JavaScript conditions, workflow objects, and policy-writing rules. For the concept, see [Policies](/pt-br/products/custody/governance/policies). For operations, see [Manage policies](/pt-br/products/custody/governance/policies/manage-policies). For reusable patterns, see [Policy examples](/pt-br/products/custody/governance/policies/examples).

## API reference

| Task | API reference |
|  --- | --- |
| Create, update, lock, or unlock a policy | [Propose an intent](/pt-br/products/custody/reference/api/openapi/intents/createintent) |
| Test a policy intent | [Perform a dry run](/pt-br/products/custody/reference/api/openapi/intents/intentdryrun) |
| Query policies | [List policies](/pt-br/products/custody/reference/api/openapi/policies/getpolicies), [Get policy details](/pt-br/products/custody/reference/api/openapi/policies/getpolicy) |
| Check the full schema | [OpenAPI specification](/pt-br/products/custody/reference/api/openapi) |


## Create policy fields

These fields are used in a `v0_CreatePolicy` payload and in genesis policy entries. Genesis policy entries are embedded in a domain's `policies` array and do not include the `type` field.

| Field | Type | Required | Rules |
|  --- | --- | --- | --- |
| `id` | UUID string | Yes | Unique policy ID. |
| `alias` | string | Yes | 1-75 characters. Use a stable operational name. |
| `rank` | integer | Yes | 0-1000. Higher rank wins among eligible policies in the same domain. Ranks aren't compared across domains. See [Policy selection](#policy-selection). |
| `intentTypes` | string array | No | If omitted, the policy can match all intent types. Use only for deliberate fallback or emergency policies. An empty array matches no intent type. |
| `intentOrigin` | enum | No | `UserSigned` or `SystemSigned`. If omitted, the policy matches user-signed proposals only. |
| `scope` | enum | Yes | `Self`, `Descendants`, or `SelfAndDescendants`. |
| `scriptingEngine` | enum | Yes | `Javascript_v0`. |
| `condition` | object | No | If omitted, the condition behaves as always true. |
| `workflow` | array | No | If omitted or `null`, matching intents are auto-approved. An empty array rejects matching intents. |
| `lock` | enum | Yes | `Unlocked` or `Locked`. |
| `description` | string | No | 0-250 characters. |
| `customProperties` | object | Yes | String key-value metadata. Use `{}` when empty. |
| `type` | string | Yes for intent payloads | `v0_CreatePolicy`. Omit inside genesis policy entries. |


## Update and lock fields

`v0_UpdatePolicy` uses a `reference` instead of `id` so the update targets a specific policy revision.

```json
{
  "payload": {
    "reference": {
      "id": "5b440ba5-d013-11eb-8cd0-dcfb48cfb3cb",
      "revision": 3
    },
    "alias": "policy-governance",
    "rank": 750,
    "intentTypes": ["v0_CreatePolicy", "v0_UpdatePolicy"],
    "intentOrigin": "UserSigned",
    "scope": "Self",
    "scriptingEngine": "Javascript_v0",
    "condition": {
      "expression": "context.references.users[context.request.author.id].roles.includes('policy-operator')",
      "type": "Expression"
    },
    "workflow": [
      {
        "role": "policy-operator",
        "quorum": 2,
        "type": "RoleQuorum"
      }
    ],
    "description": "Controls policy lifecycle operations.",
    "customProperties": {},
    "type": "v0_UpdatePolicy"
  }
}
```

`v0_LockPolicy` and `v0_UnlockPolicy` use only `reference` and `type`.

```json
{
  "payload": {
    "reference": {
      "id": "5b440ba5-d013-11eb-8cd0-dcfb48cfb3cb",
      "revision": 3
    },
    "type": "v0_LockPolicy"
  }
}
```

## Policy selection

Policy evaluation selects at most one policy in each domain, not one policy overall. Rank decides between policies of the same domain only. A policy never outranks a policy that belongs to a different domain.

When an intent is submitted, policy evaluation:

1. Builds the domain path from the root domain down to the target domain. The author must belong to a domain on this path, so a user can target only their own domain or one of its descendants.
2. Decides which domains on the path to evaluate. If the author's domain uses `CoerceDescendants`, evaluation stops at the author's domain and skips the domains below it, including the target domain. Otherwise, evaluation covers every domain on the path. For details, see [Governing strategy](#governing-strategy).
3. In each evaluated domain, takes that domain's unlocked policies and keeps the ones that match:
  - `intentOrigin`. A policy with omitted `intentOrigin` matches user-signed proposals only.
  - `intentTypes`. A policy with omitted `intentTypes` can match any intent type.
  - `scope`, relative to the target domain. See [Scope values](#scope-values).
  - `condition`. The condition must return `true`. A policy without a condition always matches.
4. In each evaluated domain, selects the eligible policy with the highest rank. If two eligible policies in the same domain have the same rank, the policy whose last modification is oldest wins. Updating, locking, or unlocking a policy counts as a modification.
5. Checks that the domains that must have a policy have one. The author's domain must have a selected policy, and so must the target domain when evaluation covers it. If either has none, the intent fails with `NoApplicablePoliciesForDomain`. Other domains on the path that have no eligible policy add no workflow.
6. Applies the workflow of every selected policy. The system approves the intent only when every selected workflow approves it. A rejection in any selected workflow rejects the intent.


Evaluation stops at the first condition that throws an error, and the intent fails with `PolicyScriptingExecutionFailed`. In each domain, the system evaluates conditions in rank order and stops at the first eligible policy. It evaluates a condition on a lower-ranked policy only after it rules out every higher-ranked policy in that domain.

System-signed proposals have no author. Evaluation treats the target domain as the author's domain. As a result, evaluation covers every domain from the root to the target domain, and the target domain must have a selected policy.

### Approvals across domains

When the system selects more than one policy, each decision counts toward exactly one of them:

- An approval or rejection counts only toward the selected policy of the decision maker's own domain. A user in a parent domain can't approve the child-domain workflow, and a user in a child domain can't approve the parent-domain workflow.
- A user can decide on an intent only if their domain is on the path to the target domain and has a selected policy for that intent. Otherwise, the system refuses the decision with `No workflow exists in this domain requiring a signature` or `User not allowed for the targeted domain`.
- If the selected policy of the decision maker's domain has no workflow, the system accepts the decision, but the decision has no effect.
- A user who already approved an earlier step of a policy can't approve a later step of the same policy. The system refuses the decision with `This user has already signed`.
- For user-signed proposals, the author's proposal counts as the first approval in the selected policy of the author's domain only. The author must hold a role required by the first step of that policy, unless the policy has no workflow. If the author doesn't, the intent fails with `NoApplicablePoliciesForDomain` and the message `Author is not authorized to propose`.


The following table shows which policies apply to an intent that targets a child domain `C` under a parent domain `P`. In every row, the policy selected in each listed domain is the highest-ranked eligible policy of that domain.

| Author's domain | Governing strategy of the author's domain | Domains evaluated | Result |
|  --- | --- | --- | --- |
| `C` | Either | `P` and `C` | `C` must have a selected policy. If `P` has an eligible policy with `Descendants` or `SelfAndDescendants` scope, its workflow also applies, and users in `P` must complete it. |
| `P` | `ConsiderDescendants` | `P` and `C` | `P` and `C` must each have a selected policy. The author's approval counts toward the `P` workflow. Users in `C` must complete the `C` workflow. |
| `P` | `CoerceDescendants` | `P` only | Only the selected `P` policy applies. The system ignores policies in `C`, including a reject-all policy. |


Because each selected workflow must approve, a child-domain policy can't weaken a parent-domain policy that applies to descendants, under either governing strategy. For example, a parent policy with `SelfAndDescendants` scope and an empty workflow rejects every matching intent in the child domain, even if the child domain's own policy auto-approves it.

### Policy changes and open intents

An open intent records the revision of each selected policy. If someone updates, locks, or unlocks one of those policies before the intent completes, the intent fails:

- Shortly after the change, Ripple Custody (Vault) fails the intent with `StaleIntent` and the message `Intent <id> is referring to old revision of policy <id>`. Decisions on it are then refused with `cannot be signed anymore`.
- If a decision arrives before that happens, the decision fails the intent with `PolicyRevisionMismatch`.


Submit a new intent to have it evaluated against the current policies.

If someone locks a domain on the path, the system refuses new intents for that path with `DomainLockedError`. It also refuses decisions on open intents for that path with `Domain <id> is locked`. The open intents don't fail. They stay open.

## Scope values

The system evaluates scope relative to the target domain of the intent:

| Value | Applies to |
|  --- | --- |
| `Self` | Intents targeting the policy's own domain. |
| `Descendants` | Intents targeting descendant domains only. |
| `SelfAndDescendants` | Intents targeting the policy's own domain and descendant domains. |


A policy with `Descendants` or `SelfAndDescendants` scope in a parent domain adds a parent-domain workflow to matching child-domain intents. It doesn't replace the child domain's policy.

## Governing strategy

The governing strategy is a property of the domain. It has an effect only on intents authored by users in that domain. The governing strategies of other domains on the path don't change how the system evaluates an intent.

| Governing strategy | Effect on intents authored in this domain |
|  --- | --- |
| `ConsiderDescendants` | Default. Evaluation covers every domain from the root down to the target domain, including domains below the author's domain. |
| `CoerceDescendants` | Evaluation covers only the domains from the root down to the author's domain. Policies in domains below the author's domain, including the target domain, don't apply, and the target domain doesn't need a matching policy. |


For a user in a child domain, the parent's governing strategy changes nothing. Under either strategy, the system evaluates that user's intents in the parent domains and in the user's own domain. To enforce a parent-domain control on child-domain users, give the parent policy `Descendants` or `SelfAndDescendants` scope. You don't need `CoerceDescendants` for that.

## Intent origin values

`intentOrigin` controls whether a policy matches a normal user-signed proposal or an API-only system-signed proposal.

| Value | Applies to |
|  --- | --- |
| Omitted | User-signed proposals. |
| `UserSigned` | User-signed proposals. |
| `SystemSigned` | System-signed proposals submitted through the API. |


Existing policies that omit `intentOrigin` do not match system-signed proposals. To allow a service caller to submit an intent without a client-side payload signature, create or update a policy with `intentOrigin: "SystemSigned"`.

## Rank guidance

Rank orders the policies of one domain. Use these ranges within each domain. A high rank in a parent domain doesn't let a parent policy replace a child-domain policy.

| Range | Typical use |
|  --- | --- |
| 900-1000 | Explicit emergency or breakglass controls with narrow intent types and high quorum. |
| 500-800 | High-risk governance such as policy, domain, user, and root administration. |
| 100-500 | Standard operational policies. |
| 1-99 | Catch-all or fallback policies that should lose to specific policies. |
| 0 | Last-resort behavior or intentionally lowest priority. |


## Condition object

A condition is either an `Expression`, an `And`, or an `Or`.

```json
{
  "condition": {
    "expression": "context.references.users[context.request.author.id].roles.includes('transaction-operator')",
    "type": "Expression"
  }
}
```

`And` and `Or` use a binary tree. Use `left` and `right`, not arrays.

```json
{
  "condition": {
    "left": {
      "expression": "context.request.payload.rank >= 700",
      "type": "Expression"
    },
    "right": {
      "expression": "context.references.users[context.request.author.id].roles.includes('policy-operator')",
      "type": "Expression"
    },
    "type": "And"
  }
}
```

You can also use JavaScript logical operators inside one expression when that is clearer.

```json
{
  "condition": {
    "expression": "context.request.payload.rank >= 700 && context.references.users[context.request.author.id].roles.includes('policy-operator')",
    "type": "Expression"
  }
}
```

## Condition context

Condition expressions can use the `context` object. System-signed policy conditions can also use `context.submitter` and `intentOrigin`.

| Object | Contains |
|  --- | --- |
| `context.request` | The intent being evaluated. |
| `context.references` | Entities explicitly referenced by the intent. You cannot query arbitrary entities from a policy condition. |
| `context.submitter` | Identity of the user or service caller that submitted the proposal. |
| `intentOrigin` | Proposal origin, either `UserSigned` or `SystemSigned`. |


Common `context.request` paths:

| Path | Contains |
|  --- | --- |
| `context.request.author.id` | User ID that created the intent. |
| `context.request.author.domainId` | Author's domain ID. |
| `context.request.targetDomainId` | Domain targeted by the intent. |
| `context.request.payload` | Intent-specific payload. |
| `context.request.payload.type` | Intent type, such as `v0_CreatePolicy`. |
| `context.request.payload.customProperties` | Custom metadata supplied in the payload, when present. |


For system-signed proposals, `context.request.author` is not present. Use `context.submitter` to check the service caller instead.

Submitter paths:

| Path | Contains |
|  --- | --- |
| `context.submitter.type` | `User` or `Service`. |
| `context.submitter.reference.id` | User ID for user-signed proposals. |
| `context.submitter.reference.domainId` | User domain ID for user-signed proposals. |
| `context.submitter.subject` | Service subject for system-signed proposals. |
| `context.submitter.custodyRoles` | Roles from the service caller token for system-signed proposals. If the configured roles claim is absent, this is an empty array. |


System-signed condition example:

```json
{
  "condition": {
    "expression": "context.submitter.type === 'Service' && context.submitter.custodyRoles.includes('gas-station-service')",
    "type": "Expression"
  }
}
```

Useful payload paths by intent type:

| Intent type | Useful paths |
|  --- | --- |
| `v0_CreateUser` | `context.request.payload.roles`, `context.request.payload.alias`, `context.request.payload.loginIds` |
| `v0_UpdateUser` | `context.request.payload.reference.id`, `context.request.payload.roles`, `context.request.payload.loginIds` |
| `v0_CreatePolicy` | `context.request.payload.rank`, `context.request.payload.intentTypes`, `context.request.payload.scope`, `context.request.payload.workflow` |
| `v0_UpdatePolicy` | `context.request.payload.reference.id`, `context.request.payload.rank`, `context.request.payload.intentTypes`, `context.request.payload.scope`, `context.request.payload.workflow` |
| `v0_CreateDomain` | `context.request.payload.alias`, `context.request.payload.governingStrategy`, `context.request.payload.permissions`, `context.request.payload.childrenDomainIds` |
| `v0_UpdateDomainPermissions` | `context.request.payload.reference.id`, `context.request.payload.permissions.readAccess` |
| `v0_CreateTransactionOrder` | `context.request.payload.accountId`, `context.request.payload.ledgerId`, `context.request.payload.parameters` |
| `v0_ReleaseQuarantinedTransfers` | Payload fields for the quarantine release request. Use existence checks before accessing optional fields. |


Common `context.references` collections:

| Collection | Access pattern | Use when |
|  --- | --- | --- |
| Users | `context.references.users[userId]` | Check the author's current roles or target user state. |
| Accounts | `context.references.accounts[accountId]` | Check ledger, account metadata, or account custom properties. |
| Endpoints | `context.references.endpoints[endpointId]` | Check endpoint trust score or endpoint metadata. |
| Vaults | `context.references.vaults[vaultId]` | Check vault properties for account or vault operations. |
| Tickers | `context.references.tickers[tickerId]` | Check ticker or asset metadata when referenced. |
| Domains | `context.references.domains[domainId]` | Check domain metadata when referenced. |


The following diagram shows how a condition can navigate from an intent payload to a referenced account's custom properties:

![Context references](/assets/context-references.69067cf7957fdbb8bc88302907817d2c6d7411eb1edade8a45e5ee83b87f36cc.556947db.png)

## JavaScript rules for conditions

Conditions are JavaScript expressions. Write one expression that evaluates to `true` or `false`.

| Rule | Guidance |
|  --- | --- |
| Use `Javascript_v0` | This is the supported scripting engine. |
| Return a boolean | The expression should evaluate to `true` or `false` for every matching intent. |
| Prefer strict paths | Check the actual payload shape for each intent type in the API reference before writing paths. |
| Check optional fields | Use `hasOwnProperty`, null checks, or array length checks before accessing optional nested fields. |
| Use role names exactly | Role names are case-sensitive and must match user roles. |
| Keep expressions deterministic | Avoid relying on external state. Policies cannot call APIs or query arbitrary entities. |


Supported JavaScript patterns:

| Pattern | Example |
|  --- | --- |
| Comparison | `context.request.payload.rank >= 700` |
| Logical operators | `a && b`, `a |
| Array includes | `roles.includes('compliance')` |
| Array some/every/filter | `outputs.some(output => BigInt(output.amount) > 100000000n)` |
| Array reduce | `outputs.reduce((sum, output) => sum + BigInt(output.amount), 0n)` |
| String methods | `alias.startsWith('prod-')`, `alias.includes('treasury')` |
| Object checks | `payload.hasOwnProperty('parameters')` |
| JSON methods | `JSON.parse(rawTx)`, `JSON.stringify(roles)` |
| Date methods | `new Date().getHours()`, `new Date().getDay()` |


Amount handling:

- Use BigInt for amount comparisons.
- Use an `n` suffix for integer literals, such as `50000000000n`.
- When the payload value is a string, wrap it with `BigInt(...)`.
- For multi-output payloads, sum amounts with `reduce`.


```json
{
  "condition": {
    "expression": "context.request.payload.parameters.outputs.reduce((sum, output) => sum + BigInt(output.amount), 0n) >= 500000000n",
    "type": "Expression"
  }
}
```

Null-safe nested access:

```json
{
  "condition": {
    "expression": "context.request.payload.hasOwnProperty('parameters') && context.request.payload.parameters != null && context.request.payload.parameters.hasOwnProperty('destination') && context.request.payload.parameters.destination.type == 'Endpoint'",
    "type": "Expression"
  }
}
```

## Condition examples

### High-risk Bitcoin transaction

This condition matches when the author is an `operator`, the transaction parameters are Bitcoin, and either the amount is at least 1 BTC or the source account has a custom property named `escalatePolicy` set to `true`.

```json
{
  "expression": "context.references.users[context.request.author.id].roles.includes('operator') && context.request.payload.hasOwnProperty('parameters') && context.request.payload.parameters != null && context.request.payload.parameters.type == 'Bitcoin' && (context.request.payload.parameters.outputs.reduce((sum, output) => sum + BigInt(output.amount), 0n) >= 100000000n || context.references.accounts[context.request.payload.accountId].metadata.customProperties.escalatePolicy == 'true')",
  "type": "Expression"
}
```

### Medium-risk Bitcoin transaction

This condition matches operator-created Bitcoin transactions below 1 BTC where the account is not escalated and the destination is either an unknown address or an endpoint with a trust score of 50 or lower.

```json
{
  "left": {
    "expression": "context.references.users[context.request.author.id].roles.includes('operator') && context.request.payload.hasOwnProperty('parameters') && context.request.payload.parameters != null && context.request.payload.parameters.type == 'Bitcoin' && context.request.payload.parameters.outputs.reduce((sum, output) => sum + BigInt(output.amount), 0n) <= 100000000n && context.references.accounts[context.request.payload.accountId].metadata.customProperties.escalatePolicy != 'true' && context.request.payload.parameters.outputs[0].destination.type == 'Address'",
    "type": "Expression"
  },
  "right": {
    "expression": "context.references.users[context.request.author.id].roles.includes('operator') && context.request.payload.hasOwnProperty('parameters') && context.request.payload.parameters != null && context.request.payload.parameters.type == 'Bitcoin' && context.request.payload.parameters.outputs.reduce((sum, output) => sum + BigInt(output.amount), 0n) <= 100000000n && context.references.accounts[context.request.payload.accountId].metadata.customProperties.escalatePolicy != 'true' && context.request.payload.parameters.outputs[0].destination.type == 'Endpoint' && context.references.endpoints[context.request.payload.parameters.outputs[0].destination.endpointId].trustScore <= 50",
    "type": "Expression"
  },
  "type": "Or"
}
```

### Low-risk Bitcoin transaction

This condition matches operator-created Bitcoin transactions below 1 BTC where the account is not escalated and the destination is either an internal account or an endpoint with a trust score of 50 or higher.

```json
{
  "left": {
    "expression": "context.references.users[context.request.author.id].roles.includes('operator') && context.request.payload.hasOwnProperty('parameters') && context.request.payload.parameters != null && context.request.payload.parameters.type == 'Bitcoin' && context.request.payload.parameters.outputs.reduce((sum, output) => sum + BigInt(output.amount), 0n) <= 100000000n && context.references.accounts[context.request.payload.accountId].metadata.customProperties.escalatePolicy != 'true' && context.request.payload.parameters.outputs[0].destination.type == 'Account'",
    "type": "Expression"
  },
  "right": {
    "expression": "context.references.users[context.request.author.id].roles.includes('operator') && context.request.payload.hasOwnProperty('parameters') && context.request.payload.parameters != null && context.request.payload.parameters.type == 'Bitcoin' && context.request.payload.parameters.outputs.reduce((sum, output) => sum + BigInt(output.amount), 0n) <= 100000000n && context.references.accounts[context.request.payload.accountId].metadata.customProperties.escalatePolicy != 'true' && context.request.payload.parameters.outputs[0].destination.type == 'Endpoint' && context.references.endpoints[context.request.payload.parameters.outputs[0].destination.endpointId].trustScore >= 50",
    "type": "Expression"
  },
  "type": "Or"
}
```

### Create or update privileged users

This condition matches user creation or update intents when the target user has the `admin` or `compliance` role.

```json
{
  "expression": "context.request.payload.roles.includes('admin') || context.request.payload.roles.includes('compliance')",
  "type": "Expression"
}
```

This condition matches user creation or update intents when the target user does not have either privileged role.

```json
{
  "expression": "!context.request.payload.roles.includes('admin') && !context.request.payload.roles.includes('compliance')",
  "type": "Expression"
}
```

Avoid these patterns:

| Avoid | Reason |
|  --- | --- |
| `fetch`, imports, network calls, or database calls | Conditions cannot call external systems. |
| DOM, browser APIs, timers, or process APIs | Policy evaluation is server-side. |
| Statements that require a block | The field expects an expression. Prefer array methods and logical operators. |
| Missing optional-field checks | Undefined nested paths can make condition evaluation fail. |
| Comparing large amounts as normal numbers | JavaScript numbers can lose precision. |


## Workflow objects

A workflow is an ordered array of approval steps. Each step must be satisfied before the next step is active.

| Type | Shape | Use when |
|  --- | --- | --- |
| `RoleQuorum` | `{ "role": "operator", "quorum": 2, "type": "RoleQuorum" }` | A number of users with one role must approve. |
| `And` | `{ "left": {...}, "right": {...}, "type": "And" }` | Multiple approval groups are required in the same step. |
| `Or` | `{ "left": {...}, "right": {...}, "type": "Or" }` | Either approval group can satisfy the step. |


Example workflow:

```json
{
  "workflow": [
    {
      "role": "transaction-operator",
      "quorum": 1,
      "type": "RoleQuorum"
    },
    {
      "left": {
        "role": "compliance",
        "quorum": 1,
        "type": "RoleQuorum"
      },
      "right": {
        "role": "risk",
        "quorum": 1,
        "type": "RoleQuorum"
      },
      "type": "And"
    }
  ]
}
```

Workflow rules:

- For user-signed proposals, the intent author counts as the first approval in the selected policy of the author's own domain.
- For user-signed proposals, the submitter must have a role required by the first workflow step of that policy.
- When the system selects policies in more than one domain, each user's decision counts only toward the policy of the user's own domain. See [Approvals across domains](#approvals-across-domains).
- For system-signed proposals, the service submitter does not count as a user approval. If a system-signed policy includes a workflow, user-signed approvers must satisfy it.
- If quorum is not reached, the step remains open and users can change their decision. Once a step is executed, it cannot be changed.
- A user can count only once in the complete approval workflow.
- Duplicate approvals are checked at public-key level.
- If a user has roles on both sides of an `And` or `Or`, the engine uses one approval on the quickest valid path.
- `RoleQuorum.quorum` must be from `1` to `2000`.
- `And` and `Or` use `left` and `right`, not arrays.
- An omitted or `null` workflow auto-approves a matching intent.
- An empty workflow array rejects a matching intent.


## Workflow examples

### Operator followed by supervisor or supervisor bot

Step 1 is satisfied by the submitter with the `operator` role. Step 2 is satisfied by one `supervisor` or one `supervisor-bot`.

```json
[
  {
    "role": "operator",
    "quorum": 1,
    "type": "RoleQuorum"
  },
  {
    "left": {
      "role": "supervisor",
      "quorum": 1,
      "type": "RoleQuorum"
    },
    "right": {
      "role": "supervisor-bot",
      "quorum": 1,
      "type": "RoleQuorum"
    },
    "type": "Or"
  }
]
```

### Operator, compliance or risk alternatives, then CISO

Step 1 is satisfied by the submitter with the `operator` role. Step 2 requires compliance or compliance-bot approval and risk or risk-bot approval. Step 3 requires one `ciso` approval.

```json
[
  {
    "role": "operator",
    "quorum": 1,
    "type": "RoleQuorum"
  },
  {
    "left": {
      "left": {
        "role": "compliance",
        "quorum": 1,
        "type": "RoleQuorum"
      },
      "right": {
        "role": "compliance-bot",
        "quorum": 1,
        "type": "RoleQuorum"
      },
      "type": "Or"
    },
    "right": {
      "left": {
        "role": "risk",
        "quorum": 1,
        "type": "RoleQuorum"
      },
      "right": {
        "role": "risk-bot",
        "quorum": 1,
        "type": "RoleQuorum"
      },
      "type": "Or"
    },
    "type": "And"
  },
  {
    "role": "ciso",
    "quorum": 1,
    "type": "RoleQuorum"
  }
]
```

## UI policy builder mapping

The **Create policy** wizard in the UI builds a `v0_CreatePolicy` payload, and **Edit policy** builds a `v0_UpdatePolicy` payload. This section lists every option the wizard offers and the payload field it sets. For the procedure, see [Create a policy in the UI](/pt-br/products/custody/governance/policies/manage-policies#create-a-policy-in-the-ui).

| Wizard step | Field | Payload field | Notes |
|  --- | --- | --- | --- |
| Information | Policy name | `alias` | Required. |
| Information | Description | `description` | Optional. |
| Information | Scope | `scope` | **Self**, **Descendants**, or **Self & descendants**. Default **Self**. |
| Information | Custom properties | `customProperties` | Name-value pairs. |
| Information | Initial lock status | `lock` | **Unlocked** or **Locked**. Default **Unlocked**. Shown only when you create a policy. |
| Conditions | Intent types | `intentTypes` | Always an explicit list. See [Intent types in the UI](#intent-types-in-the-ui). |
| Conditions | Additional conditions | `condition` | See [Condition types in the UI](#condition-types-in-the-ui). An empty editor sends `null`. |
| Evaluation order | Importance rank | `rank` | 0-1000. Default 1. |
| Approval workflow | Workflow option and steps | `workflow` | See [Workflow options in the UI](#workflow-options-in-the-ui). |
| Not shown | Policy ID | `id` | Generated. |
| Not shown | Scripting engine | `scriptingEngine` | Always `Javascript_v0`. |
| Not shown | Intent origin | `intentOrigin` | Never set. The UI creates user-signed policies only. |


Editing an API-created policy in the UI
The UI update payload never includes `intentOrigin` and always lists intent types explicitly. If you edit a policy in the UI:

- A policy with `intentOrigin: "SystemSigned"` becomes a user-signed policy and stops matching system-signed proposals.
- A policy without `intentTypes` gets an explicit list of the intent types the UI offers, and stops matching the intent types that the UI doesn't offer.
- The UI removes intent types that have no UI selector, such as `v0_NotarizeData`, from the policy. If the policy has no other intent types, the UI saves an empty list, so the policy matches nothing. The UI doesn't warn you, and the **Review** step shows **0 intent types**.


The policy details page in the UI doesn't show `intentOrigin`. Check it with [Get policy details](/pt-br/products/custody/reference/api/openapi/policies/getpolicy). Update system-signed policies, catch-all policies, and policies that use intent types without a UI selector with the API.

### Intent types in the UI

The **Conditions** step groups the selectable intent types by entity. Each selected item adds an entry to `intentTypes`, and you must select at least one. **Select all intent types** selects every item, and the UI still sends them as an explicit list. You can't create a policy without `intentTypes` in the UI. To create a catch-all policy, use the API.

| UI group | API intent types |
|  --- | --- |
| Transactions & Transfers | `v0_CreateTransactionOrder`, `v0_CreateTransferOrder`, `v0_AttemptTransactionOrderCancellation`, `v0_ReleaseQuarantinedTransfers` |
| Endpoints | `v0_CreateEndpoint`, `v0_UpdateEndpoint`, `v0_LockEndpoint`, `v0_UnlockEndpoint` |
| Policies | `v0_CreatePolicy`, `v0_UpdatePolicy`, `v0_LockPolicy`, `v0_UnlockPolicy` |
| Domains | `v0_CreateDomain`, `v0_UpdateDomain`, `v0_UpdateDomainPermissions`, `v0_LockDomain`, `v0_UnlockDomain` |
| Ledgers | `v0_CreateLedger`, `v0_UpdateLedger` |
| Accounts | `v0_CreateAccount`, `v0_UpdateAccount`, `v0_AddAccountLedgers`, `v0_LockAccount`, `v0_UnlockAccount` |
| Assets | `v0_UpdateTicker`, `v0_ValidateTickers`, `v0_LockTicker`, `v0_UnlockTicker` |
| Users | `v0_CreateUser`, `v0_UpdateUser`, `v0_LockUser`, `v0_UnlockUser` |
| Vaults | `v0_CreateVault`, `v0_UpdateVault`, `v0_LockVault`, `v0_UnlockVault`, `v0_RewrapVaultKeyMaterial`, `v0_CreateBackup`, `v0_AcknowledgeBackup` |
| Separate checkboxes | `v0_SignManifest` (**Sign Manifest**), `v0_ExecuteExtension` (**Execute Extension**) |


Item labels show the intent type name in sentence case and use Asset in place of Ticker. For example, `v0_LockTicker` is **Lock asset** and `v0_ValidateTickers` is **Validate assets**.

The following intent types have no UI selector. You can reference them in `intentTypes` only through the API: `v0_CreateTicker`, `v0_NotarizeData`, `v0_RegisterTrustedPublicKey`, `v0_AddTrustedPublicKeysForMigration`, `v0_SetSystemProperty`, and `v0_MigrateSilo3AccountBatch`.

### Condition types in the UI

Under **Additional conditions**, select **Create an additional condition** to open the condition editor. Select an entry from **Predefined conditions**, enter its **Value**, and select **Add condition +** to insert the generated condition. If the editor already contains a condition, the UI combines the existing condition and the new one in an `And` node. The UI has no option to combine predefined conditions with `Or`. To use `Or`, or to write your own expression, edit the condition JSON in the editor directly.

The UI wraps predefined conditions that apply only to certain intent types in an `And` node with an intent type check, so the condition is `false` for other intent types. You enter values as text: you type IDs instead of picking them. For list values, separate the values with commas.

The author conditions generate the following expressions:

| Predefined condition | Generated expression |
|  --- | --- |
| If intent author belongs to domain | `context.request.author.domainId == "<value>"` |
| If intent author does not belong to domain | `context.request.author.domainId != "<value>"` |
| If intent author is | `context.request.author.id == "<value>"` |
| If intent author is not | `context.request.author.id != "<value>"` |


The other predefined conditions cover:

| Area | Predefined conditions |
|  --- | --- |
| Users | If user with role is created or updated |
| Policies | If policy targets intent type, If policy scope is, If policy rank is greater than or equal to, If policy rank is less than or equal to |
| Accounts | If account ledger is, If account is in vault |
| Transactions | If transaction amount is greater than or equal to, If transaction amount is less than or equal to, If transaction is sent from account, If transaction vault source is, If transaction destination endpoint is, If transaction destination address is, If transaction destination account is, If transaction destination is an account, If transaction is sent to endpoint which has a score that is greater than or equal to, If transaction is sent to endpoint which has a score that is less than or equal to, If transaction makes Ethereum contract call or has payload data |
| Endpoints | If endpoint ledger is, If endpoint trust score is greater than or equal to, If endpoint trust score is less than or equal to |


Review the generated JSON in the editor before you continue. The transaction amount conditions compare the integer amount in the ledger's smallest unit.

### Workflow options in the UI

The **Approval workflow** step offers three options that map to the `workflow` field:

| UI option | Resulting `workflow` | Behavior |
|  --- | --- | --- |
| Approval workflow (recommended) | Array with one entry per step | Approvers must satisfy each step in order. |
| Always approve | `null` | The system approves matching intents without user approvals. |
| Always reject | Empty array `[]` | Matching intents are rejected without user intervention. |


In an approval workflow step, each approval group becomes a `RoleQuorum` object, with **Amount** as `quorum` and the selected **Role** as `role`. The default amount is 1. **Add condition +** nests the groups of a step in an `And` or `Or` object, and **Add step +** appends another entry to the `workflow` array.

### Review step fields

The **Review** step shows the policy before submission:

| Section | Fields | Payload fields |
|  --- | --- | --- |
| Policy information | Policy name, policy ID, description, evaluation order, scope, custom properties, lock status | `alias`, `id`, `description`, `rank`, `scope`, `customProperties`, `lock` |
| Intent types | Selected intent types | `intentTypes` |
| Additional conditions | Condition JSON | `condition` |
| Approval workflow | One entry per step | `workflow` |


## Role rules

Role names used in users, read access, conditions, and workflows must match exactly.

| Valid | Avoid |
|  --- | --- |
| `policy-operator` | `PolicyOperator` |
| `transaction-operator` | `transaction_operator` |
| `compliance` | `Compliance Team` |
| `platform-admin` | `platform admin` |


The API schema accepts role names that match `[a-z0-9\-]+`.

## Minimal create-policy example

```json
{
  "id": "c35fa005-1640-42ee-a8a5-c43aaae6eb87",
  "alias": "operator-approval",
  "rank": 100,
  "scope": "Self",
  "intentTypes": ["v0_CreateTransactionOrder"],
  "scriptingEngine": "Javascript_v0",
  "condition": {
    "expression": "context.references.users[context.request.author.id].roles.includes('transaction-operator')",
    "type": "Expression"
  },
  "workflow": [
    {
      "role": "transaction-operator",
      "quorum": 2,
      "type": "RoleQuorum"
    }
  ],
  "lock": "Unlocked",
  "description": "Requires transaction operator quorum.",
  "customProperties": {},
  "type": "v0_CreatePolicy"
}
```

## Common mistakes

| Mistake | Result | Fix |
|  --- | --- | --- |
| Empty `workflow: []` | Matching intents are rejected. | Omit workflow or use `null` for auto-approval, or define approval steps. |
| Omitted `intentTypes` on a high-rank policy | Policy can match unexpectedly broad workflows. | Specify intent types unless the policy is a deliberate fallback. |
| `customProperties: null` | Payload validation can fail. | Use `{}` when empty. |
| Role names with uppercase, underscores, spaces, or padding | Workflows cannot be satisfied by expected roles. | Use lowercase hyphenated role names, such as `policy-operator`. |
| `And` or `Or` written as arrays | Payload validation fails. | Use `left`, `right`, and `type`. |
| Amount compared as a JavaScript number | Precision loss or mismatched comparisons. | Use `BigInt(...)` and `n` literals. |
| Missing optional-field checks | Condition can fail for intent types with different payload shapes. | Check existence before accessing nested fields. |
| Required quorum has too few users | Intent cannot be approved. | Create enough users before deploying the policy. |
| First workflow step excludes maker role for a user-signed policy | Intent fails at submission with `NoApplicablePoliciesForDomain`. | Include the maker role in the first workflow step. For system-signed policies, make sure user approvers can satisfy the workflow. |
| Relying on a high-rank parent policy to replace a child-domain policy | Both policies apply. The child-domain workflow is still required, and a child reject-all still rejects. | Ranks compete only within a domain. Design each domain's policies so that its own workflow is acceptable. |
| Relying on `CoerceDescendants` to protect child domains from weak child policies | The strategy doesn't affect child-domain authors. Under either strategy, the system evaluates their intents in the parent and child domains. | Give the parent policy `Descendants` or `SelfAndDescendants` scope. |
| No eligible policy in the author's domain | Intent fails with `NoApplicablePoliciesForDomain`, even when the target domain has a matching policy. | Give each domain whose users propose intents a policy that matches those intents. |


For implementation patterns, see [Policy examples](/pt-br/products/custody/governance/policies/examples).