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

# Procedure document

> The file format of a procedure, from front matter and headings to run order, references, templates and run statuses.

A procedure is one Markdown file. YAML front matter declares its inputs and output, headings group
the steps, prose explains them, and fenced blocks called nodes say what runs. This page describes
the format that every node page builds on.

## Example

This illustrative procedure drafts the text of a nonpayment notice. It has a run title, an input
with a default, an input with its own schema, a template, and the run's own URL in its result.

````markdown nonpayment-notice.procedure.md theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
---
kind: procedure@v0
id: nonpayment-notice
run:
  title: 'Nonpayment notice: {{ $inputs.policy_number }}'

inputs:
  policy_number: { type: string }
  amount_due: { schema: amount }
  grace_days:
    type: integer
    default: 10
outputs:
  notice: { schema: notice }
---

# Nonpayment notice

Prepare the text of a nonpayment notice for a policy.

## Draft the notice

Build the notice text from the inputs. The `{{ }}` placeholders insert each value as text.

```yaml value id=draft-notice
schema: notice-draft
output: draft
value:
  subject: 'Payment due on policy {{ $inputs.policy_number }}'
  body: 'Pay {{ $inputs.amount_due }} within {{ $inputs.grace_days }} days to keep your coverage.'
```

## Return the notice

```yaml complete id=notice-ready
output: notice
value:
  policyNumber: $inputs.policy_number
  graceDays: $inputs.grace_days
  subject: $draft.subject
  body: $draft.body
  runUrl: $run.url
```

## Resources

```yaml schema id=amount
type: string
format: decimal
```

```yaml schema id=notice-draft
type: object
additionalProperties: false
required: [subject, body]
properties:
  subject: { type: string }
  body: { type: string }
```

```yaml schema id=notice
type: object
additionalProperties: false
required: [policyNumber, graceDays, subject, body, runUrl]
properties:
  policyNumber: { type: string }
  graceDays: { type: integer }
  subject: { type: string }
  body: { type: string }
  runUrl: { type: string }
```
````

## File name and layout

Name the file `<id>.procedure.md`, such as `nonpayment-notice.procedure.md`. The suffix is the
convention tools look for; the procedure's identity comes from `id`, not the file name.

The file has this order, with nothing in between:

1. Front matter, starting on the first line with `---` and ending with a line that is exactly
   `---`.
2. At least one blank line.
3. One `#` heading: the procedure's title. It is the only title; front matter doesn't repeat it.
4. `##` to `######` headings, prose and nodes.

The file must be UTF-8, with no byte order mark.

## Front matter

| Key | Type | Required | What it does |
| - | - | - | - |
| `kind` | string | Yes | The language version. Always `procedure@v0` |
| `id` | string | Yes | The procedure's stable identity. Publishing, runs, triggers and `invoke` all use it |
| `inputs` | mapping | Yes | The run's inputs, by name. May be empty: `inputs: {}` |
| `outputs` | mapping | Yes | Exactly one named output |
| `run.title` | string | No | The title each run shows. Defaults to the `#` heading |

Effective ignores other top-level keys. Don't write a `version`: Effective numbers versions when
you publish.

### Names

* **Procedure id:** one or more segments separated by dots. Each segment starts with a lowercase
  letter and holds lowercase letters, digits and hyphens, such as `nonpayment-notice` or
  `billing.nonpayment-notice`. At most 256 characters.
* **Input, output and value names:** a lowercase letter followed by lowercase letters, digits and
  underscores, such as `policy_number`. `inputs`, `run` and `project` are reserved.

### Inputs

Each input has exactly one of `type` or `schema`, and may have a `default`:

```yaml theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
inputs:
  policy_number: { type: string }
  amount_due: { schema: amount }
  grace_days:
    type: integer
    default: 10
```

* `type` is one of `string`, `number`, `integer`, `boolean`, `object`, `array` or `null`.
* `schema` names a [`schema`](https://docs.canary.effectiveai.app/procedures/reference/nodes/schema) block in the same document. Use
  it for anything more specific than a bare type, such as a `date-time` or `decimal` string.
* An input without a `default` is required when a run starts. A missing input with a `default`
  gets a copy of that value. The default must match the input's type or schema.
* An explicit `null` is a value, not a missing input.

### Output

`outputs` names one output with one `schema`:

```yaml theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
outputs:
  notice: { schema: notice }
```

Every path through the procedure that succeeds must end at a
[`complete`](https://docs.canary.effectiveai.app/procedures/reference/nodes/complete) node that returns this output. A run that fails
or is cancelled returns no output.

### Run title

`run.title` may use `{{ }}` templates, but only over `$inputs`. It is fixed when the run starts and
never affects what the run does.

## Headings

`##` to `######` headings form a tree. Each heading owns the text and nodes up to the next
heading of the same or a higher level. Don't skip levels: a `####` must sit under a `###`.

Every heading gets an address. [`choice`](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice) targets headings by
address, and Markdown links such as `[Deny](#deny-refund)` can use it. By
default the address is derived from the heading text: lowercase it, replace each run of characters
other than `a`–`z` and `0`–`9` with `-`, trim leading and trailing `-`, and prefix `#`. So
`## Deny the refund` becomes `#deny-the-refund`.

To keep an address stable when you reword a heading, end the heading with a custom id:

```markdown theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
## Deny the refund {#deny-refund}
```

The custom id uses lowercase letters and digits separated by single hyphens. It must be the last
thing on the heading line, after one space. Addresses, derived or custom, must be unique across
the document, and every local link must point to an existing one. The `#` title heading takes no
custom id.

Headings don't run. They don't create scopes, hide values or guard entry.

## Nodes

A node is a fenced code block whose first line names a language, a role and an id:

```text theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
yaml <role> id=<fence-id> [attribute=value ...]
```

* The fence uses backticks, starts in the first column, and isn't inside a list, quote or HTML.
  A fenced block with only a language, such as plain `yaml`, is ordinary example code.
* `id=` comes first. Ids use lowercase letters, digits and hyphens, and are unique across the
  document, declarations included.
* Every node sits under a `##` or deeper heading. A node before the first `##` is an error.
* Prose and ordinary Markdown never run.

[`value`](https://docs.canary.effectiveai.app/procedures/reference/nodes/value), [`call`](https://docs.canary.effectiveai.app/procedures/reference/nodes/call) and the
other runtime nodes are `yaml`. [Functions and effects](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect.md)
are `ts`.

## Run order

Runtime nodes run in document order:

1. Take the top-level `##` sections in order.
2. Within a section, run the nodes it owns directly, in order.
3. Then do the same for each of its child sections, in order.
4. Then continue with the next section.

The first runtime node in that order is where every run starts. A branching node such as
[`choice`](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice) claims the heading sections it targets as its
branches; a branch starts at the first node its section owns, or else at the first node in its
first child section that has one.

### Declarations can go anywhere

[`schema`](https://docs.canary.effectiveai.app/procedures/reference/nodes/schema), [`secret`](https://docs.canary.effectiveai.app/procedures/reference/nodes/secret),
[`retry`](https://docs.canary.effectiveai.app/procedures/reference/nodes/retry) and the code declarations,
[`ts function` and `ts effect`](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect), are
declarations. They never run and take no place in the run order. Effective reads them all before
anything else, so a step can use a declaration that appears later in the file.

Put declarations beside their first use, or group them under a heading such as `## Resources`.
The heading name is a convention, not a scope: moving a declaration doesn't change what the
procedure does. It does change the source, so publishing the move creates a new version.

## References

A reference reads a value. It starts with `$` and follows required members with dots.

| Reference | Reads |
| - | - |
| `$inputs.policy_number` | A run input |
| `$draft.subject` | A member of a value an earlier step bound with `output: draft` |
| `$review.value.approved` | A member of a [`task`](https://docs.canary.effectiveai.app/procedures/reference/nodes/task) or [`agent`](https://docs.canary.effectiveai.app/procedures/reference/nodes/agent) answer. Their answers sit under `.value` |
| `$run.id`, `$run.url` | The run's id and its page in Effective |
| `$run.principal.type`, `$run.principal.id` | Who the run runs as. `type` is `product-user`, `service` or `unknown` |
| `$run.cause.kind` | What started the run, such as `direct`, `trigger` or `procedure-invocation` |

* Every member in the path must be required by its schema. There are no array indexes, wildcards,
  arithmetic or function calls in a reference. Use a [`value`](https://docs.canary.effectiveai.app/procedures/reference/nodes/value)
  node, or a pure `ts function` through [`call`](https://docs.canary.effectiveai.app/procedures/reference/nodes/call), to compute
  anything more.
* A value can be read only by steps that come after the step that binds it on every path.
* Values are immutable. Each step receives its own copy.
* `$run.userId` still works but is deprecated. Use `$run.principal.id`.

A task or agent answer is wrapped. Read `$review.value.approved`, not `$review.result.approved`.
Other nodes, such as `value`, `call` and `wait`, bind their result directly.

### References in YAML

In a node's data fields, an unquoted value that is exactly a reference is a reference. Quote it to
get the literal text:

```yaml theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
policyNumber: $inputs.policy_number # the input's value
label: '$inputs.policy_number' # the literal text "$inputs.policy_number"
```

A reference keeps the value's type: a number stays a number.

## Templates

A template inserts values into a string with `{{ }}`:

```yaml theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
title: 'Approve the refund for {{ $inputs.policy_number }}?'
```

Templates work in:

* `run.title`, over `$inputs` only;
* the `title` and `instructions` of [`task`](https://docs.canary.effectiveai.app/procedures/reference/nodes/task) and
  [`agent`](https://docs.canary.effectiveai.app/procedures/reference/nodes/agent) nodes; and
* any string inside the `value` of a [`value`](https://docs.canary.effectiveai.app/procedures/reference/nodes/value) node.

Other fields and prose don't use templates.

* Each placeholder holds exactly one reference, with optional spaces inside the braces. No `??`
  and no expressions.
* The value must be a string, number or boolean. Objects, arrays and `null` are errors.
* A template always produces a string, even when it is only one placeholder. To keep a value's
  type, use a plain reference instead.
* Inserted text is never read as a template again.
* To write literal `{{`, escape it as `\{{`. In a double-quoted YAML string, write `\\{{`.

Text a template inserts may come from outside your organization, such as an email subject. It is
shown as text, and agents receive it as data, not as instructions.

## YAML rules

Front matter and node bodies use a strict form of YAML:

* No anchors, aliases, merge keys, tags, directives or multiple documents.
* No duplicate keys.
* Only lowercase `true`, `false` and `null`, and plain JSON numbers, are read as non-strings. Values
  such as `yes`, `2026-11-01`, `0x1F` or `+1` are strings, or errors where a number is required.
* Whole numbers must be between -9007199254740991 and 9007199254740991.
* Comments are allowed and have no meaning.

## Limits

| What | Limit |
| - | - |
| Whole file | 1 MiB |
| Front matter | 64 KiB |
| One node | 64 KiB |
| One string | 64 KiB |
| One YAML value | 1 MiB |
| YAML nesting depth | 32 |
| YAML items in the file | 10,000 |
| Runtime nodes | 4,096 |

A file over a limit is refused, never cut short.

## Run statuses

When you [read a run](https://docs.canary.effectiveai.app/guides/procedures.md#read-the-result), its `status` is one of:

| Status | Meaning |
| - | - |
| `starting` | The run has been accepted and is starting |
| `running` | The run is working or waiting, for example on a task or a `wait` |
| `completed` | The run reached a `complete` node and has an `output` |
| `failed` | The run stopped with a `failure`, which has a `code` and a `message` |
| `cancelled` | Someone cancelled the run |
| `terminated` or `timed_out` | The run ended without completing |
| `unavailable` | The run's state couldn't be read |

`completed`, `failed`, `cancelled`, `terminated` and `timed_out` are final. New statuses may be
added; treat one you don't know as not final. A run also has `paused`, which is `true` while it is
paused.

A failed run's `failure.code` says why, such as `invalid_input`, `schema_mismatch`,
`operation_failed` or `poll_timeout`. New codes may be added.

## Common errors

| Code | Cause |
| - | - |
| `PROC-DOC-001` | The file isn't valid UTF-8, has a byte order mark or a NUL character, or is over a size limit |
| `PROC-DOC-002` | The front matter or the `#` title is missing or out of place |
| `PROC-DOC-003` | A known front matter key has an invalid value |
| `PROC-DOC-004` | The procedure `id` is invalid |
| `PROC-DOC-005` | An input declaration or its `default` is invalid |
| `PROC-DOC-006` | `outputs` doesn't have exactly one output, or its `schema` doesn't exist |
| `PROC-BLOCK-001` | Headings skip a level or are otherwise invalid |
| `PROC-BLOCK-002` | A heading address is empty, malformed or used twice |
| `PROC-BLOCK-003` | A node isn't under a `##` or deeper heading |
| `PROC-BLOCK-004` | A local Markdown link points to an address that doesn't exist |
| `PROC-FENCE-002` | A node's first line is malformed, for example it uses tabs |
| `PROC-FENCE-003` | A node's `id=` is missing, not first, or invalid |
| `PROC-FENCE-004` | Two nodes share an id, or a node repeats an attribute |
| `PROC-FENCE-005` | The language and role aren't a known node, such as `yaml cal` |
| `PROC-DATA-002` | YAML breaks the rules above |
| `PROC-DATA-003` | A reference or template is malformed, or used where it isn't allowed |
| `PROC-DATA-004` | A reference names an input, value or member that doesn't exist, or reads `.result` on a task or agent answer |
| `PROC-DATA-006` | The procedure reads the deprecated `$run.userId` |

## See also

* [Procedures overview](https://docs.canary.effectiveai.app/procedures/overview.md): what procedures are for.
* [`schema`](https://docs.canary.effectiveai.app/procedures/reference/nodes/schema): the contracts inputs and outputs name.
* [`complete`](https://docs.canary.effectiveai.app/procedures/reference/nodes/complete): return the output.
* [`choice`](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice): branch to heading sections.
* [Runs and versions](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md): what a run records and how
  versions work.


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