> For the complete documentation index, see [llms.txt](https://krynix.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://krynix.gitbook.io/docs/reference/policy-reference.md). Agents can also search and read this documentation through its [MCP server](https://krynix.gitbook.io/docs/~gitbook/mcp).

# Policy reference

**API version:** `krynix.dev/v1`. The engine is `@krynix/policy`; the same parser and matcher run in the hosted decision point (`POST /v1/decide`), in `@krynix/sdk`, in the MCP gateway and in the CLI, so a rule behaves identically wherever it runs.

## Schema

```yaml
apiVersion: krynix.dev/v1
kind: Policy
metadata:
  name: string               # lower-case, the registry key
  version: string            # immutable once registered
  description: string
  labels:                    # optional
    key: value
spec:
  scope:
    agents: [string]         # agent ids, or "*"
    event_types: [string]    # usually ["tool_call"]
  rules:
    - id: string
      description: string
      match:
        event_type: string
        payload:
          - field: string    # dotted path into the payload, e.g. arguments.command
            operator: eq|neq|in|not_in|matches|contains|exists|gt|lt|gte|lte
            value: any
      action: allow|deny|redact|require-approval
      severity: info|warning|error|critical
      ci_failure: boolean    # CLI only: fail the pipeline on this rule
      message: string        # the reason the agent sees on deny
      on_timeout: allow|deny # require-approval only; default deny
      on_violation:
        notify: [string]
        create_issue: boolean
  defaults:
    unmatched_action: allow|deny
    unmatched_severity: info|warning
  tools:                     # gateway only: per-tool data-flow flags
    <tool_name>:
      reads_private_data: boolean
      sees_untrusted_content: boolean
      can_exfiltrate: boolean
  flow:                      # gateway only
    block_trifecta: boolean
    declassify: [string]
```

## Evaluation

* **Scope first.** An event outside `scope.agents` or `scope.event_types` is not decided by this policy. In the hosted decision point a bound policy whose scope does not cover the agent abstains; if none covers it, the decision is refused (`422 POLICY_NOT_APPLICABLE`).
* **First match wins.** Rules are tried in order; the first whose every payload condition holds decides. Order from most specific to most general.
* **No match** gets `defaults.unmatched_action`.
* **Several policies** (an agent's bindings plus the organisation's baselines) each decide the call on its own; the most restrictive verdict wins: `deny` > `require-approval` > `redact` > `pass`. A tie goes to the policy that sorts first by name.
* **Deterministic.** The same event and the same policies give the same verdict, on any machine, every time. There is no sampling and no model in the loop.

## Operators

| Operator                 | Matches when                                                                 | Value             |
| ------------------------ | ---------------------------------------------------------------------------- | ----------------- |
| `eq` / `neq`             | the field equals / does not equal the value                                  | any               |
| `in` / `not_in`          | the field is / is not one of the values                                      | array             |
| `matches`                | the field, as a string, matches the regular expression (ECMAScript, Unicode) | string            |
| `contains`               | the field, as a string, contains the substring                               | string            |
| `exists`                 | the field is present (`null` counts as present)                              | `true` or `false` |
| `gt`, `lt`, `gte`, `lte` | both sides coerce to finite numbers and compare                              | number            |

A numeric operator with a non-numeric value is refused at parse time. A non-numeric field value never matches a numeric operator and never throws.

## Actions

| Action             | Hosted decision point                                                            | SDK and gateway                        | CLI (`krynix evaluate`)                                              |
| ------------------ | -------------------------------------------------------------------------------- | -------------------------------------- | -------------------------------------------------------------------- |
| `allow`            | `pass`                                                                           | the call runs                          | no violation                                                         |
| `deny`             | `deny`, with `message` as the reason                                             | the call does not run                  | a violation; exits `1` (`error`) or `2` (`critical`) when CI-failing |
| `redact`           | `redact`, with rewritten arguments; a hook that cannot rewrite treats it as deny | the call runs with rewritten arguments | recorded                                                             |
| `require-approval` | `require-approval`; `on_timeout` applies while no approval queue exists          | the SDK polls for approval             | exits `3` when nothing else fails                                    |

A violation is CI-failing when its severity is `error` or `critical`, or when `ci_failure: true`.

## Where policies live

|             | Hosted                                                                              | Packages (SDK, gateway, CLI)                                  |
| ----------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| Registered  | the dashboard (Policies → New policy)                                               | a `.policy.yaml` file in your repository                      |
| Applied     | bound to an agent, or an organisation baseline                                      | passed to the SDK, the gateway, or `krynix evaluate --policy` |
| Changed     | a new version; old versions are immutable and archivable                            | a commit                                                      |
| Who decided | recorded in every `decision` record with the position in the agent's change history | the gateway's audit chain, or the CLI's exit code             |

## Data-flow rules

`spec.tools` and `spec.flow` are evaluated by the MCP gateway only: with `flow.block_trifecta` on, a `can_exfiltrate` tool call is denied once the session has both read private data and seen untrusted content, whatever the per-rule verdicts say. `flow.declassify` names tools that contribute no taint; it does not exempt an exfiltrating sink. The hosted decision point and the CLI carry these fields through and do not evaluate them.

## Validation

```bash
krynix validate --policy policies/
krynix policy test --policy policies/no-shell.policy.yaml --trace traces/session.trace.jsonl
```

The hosted registry parses a version at registration and refuses an unparseable one; binding an unparseable version to an agent is refused too (`422 POLICY_UNPARSEABLE`).
