> ## 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.

# Validation

> What the engine checks when you stage a rule document, the exact refusal texts, the warnings, and what validates but still does not run.

After you read this page, you can read a refusal or a warning from the engine, find its cause in your document, and fix it.

## Where the checks run

The engine checks a document when you stage it, before the owner signs anything. It runs the same document checks again when the commit lands on chain.

| SDK call | Route | Account kind |
| - | - | - |
| `stageDsl(params)` | `POST /api/wallets/{account}/dsl/commit/stage` | `safe_module` |
| `stageErc20AllowDsl(params)` | `POST /api/wallets/{account}/dsl/commit/stage` | `erc20_allow` |

The document travels encrypted to the engine. The refusal and the warnings come back encrypted to your client, and the SDK opens them. The Anafi API in the middle cannot read them.

| Outcome | What your code gets |
| - | - |
| Accepted | A staged result with `warnings: string[]`: the warning texts, in the order of the engine. Empty for a clean document. |
| Refused for its content | `DslStageRefusedError`, HTTP status 422. `refusal` holds the reason as the engine wrote it. The message is `the engine refused the document: <refusal>`. |
| Refused for its inbox | `NotificationEmailNotVerifiedError`, a subclass of `DslStageRefusedError`. |
| Built on an old document | `DslStaleParentError`, HTTP status 409. `current` holds the document that the chain has now. Build the document again on `current`. |

The error classes are on [Errors](https://docs.ana.fi/sdk/errors.md). The stage call is on [Documents](https://docs.ana.fi/sdk/documents.md).

The engine stops at the first refusal. Fix it and stage again to see the next one.

## The order of the checks

**1. Size**

Length, nesting depth, anchors and aliases.

**2. Parse**

The YAML, the shape of every mapping and scalar, the units of every expression, the variables, the trigger fields, the transfer filters, the cents of `off_ramp` literals, and the allowlists.

**3. Address checks**

A watched `account` that is the account itself, a payment to the account itself, a payment to the zero address.

**4. Network checks**

The bank payout rail, the tokens of the network, the price of `price_crossed` tokens, the fee floor of literal amounts, the fee token, the swap venue, the size of each `send_batch`.

**5. Inbox**

`global.notification_email` against the verified inbox of the account.

**6. Account kind**

What the adapter of the account can serve.

**7. Parent**

The document that the stage names as its parent is still the document on chain.

## Size refusals

These come before the YAML parse. The text has no prefix.

| Cause | Refusal text |
| - | - |
| Longer than 65536 bytes | `DSL document is <bytes> bytes, over the 65536-byte limit` |
| Deeper than 32 levels | `DSL document nests at least <depth> levels deep, over the 32-level limit` |
| An anchor `&x` or an alias `*x` | `DSL document uses a YAML anchor or alias (line <n>); the DSL grammar has no use for either` |

An unquoted `time_of_day: *:15` is an alias. Quote it.

## Parse refusals

Each parse refusal at staging starts with `DSL parse: `. A refusal inside a rule then names the rule: `DSL parse: rule '<rule>': <reason>`. A YAML syntax error names the line and the column: `DSL parse: <line>:<col>: YAML parse: <reason>`.

### Shape

| Class | Refusal text | Example cause |
| - | - | - |
| YAML | `YAML parse: <reason>` | bad indentation, a repeated key |
| Wrong node | `expected <a mapping \| a sequence \| a string \| an integer \| a boolean \| a scalar \| a scalar mapping key>; got <null \| bool \| number \| string \| sequence \| mapping \| tagged>` | `rules:` with no value |
| Missing field | `required field '<field>' missing` | a `send_one` with no `to` |
| Unknown field | `unknown field '<key>' in <context>` | `max_executions: 5` in a rule |
| Bad scalar | `bad <form> '<text>'` | `bad ISO-8601 timestamp '2027-01-01'` |
| Unknown value | `unknown <field> '<value>'` | `unknown token 'usdc'`, `unknown notify channel 'sms'` |
| Out of range | `<field> <constraint>` | `periodic interval_seconds must be at least 10 seconds` |
| Empty list | `<list> must not be empty` | `rule actions must not be empty` |
| Structure | a fixed text | `calendar requires at least one of day_of_month or day_of_week` |
| Rule name | `rule name must not be empty`, `duplicate rule name '<name>'` | |
| Rule count | `document defines <count> rules; at most 32 are allowed` | |
| No rules key | `DslDocument must contain at least one of 'rules' or 'agent_envelope'` | `{}` |

The `<context>` of an unknown field is one of: `document`, `global constraints`, `fees_method`, `rule`, `agent_envelope`, `periodic trigger`, `calendar trigger`, `at_fixed_time trigger`, `incoming_tx trigger`, `outgoing_tx trigger`, `price_crossed trigger`, `send_one action`, `send_batch action`, `send_batch recipient`, `exchange action`, `notify action`, `off_ramp action`, `off_ramp recipient`.

The `<form>` of a bad scalar is one of these texts:

| Form text | Field |
| - | - |
| `address (expected 0x + 40 hex chars or $variable reference)` | an address position |
| `IBAN (expected an uppercase IBAN without spaces, or a $variable reference)` | an IBAN position |
| `ISO-8601 timestamp` | `start`, `expiry`, `timestamps`, `agent_envelope.expiry` |
| `IANA timezone` | `calendar.timezone` |
| `time_of_day ("HH:MM", "*:MM", or "*/N:MM" with N in 1..=23)` | `calendar.time_of_day` |
| `day_of_month`, `day_of_month (out of range)`, `day_of_month (must be a non-negative integer)` | `calendar.day_of_month` |
| `value range (expected '<N> <TOKEN>' or '<N>..<M> <TOKEN>')`, `value range bound` | a transfer trigger `value` |
| `token value (expected '<N> <TOKEN>')`, `amount in token value` | `balance_floor`, `per_tx_max` |
| `integer`, `non-negative integer` | an integer field |
| `decimal (>18 fractional digits or overflow)`, `integer (overflow)` | `price_usd`, a range bound |
| `country (expected an ISO 3166-1 alpha-2 code such as DE)` | `off_ramp.to.country` |

The `<field>` of an unknown value is one of: `trigger type`, `action type`, `notify channel`, `day-of-week`, `token`, `direction`, `off_ramp provider`, `fees_method type`.

The structure texts:

* `day_of_month must not contain duplicates`
* `day_of_week must not contain duplicates`
* `timestamps must not contain duplicates`
* `calendar requires at least one of day_of_month or day_of_week`
* ``off_ramp recipient needs the account holder: `first_name` and `last_name` for a person, or `company_name` for a business``
* ``off_ramp recipient names both a person and a `company_name`; write exactly one holder``
* `` off_ramp recipient names a person by half; write both `first_name` and `last_name` ``
* ``off_ramp recipient's `first_name` must not be blank``, and the same for `last_name` and `company_name`

The out-of-range texts:

* `value range lower bound must be <= upper bound`
* `periodic interval_seconds must be > 0`
* `periodic interval_seconds must be at least 10 seconds`
* `periodic interval_seconds must be at most 3153600000 (100 years)`
* `off_ramp memo must be 5 to 140 characters, at least 5 of them past any leading or trailing spaces`
* `price_crossed price_usd must be > 0`

The empty-list texts name these lists: `day_of_month`, `day_of_week`, `timestamps`, `send_batch recipients`, `rule actions`, `global.token_allowlist`, `global.recipient_allowlist`, `global.iban_allowlist`, `agent_envelope.token_allowlist`.

### Expressions

| Cause | Refusal text |
| - | - |
| Syntax | `value expression: <parser message>`, for example `value expression: Invalid token at 9` |
| Bare token name | `value expression: a bare token name is not a value: write an amount ("25 USDT") or trigger.value` |
| Variable in a value | `value expression names variable '$<name>', but a variable stands only at an address or IBAN position: write the amount itself` |
| Too long | `value expression: value expression is <n> bytes, over the 256-byte limit` |
| Units of `+`, `-` | ``rule '<rule>': `+` operands must agree: left is <unit>, right is <unit>`` |
| Units of `min`, `max` | ``rule '<rule>': `min` arms must agree: first is <unit>, second is <unit>`` |
| Two amounts multiplied | ``rule '<rule>': `*` cannot multiply two token-typed values (<unit> and <unit>)`` |
| Value is not an amount | `rule '<rule>': <send_one \| send_batch recipient \| exchange in> value must be a token amount; got <unit>` |
| Same token on both sides | ``rule '<rule>': exchange `in` and `out` are both <TOKEN>; a swap must name two different tokens`` |
| `off_ramp` not in `EURe` | `rule '<rule>': off_ramp value must be an amount of EURe, the token its provider redeems; got <unit>` |

A `<unit>` reads `amount of <TOKEN>`, `percentage`, `bare number` or `polymorphic`. `polymorphic` is the unit of `trigger.value` under a transfer trigger without a range.

### References, filters and allowlists

| Cause | Refusal text |
| - | - |
| Bad variable name | `variable name '<key>' is not a name a $ reference can use: start with a letter or '_', then use letters, digits and '_'` |
| Undefined variable | `undefined variable '$<name>'` |
| Variable is not an address | `variable '$<name>' is used as an address but its value '<value>' is not a 0x + 40-hex address` |
| Variable is not an IBAN | `variable '$<name>' is used as an IBAN but its value '<value>' is not a canonical IBAN (uppercase, no spaces, valid check digits)` |
| Zero `account` | `transfer account '<account>' resolves to the zero address` |
| `account` equals `from` or `to` | `transfer account '<account>' and counterparty '<other>' resolve to the same address` |
| Zero `outgoing_tx.to` | `outgoing_tx to '<to>' resolves to the zero address; a burn is not an outbound payment` |
| Unknown trigger field | `unknown trigger field 'trigger.<field>'; the only field is 'trigger.value'` |
| `trigger.value` without a transfer trigger | `'trigger.value' reads the amount of a matched transfer, so only an incoming_tx or outgoing_tx rule can use it` |
| `off_ramp` literal with a fraction of a cent | `off_ramp value '<amount> EURe' names a fraction of a cent, which no bank transfer can carry` |
| Token not on the allowlist | `token '<TOKEN>' not in global.token_allowlist` |
| Recipient not on the allowlist | `address '<address>' not in global.recipient_allowlist` |
| IBAN not on the allowlist | `IBAN '<iban>' not in global.iban_allowlist` |

## Address refusals

These texts have no `DSL parse: ` prefix.

| Cause | Refusal text |
| - | - |
| A transfer trigger watches the account itself | `rule '<rule>': account '<account>' is this wallet; omit account to watch this wallet` |
| A send pays the account itself | `rule '<rule>': This is your own Anafi account. Choose another destination.` |
| A send pays the zero address | `rule '<rule>': This is the zero address. Funds sent there are lost. Choose another destination.` |

The comparison ignores letter case and replaces each `$name` first. The checks apply to `send_one` and `send_batch` under every trigger.

## Network refusals

The `<network name>` is `Polygon PoS`, `X Layer` or `Polygon Amoy testnet`. The `<network>` is `polygon`, `xlayer` or `polygon-amoy`.

| Cause | Refusal text |
| - | - |
| `off_ramp` on `polygon` or `xlayer` | `rule '<rule>': network <network> carries no fiat rail, so an off_ramp through monerium could never execute here` |
| A token that the network does not have, in a rule | `rule '<rule>': <TOKEN> is not a token on <network name>.` |
| The same, in `global.token_allowlist` | `global.token_allowlist: <TOKEN> is not a token on <network name>.` |
| `USDT` on `polygon` | The text above, then ` Did you mean USDT0?` |
| `price_crossed` on a token that the network does not price | ``rule '<rule>': <network name> has no price for <TOKEN>, so a `price_crossed` on it could never fire`` |
| A literal amount at or below the fee floor | `An amount of <amount> <TOKEN> or less is refused: the Anafi fee is at least $0.20` |
| A literal amount in a token with no known price | `No price is known for <TOKEN>, so the Anafi fee cannot be computed` |
| A fee token that is not the native coin or a dollar stablecoin | `fee token <TOKEN> is not allowed on this chain; use the native coin or a dollar stablecoin` |
| A `token_allowlist` without the fee token | `global.token_allowlist does not contain fee token <TOKEN>` |
| `exchange` on `polygon-amoy` | ``rule '<rule>': network polygon-amoy has no swap aggregator, so an `exchange` could never execute here`` |
| `exchange` of a token with no contract | `rule '<rule>': exchange <input \| output> token <TOKEN> has no contract on network <network>` |
| `send_batch` with more than 24 items | `rule '<rule>': send_batch has <count> recipients, but this chain's limit is 24` |

The token check covers `global.token_allowlist`, transfer trigger ranges, `price_crossed.token`, the literal amounts of `send_one`, `send_batch` and `off_ramp`, and both sides of `exchange` on a network with a swap venue. The fee floor check covers only an action value that is one literal amount, such as `"0.1 USDC"`.

## Inbox refusal

| Cause | Refusal text |
| - | - |
| `global.notification_email` is not the verified inbox of the account | `the document's notification email is not verified for this wallet` |

The text is the same if the account has a different verified inbox or none. A document without `global.notification_email` passes this check. See [notification\_email](https://docs.ana.fi/rules/document.md#notification_email).

## Account kind refusals

A `safe_module` account gets no account kind refusal. It accepts every action that the network accepts, `off_ramp` included.

An `erc20_allow` account can pull only ERC-20 tokens, and it pays the fees in an ERC-20 token. The engine refuses these documents for it:

| Cause | Refusal text |
| - | - |
| No `global.fees_method` | `the ERC20Allow leg needs global.fees_method` |
| The fee token is the native coin | `the ERC20Allow fee token <TOKEN> is the native coin` |
| A send of the native coin | `rule '<rule>' sends the native coin <TOKEN>` |
| A send whose token is not named, such as `trigger.value` without a range | `rule '<rule>' has a send whose token the document does not name` |
| A send of a token with no contract | `rule '<rule>' sends <TOKEN>, which has no contract on this chain` |
| An exchange input whose token is not named | `rule '<rule>' has an exchange input whose token the document does not name` |
| An exchange that sells or buys the native coin | `rule '<rule>' has the native coin <TOKEN> as its exchange <input \| output> token` |
| An exchange token with no contract | `rule '<rule>' has exchange <input \| output> token <TOKEN>, which has no contract on this chain` |
| An `off_ramp` | `rule '<rule>' has an off_ramp, which the ERC20Allow leg does not serve` |

The SDK checks the same causes on the client before it sends the stage. It also refuses an `exchange` when the adapter of the network runs no swaps. See [ERC20Allow in the SDK](https://docs.ana.fi/sdk/erc20-allow.md).

## Warnings

A warning does not stop the stage. The staged result lists the warnings in this order: for each rule, warnings 2, 3 and 4; then warning 1 in token order; then warning 6; then warning 5 in author order.

| # | Name | Text | Meaning and what to do |
| - | - | - | - |
| 1 | Shared token | `token '<TOKEN>' is spent by multiple rules (<rule>, <rule>); ordering may cause later rules to fail at runtime` | Two or more rules name a literal amount of the same token in a send, an exchange input or an `off_ramp`. If the balance is short, a later fire can fail. Check that the account holds enough for all of them. |
| 2 | Fixed times after expiry | `rule '<rule>': every at_fixed_time timestamp is after the rule's expiry — the rule can never fire` | Move `expiry` or the timestamps. |
| 3 | Fixed times before start | `rule '<rule>': every at_fixed_time timestamp is before the rule's start — the rule can never fire` | Move `start` or the timestamps. |
| 4 | No inbox | ``rule '<rule>': a `notify` fires but the document sets no `global.notification_email` — the notification is never delivered`` | The rule fires and its other actions run. Add the verified inbox, or remove the `notify`. |
| 5 | Unused variable | `variable '$<name>' is defined but no address or IBAN position uses it` | Remove the entry, or fix the `$name` that should use it. |
| 6 | Shared arrival overspend | `rules (<rule>, <rule>) can all fire on the same incoming <TOKEN or transfer>, and together they spend more than it brings in — one of their actions can fail unless the wallet already holds the difference` | See below. |

Warning 6 looks at enabled `incoming_tx` rules without `account`. It finds the rules that one transfer into the account can fire together. It warns when their known spends exceed every transfer in that case:

* A rule fires on a transfer when its `from` is absent or equal to the sender, and its `value` range is absent or holds the token and the amount.
* Known spends are `trigger.value`, `trigger.value * <N>%`, `trigger.value * <N>`, and a literal amount in the token of the transfer. Other expressions are left out, so the warning never states more than the rules take.
* It warns for shares that add up to more than 100%, for a 100% share next to a fixed amount, and for fixed amounts above what the upper bound of the range leaves after the shares.
* Under an open upper bound, shares of 100% or less plus a fixed amount do not warn. A large transfer covers them.
* It names the token, or `transfer` when the overspend occurs for a token that no rule names.

`outgoing_tx` rules and rules with `account` do not take part, because their transfer does not fund the account.

## Valid, but it does not run

A document can pass every check and still do nothing in some cases. Know these before you commit:

| Case | What happens |
| - | - |
| A transfer range fully below the minimum transfer of the network, such as `"0.000001..0.00001 WETH"` | The rule never fires. |
| A result below zero, such as `"1 USDC - 5 USDC"` | Every fire refuses the action. |
| A zero `exchange` input, such as `"0 USDC"` | Every fire refuses the action. |
| `trigger.value` mixed with a literal token, without a range | The action runs only when the transfer is in that token. See [trigger.value](https://docs.ana.fi/rules/values.md#triggervalue). |
| `"trigger.value * 100 USDC"` without a range | Every fire refuses the action. |
| `notify` without `global.notification_email` | Nothing is delivered. Warning 4. |
| `notify` with `channel: push` or `telegram` | An email is sent. |
| `agent_envelope` | Nothing is enforced and nothing runs. |
| `enabled: false`, or `start` at or after `expiry` | The rule never fires. |
| `at_fixed_time` instants in the past when the engine adopts the document | They never fire. |
| `calendar` with `day_of_month: [31]` | No fire in a month with fewer days. |
| `price_crossed` adopted while the price is already past the level | No fire until the price goes back and crosses again. |
| A payment that the `erc20_allow` permission does not cover: no allowance, a cap with no room, or the block switch on | The adapter reverts the payment. |
| An `exchange` on an `erc20_allow` account when the adapter permits no route for the pair | The adapter reverts the swap. |
| An `off_ramp` when the Safe is not linked to Monerium, or the off-ramp policy of the Safe refuses the order | Monerium does not pay. |
| An action when the account holds too little of the token | The payment fails. A `send_batch` pays no item. |

The status of each fire is on [Activity](https://docs.ana.fi/concepts/activity.md).


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