> For the complete documentation index, see [llms.txt](https://govplane.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://govplane.gitbook.io/docs/documentation/schemas/policy-bundle.md).

# Policy Bundle

`RuntimeBundleV1` — the document the SDK loads and evaluates.

### Top level

| Field           | Type              | Required | Notes                                          |
| --------------- | ----------------- | -------- | ---------------------------------------------- |
| `schemaVersion` | `1`               | ✅        | Integer. Any other value is rejected.          |
| `env`           | `string`          | ✅        | `prod` \| `staging` \| `dev` \| `test`         |
| `policies`      | `RuntimePolicy[]` | ✅        | May be empty                                   |
| `orgId`         | `string`          | —        | Required for Cloud bundles, optional for local |
| `projectId`     | `string`          | —        | Required for Cloud bundles, optional for local |
| `generatedAt`   | `string`          | —        | ISO-8601                                       |
| `bundleVersion` | `number`          | —        | Revision counter, whole number ≥ 1             |
| `checksum`      | `string`          | —        | `sha256:<64 hex>` over the canonical payload   |
| `etag`          | `string`          | —        | Delivery metadata                              |
| `signature`     | `BundleSignature` | —        | Detached signature over the canonical payload  |

```json
{
  "schemaVersion": 1,
  "env": "prod",
  "bundleVersion": 3,
  "generatedAt": "2026-08-08T09:00:00.000Z",
  "policies": [],
  "checksum": "sha256:9f2c…",
  "signature": { "algorithm": "ECDSA_SHA_256", "keyId": "release-2026-08", "value": "MEUCIG…" }
}
```

### Policy

| Field           | Type            | Required | Notes                                     |
| --------------- | --------------- | -------- | ----------------------------------------- |
| `policyKey`     | `string`        | ✅        | Unique across the bundle                  |
| `activeVersion` | `number`        | ✅        |                                           |
| `rules`         | `RuntimeRule[]` | ✅        | May be empty                              |
| `defaults`      | `PolicyDefault` | —        | Applies when no rule in this policy fires |

```json
{
  "policyKey": "login-protection",
  "activeVersion": 1,
  "defaults": { "effect": "allow" },
  "rules": []
}
```

### Rule

| Field         | Type                       | Required | Notes                                            |
| ------------- | -------------------------- | -------- | ------------------------------------------------ |
| `id`          | `string`                   | ✅        | Unique **within the policy**, not the bundle     |
| `status`      | `"active"` \| `"disabled"` | ✅        | Only `active` fires                              |
| `priority`    | `number`                   | ✅        | Higher wins, within one effect type              |
| `target`      | `Target`                   | ✅        |                                                  |
| `effect`      | `Effect`                   | ✅        | Unconditional / fallback effect                  |
| `when`        | `WhenAst`                  | —        | Absent means always apply `effect`               |
| `thenEffect`  | `Effect`                   | —        | When `when` is true. Falls back to `effect`      |
| `elseEffect`  | `Effect`                   | —        | When `when` is false. Absent means skip the rule |
| `description` | `string`                   | —        |                                                  |

```json
{
  "id": "r_deny_after_five",
  "status": "active",
  "priority": 100,
  "target": { "service": "auth", "resource": "login", "action": "authenticate" },
  "when": { "op": "gte", "path": "failedAttempts", "value": 5 },
  "effect": { "type": "deny" }
}
```

### Target

All three required, non-empty. Matching is exact — no wildcards, no hierarchy.

```json
{ "service": "auth", "resource": "login", "action": "authenticate" }
```

### Effect

`type` is one of `allow`, `deny`, `kill_switch`, `throttle`, `custom`. Three carry a descriptor.

```json
{ "type": "allow" }
{ "type": "deny" }
{ "type": "kill_switch", "killSwitch": { "service": "payments", "reason": "INC-4421" } }
{ "type": "throttle",    "throttle": { "limit": 10, "windowSeconds": 3600, "key": "tenant" } }
{ "type": "custom",      "value": "{\"newCheckout\":true}" }
```

| Type          | Required descriptor | Fields                          |
| ------------- | ------------------- | ------------------------------- |
| `allow`       | —                   |                                 |
| `deny`        | —                   |                                 |
| `kill_switch` | `killSwitch`        | `service` (required), `reason`  |
| `throttle`    | `throttle`          | `limit`, `windowSeconds`, `key` |
| `custom`      | `value`             | Arbitrary string, often JSON    |

### Policy defaults

Same effect vocabulary, expressed as a descriptor rather than an object with `type`.

```json
{ "effect": "allow" }
{ "effect": "deny" }
{ "effect": "kill_switch", "killSwitch": { "service": "payments" } }
{ "effect": "throttle",    "throttle": { "limit": 100, "windowSeconds": 60, "key": "tenant" } }
{ "effect": "custom",      "customEffect": "{\"tier\":\"free\"}" }
```

{% hint style="info" %}
Note `customEffect` here, versus `value` on a rule effect. A `kill_switch` or `throttle` default missing its descriptor is ignored rather than applied.
{% endhint %}

### Condition (`when`)

Comparison, membership and existence leaves:

```json
{ "op": "eq",     "path": "role",   "value": "admin" }
{ "op": "neq",    "path": "plan",   "value": "free" }
{ "op": "gt",     "path": "amount", "value": 1000 }
{ "op": "gte",    "path": "amount", "value": 1000 }
{ "op": "lt",     "path": "amount", "value": 50 }
{ "op": "lte",    "path": "amount", "value": 50 }
{ "op": "in",     "path": "role",   "values": ["admin", "superuser"] }
{ "op": "exists", "path": "requestTier" }
```

Logical combinators:

```json
{ "op": "and", "conditions": [
  { "op": "eq", "path": "isAuthenticated", "value": true },
  { "op": "in", "path": "role", "values": ["admin", "superuser"] }
] }

{ "op": "or", "conditions": [
  { "op": "eq", "path": "plan", "value": "enterprise" },
  { "op": "gte", "path": "amount", "value": 1000 }
] }

{ "op": "not", "condition": { "op": "eq", "path": "role", "value": "banned" } }
```

| Operator                              | Payload            |
| ------------------------------------- | ------------------ |
| `eq`, `neq`, `gt`, `gte`, `lt`, `lte` | `path`, `value`    |
| `in`                                  | `path`, `values[]` |
| `exists`                              | `path`             |
| `and`, `or`                           | `conditions[]`     |
| `not`                                 | `condition`        |

Behaviour worth knowing:

* `path` may be written `plan` or `ctx.plan` — a leading `ctx.` is stripped. Dots traverse nested objects.
* Ordering comparisons coerce both sides to numbers, so a non-numeric value yields `false` rather than an error.
* `exists` is false for `null` and absent; true for `0`, `""` and `false`.
* An unknown operator is **false, not an error**, so an older runtime does not crash on a newer bundle.
* Legacy spellings are accepted: `ne` for `neq`, `args` for `conditions`, `arg` for `condition`.

### Signature

```json
{ "algorithm": "ECDSA_SHA_256", "keyId": "release-2026-08", "value": "MEUCIG…" }
```

| Algorithm       | Key                     | `value` encoding | Local | Cloud |
| --------------- | ----------------------- | ---------------- | ----- | ----- |
| `ECDSA_SHA_256` | P-256 key pair          | base64 DER       | ✅     | ✅     |
| `HMAC_SHA256`   | 256-bit secret (64 hex) | lowercase hex    | ✅     | ❌     |

Ed25519 is rejected.

### Canonical payload

Checksums and signatures cover a projection, not the file:

```
schemaVersion, orgId, projectId, env,
policies[] → policyKey, activeVersion, defaults, rules
```

Excluded: `generatedAt`, `bundleVersion`, `checksum`, `etag`, `signature`. Keys are sorted recursively and serialised without whitespace, then hashed as UTF-8 — so reformatting a bundle does not invalidate its signature.

### Validation codes

Returned by `validateBundle()` and by `govplane validate`.

| Code                                          | Meaning                                     |
| --------------------------------------------- | ------------------------------------------- |
| `DOCUMENT_NOT_OBJECT`                         | Not a JSON object                           |
| `INVALID_SCHEMA_VERSION`                      | `schemaVersion` is not `1`                  |
| `INVALID_ENV`                                 | Not one of the four environments            |
| `MISSING_POLICY_KEY` / `DUPLICATE_POLICY_KEY` | Policy key absent or reused                 |
| `INVALID_ACTIVE_VERSION`                      | Not a number                                |
| `RULES_NOT_ARRAY`                             | `rules` is not an array                     |
| `MISSING_RULE_ID` / `DUPLICATE_RULE_ID`       | Rule id absent or reused within the policy  |
| `INVALID_RULE_STATUS`                         | Not `active` or `disabled`                  |
| `INVALID_RULE_PRIORITY`                       | Not a number                                |
| `INVALID_RULE_TARGET`                         | `target` or one of its three fields missing |
| `INVALID_RULE_EFFECT`                         | Effect missing or unrecognised              |

### See also

* [Policy Drafts Schema](/docs/documentation/schemas/policy-draft.md) — the authoring format
* [Bundles](/docs/documentation/basic-concepts/bundles.md) — checksums, signing and verification
* [Effects](/docs/documentation/basic-concepts/effects.md)&#x20;
* [Conditional Rules](/docs/documentation/basic-concepts/conditional-rules.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://govplane.gitbook.io/docs/documentation/schemas/policy-bundle.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
