> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ana.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# Document structure

> Every top-level key, every global setting, every rule key, and the YAML rules that the engine applies to a rule document.

After you read this page, you can write the frame of any rule document: its variables, its global settings, its rules, and the YAML scalars inside them.

## Top level

A document is one YAML mapping. These are the only keys it accepts:

| Key | Type | Required | Meaning |
| - | - | - | - |
| `variables` | mapping, name to scalar | no | Names for addresses and IBANs. See [variables](#variables). |
| `global` | mapping | no | Settings for the full document. See [global](#global). |
| `rules` | mapping, rule name to rule | see below | The rules, in author order. See [rules](#rules). |
| `agent_envelope` | mapping | see below | A declaration that the engine does not enforce. See [agent\_envelope](#agent_envelope). |

The document must have the key `rules`, the key `agent_envelope`, or both. If it has neither, it is refused with `DslDocument must contain at least one of 'rules' or 'agent_envelope'`. This check looks at the key, not at the number of rules:

* `rules: {}` is valid. It means "run nothing". Commit it to stop every rule of the account and keep the permission in place. An `erc20_allow` account needs `global.fees_method` in this document too.
* A bare `rules:` with no value is a YAML null. It is refused with `expected a mapping; got null`.

Any other top-level key is refused with `unknown field '<key>' in document`.

> [!NOTE]
>
> The commit of a document with `rules: {}` retires every rule of the account. The engine keeps only the new empty document. Keep your own copy of the rules before you replace them.

## variables

`variables` gives a name to an address or to an IBAN, so that the rules can refer to it as `$name`.

```yaml theme={null}
variables:
  landlord: "0x1111111111111111111111111111111111111111"
  landlord_iban: "DE89370400440532013000"
```

| Rule | Detail |
| - | - |
| Name | Must match `[A-Za-z_][A-Za-z0-9_]*`. Another name is refused with `variable name '<key>' is not a name a $ reference can use: start with a letter or '_', then use letters, digits and '_'`. |
| Value | A YAML text, number or boolean. The engine reads it as text. A null value is refused with `expected a string; got null`. Quote it. |
| Where a `$name` can stand | Only at an address position or an IBAN position. See the list below. |
| Check | The value is checked where it is used, not where it is defined. At an address position it must be `0x` and 40 hex characters. At an IBAN position it must be a canonical IBAN. |
| Unused entry | Valid. The engine gives the warning `variable '$<name>' is defined but no address or IBAN position uses it`. |

Address positions: `incoming_tx.account`, `incoming_tx.from`, `outgoing_tx.account`, `outgoing_tx.to`, `send_one.to`, the `to` of each `send_batch` recipient, each entry of `global.recipient_allowlist`, and `agent_envelope.to` and `agent_envelope.recipient_allowlist`.

IBAN positions: `off_ramp.to.iban` and each entry of `global.iban_allowlist`.

A `$name` in a value expression, such as `value: "$budget"`, is refused. A variable never holds an amount. See [Values](https://docs.ana.fi/rules/values.md#what-a-value-cannot-contain).

## global

`global` holds settings for the full document. Every key is optional. An unknown key is refused with `unknown field '<key>' in global constraints`.

```yaml theme={null}
global:
  token_allowlist: [USDC, WETH]
  recipient_allowlist: ["$landlord", "$savings"]
  fees_method: { type: fixed_token, token: USDC }
```

| Key | Type | Meaning |
| - | - | - |
| `token_allowlist` | list of token symbols, at least 1 | Every token that the document names must be on this list. |
| `recipient_allowlist` | list of addresses, at least 1 | Every `send_one` and `send_batch` recipient must be on this list. |
| `iban_allowlist` | list of IBANs, at least 1 | Every `off_ramp` IBAN must be on this list. |
| `fees_method` | mapping | The one token that pays every Anafi fee of the document. |
| `notification_email` | text | The one inbox for every `notify` action of the document. |

The three allowlists are described in full on [Limits](https://docs.ana.fi/rules/limits.md#allowlists). An empty list is refused, for example `global.token_allowlist must not be empty`. Omit the key to set no limit.

### fees\_method

```yaml theme={null}
global:
  fees_method: { type: fixed_token, token: USDC }
```

| Field | Type | Required | Meaning |
| - | - | - | - |
| `type` | text | yes | The only value is `fixed_token`. Another value is refused with `unknown fees_method type '<value>'`. |
| `token` | token symbol | yes | The token that pays the fees. |

Without `fees_method`, the fees are paid in the native coin of the network.

The fee token must be the native coin or a dollar stablecoin of the network. Another token is refused at staging with `fee token <TOKEN> is not allowed on this chain; use the native coin or a dollar stablecoin`.

| Network | Accepted fee tokens |
| - | - |
| `polygon` | `POL`, `USDC`, `USDC.e`, `USDT0` |
| `xlayer` | `OKB`, `USDC`, `USDG`, `USDT0` |
| `polygon-amoy` | `POL`, `USDC` |

Two more rules apply:

* If `global.token_allowlist` is present, it must contain the fee token. This includes the native coin when you omit `fees_method`. Otherwise the document is refused with `global.token_allowlist does not contain fee token <TOKEN>`.
* An `erc20_allow` account must set `fees_method`, and the token must not be the native coin. The adapter of that account can pull only ERC-20 tokens. See [what each account kind accepts](https://docs.ana.fi/rules/validation.md#account-kind-refusals).

The fee amounts and terms are on [Fees](https://docs.ana.fi/concepts/fees.md).

### notification\_email

```yaml theme={null}
global:
  notification_email: "owner@example.com"
```

`notification_email` is the only inbox of the document. Every `notify` action of every rule sends its email there.

| Case | Result |
| - | - |
| Absent, empty or only spaces | The document has no inbox. Each `notify` still fires and delivers nothing. Each rule with a `notify` gets a warning. |
| The address that the owner verified for this account | Accepted. The engine compares the two after it trims them and changes them to lowercase. |
| Any other address | Refused at staging with `the document's notification email is not verified for this wallet`. The SDK throws `NotificationEmailNotVerifiedError`. The engine refuses it again when the commit lands. |

The rule language does not check the address syntax. An address that has a non-ASCII character, a space inside it, or one of the characters `<`, `>`, `,`, `;` or `"` can never match a verified address.

The engine reads the address when it adopts the document. It does not read it again when a rule fires. If the owner verifies a different address later, the mail goes to the old address until a new document is committed. A new document that still names the old address is refused.

> [!WARNING]
>
> Do not put an address in `notification_email` that the owner did not verify. The stage refuses the document. The owner verifies an inbox through a sign-in that names the domain of the Anafi dapp, `app.ana.fi`. An integration on another domain cannot complete that flow today. See [Notification email](https://docs.ana.fi/flows/notification-email.md).

The SDK function `documentWithNotificationEmail(yaml, canonicalEmail)` returns the document with `global.notification_email` set to a canonical address. See [Notification email in the SDK](https://docs.ana.fi/sdk/notification-email.md).

## rules

`rules` is a mapping. Each key is a rule name, and each value is a rule. A document can hold at most 32 rules. More are refused with `document defines <count> rules; at most 32 are allowed`.

```yaml theme={null}
rules:
  dapp_standing_order_3f9a1c:
    trigger:
      type: periodic
      interval_seconds: 604800
    actions:
      - type: send_one
        to: "0x1111111111111111111111111111111111111111"
        value: "25 USDC"
    enabled: true
    start: "2027-01-01T00:00:00Z"
    expiry: "2027-12-31T23:59:59Z"
```

| Key | Type | Required | Default | Meaning |
| - | - | - | - | - |
| `trigger` | mapping | yes | none | When the rule fires. See [Triggers](https://docs.ana.fi/rules/triggers.md). |
| `actions` | list of mappings, at least 1 | yes | none | What the rule does, in order. See [Actions](https://docs.ana.fi/rules/actions.md). An empty list is refused with `rule actions must not be empty`. |
| `enabled` | boolean | no | `true` | `false` keeps the rule in the document and never fires it. |
| `start` | RFC 3339 instant | no | none | Before this instant, the rule does not fire. |
| `expiry` | RFC 3339 instant | no | none | After this instant, the rule does not fire. |

Any other key is refused with `unknown field '<key>' in rule`. An error inside a rule names the rule: `rule '<name>': <error>`.

### Rule names and identity

| Rule | Detail |
| - | - |
| Form | Any YAML text or number key that is not empty. An empty name is refused with `rule name must not be empty`. |
| Unique | A key that occurs twice is a YAML error: `YAML parse: rules: duplicate entry with key "<name>"`. Two different keys that read as the same name, such as `1` and `"1"`, are refused with `duplicate rule name '1'`. |
| Recommended form | Lowercase letters, digits and `_`. The SDK readers of the form builders read only names that match `\w+`. |
| Convention | The Anafi dapp names a rule `dapp_<kind>_<six hex digits>`, for example `dapp_dca_528aff`. The public rule-language page asks a coding agent to use `ai_<what it does>_<six hex digits>`. |

The engine identifies a rule by its name and by the full content of its trigger. When you commit a new document, the engine compares it with the current one:

| Change in the new document | Result |
| - | - |
| Same name, same trigger, other `actions`, `enabled`, `start` or `expiry` | The same rule continues with the new values. |
| Same name, different trigger | The engine retires the old rule and starts a new rule. |
| New name | The engine starts a new rule. A rename is a removal plus a new rule. |
| Name not in the new document | The engine retires the rule. |

> [!WARNING]
>
> Do not rename a rule to edit it. Keep every rule name that a document already has. A rename retires the rule and starts a different one.

### enabled

`enabled` accepts a YAML boolean (`true`, `false` and their capitalized forms) or the exact texts `"true"` and `"false"`. A disabled rule stays in the document and in the commitment. It does not fire. Commit the document again with `enabled: true` to fire it again.

### start and expiry

`start` and `expiry` are RFC 3339 instants with a date, a time and an offset, for example `"2027-01-01T00:00:00Z"` or `"2027-01-01T09:00:00+01:00"`. A bare date such as `"2027-01-01"` is refused with `bad ISO-8601 timestamp '2027-01-01'`.

| Bound | Behavior |
| - | - |
| `start` in the future | The rule does not fire before `start`. The first fire is the first trigger boundary at or after `start`. |
| `start` in the past | No effect. |
| `expiry` in the past | The rule does not fire. |
| `expiry` moved later in a new commit | The rule fires again from the time of that commit. It does not fire for the time it missed. |
| `start` at or after `expiry` | Valid. The rule never fires. |

Neither bound removes the rule. A rule after its `expiry` stays in the document and fires again if a later commit moves `expiry`.

## agent\_envelope

`agent_envelope` declares limits for an agent key that spends from the account. The engine accepts it and enforces none of its fields. No fee, no transfer and no check comes from it.

> [!WARNING]
>
> Do not rely on `agent_envelope` to limit an agent. Put each automation that must run in a rule. Put each limit that must hold on chain in the permission of the adapter. See [Limits](https://docs.ana.fi/rules/limits.md).

| Field | Type | Required | Meaning that the field declares |
| - | - | - | - |
| `to` | address | yes | The address of the agent key. |
| `token_allowlist` | list of token symbols, at least 1 | yes | The tokens the agent may spend. It does not use `global.token_allowlist`. |
| `recipient_allowlist` | list of addresses | no | The addresses the agent may pay. An empty list is valid here. |
| `balance_floor` | `"<N> <TOKEN>"` | no | The balance that the account keeps after each spend. |
| `per_tx_max` | `"<N> <TOKEN>"` | no | The largest amount of one spend. |
| `expiry` | RFC 3339 instant | no | The end of the envelope. |

The parser checks the shape of each field: the addresses, the token symbols, the amounts and the instant. Any other key is refused with `unknown field '<key>' in agent_envelope`.

## YAML scalar rules

The engine reads the document with a YAML 1.2 parser. A plain scalar, without quotes, can become a number or a boolean. These rules prevent surprises:

| Rule | Why |
| - | - |
| Put every address in double quotes. | An unquoted address whose value fits in 128 bits, such as `0x0000000000000000000000000000000000000001`, becomes an integer. The document is then refused. |
| Put every `time_of_day` in double quotes. | An unquoted value that starts with `*`, such as `*:15`, is a YAML alias. The document is refused. |
| Put every amount, range, expression, timestamp and IBAN in double quotes. | The quotes keep the text exactly as you wrote it. |
| Do not use YAML anchors (`&name`) or aliases (`*name`). | The engine refuses them before it parses the document: `DSL document uses a YAML anchor or alias (line <n>); the DSL grammar has no use for either`. |
| Write integer fields as YAML integers. | `interval_seconds`, `hold_seconds`, `cooldown_seconds` and `day_of_month` entries accept an integer or a text of digits. A negative number or a fraction is refused. |
| Write `price_usd` as a number or as quoted text. | Both work. Quoted text keeps every digit exactly. |
| Token symbols, `type` values, weekday names and `direction` can stay plain. | They are plain text in YAML. `USDC.e` is plain text too. |

Comments, blank lines, indentation width, flow style (`{ ... }`, `[ ... ]`) and block style are all valid. They do not change what the engine reads. They do change the bytes of the document, and so the commitment.

## Size limits

The engine checks these limits before it parses the YAML:

| Limit | Value | Refusal text |
| - | - | - |
| Length of the document | 65536 bytes (64 KiB) | `DSL document is <bytes> bytes, over the 65536-byte limit` |
| Nesting depth | 32 levels | `DSL document nests at least <depth> levels deep, over the 32-level limit` |
| Anchors and aliases | none allowed | `DSL document uses a YAML anchor or alias (line <n>); the DSL grammar has no use for either` |

The deepest valid document nests 7 levels: the document, `rules`, a rule, `actions`, an action, `recipients`, and a recipient.

Other limits apply to parts of the document:

| Part | Limit |
| - | - |
| Rules in one document | 32 |
| One value expression | 256 bytes |
| Recipients in one `send_batch` | 24, checked at staging |
| `periodic.interval_seconds` | 10 to 3153600000 |
| `off_ramp.memo` | 5 to 140 characters |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.