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

# complete node

> End the run successfully and return the procedure's declared output.

A `complete` ends the run successfully and sets the procedure's one declared output. Every path
that succeeds must end at a `complete`. To build an intermediate value and keep going, use
[`value`](https://docs.canary.effectiveai.app/procedures/reference/nodes/value) instead.

## Syntax

```yaml complete id=release-rejected theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
output: release
value:
  tag: $release_metadata.nextTag
  approved: false
  approvalNote: $approval.value.note
  deployStatus: cancelled
```

The fence takes no attributes after `id`.

## Fields

| Field | Type | Required | Default | What it does |
| - | - | - | - | - |
| `output` | name | No | The procedure's one output | The output name declared under `outputs` in the front matter. When present, it must match that name. |
| `value` | any | Yes | None | The output value. Objects and arrays can nest. Each leaf is a JSON literal or a required `$` reference. The whole value must match the output's schema. |

`complete` is stricter than `value`: templates, optional references and `??` fallbacks are not
allowed. Build those in a [`value`](https://docs.canary.effectiveai.app/procedures/reference/nodes/value) node first and reference
the result.

## Example

Two branches of a [`choice`](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice) each end with their own
`complete`. Both build the same declared output from the values available on that branch:

````markdown cancellation-review.procedure.md theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
---
kind: procedure@v0
id: cancellation-review

inputs:
  policy_number: { type: string }
  balance_due: { type: number }
outputs:
  decision: { schema: cancellation-decision }
---

# Cancellation review

Decide whether a policy with an unpaid balance should be cancelled.

## Check balance

```yaml call id=check-balance
function: '@local.classify-balance'
input:
  balance: $inputs.balance_due
output: balance
```

```yaml choice id=route-balance
on: $balance.status
cases:
  owed: '#cancel'
  settled: '#keep'
```

### Cancel {#cancel}

```yaml complete id=cancelled
output: decision
value:
  policyNumber: $inputs.policy_number
  action: cancel
  balanceDue: $inputs.balance_due
```

### Keep {#keep}

```yaml complete id=kept
output: decision
value:
  policyNumber: $inputs.policy_number
  action: keep
  balanceDue: 0
```

## Resources

```yaml schema id=balance-input
type: object
additionalProperties: false
required: [balance]
properties:
  balance: { type: number }
```

```yaml schema id=balance-status
type: object
additionalProperties: false
required: [status]
properties:
  status: { enum: [owed, settled] }
```

```yaml schema id=cancellation-decision
type: object
additionalProperties: false
required: [policyNumber, action, balanceDue]
properties:
  policyNumber: { type: string }
  action: { enum: [cancel, keep] }
  balanceDue: { type: number }
```

```ts function id=classify-balance input=balance-input result=balance-status
({ balance }) => ({ status: balance > 0 ? 'owed' : 'settled' });
```
````

With `policy_number: NW-100234` and `balance_due: 412.5`, the run ends at `cancelled` and returns:

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{ "decision": { "policyNumber": "NW-100234", "action": "cancel", "balanceDue": 412.5 } }
```

To return a value you already built, reference it whole: `value: $notice_letter`.

## On retry and resume

* **Nothing after it.** A `complete` has no next step. A node placed after it on the same path is
  unreachable and fails validation.
* **No falling off the end.** Every path that succeeds reaches exactly one `complete`. Reaching the
  end of the document without one is invalid.
* **All or nothing.** The run resolves the whole value and checks it against the output schema
  before the run ends. No partial output is ever visible.
* **Fixed output.** The output can't be silently rewritten. A different value needs different data
  going in, or a new published version.
* **Failure has no output.** A run that is cancelled or fails ends with its own outcome and no
  successful output.

## Common errors

| Code | Cause | Fix |
| - | - | - |
| `PROC-COMPLETE-001` | The body has a field other than `output` and `value`, or is missing `value`. | Use only `output` and `value`. |
| `PROC-COMPLETE-002` | `output` names something other than the declared output, for example a named value. | Use the name under `outputs` in the front matter, or leave `output` out. |
| `PROC-SCHEMA-005` | The value doesn't fit the output schema, for example `value.balanceDue is required by cancellation-decision.` | Add the missing field or fix its type. |
| `PROC-DATA-003` to `PROC-DATA-005` | A reference is malformed, unavailable or optional. | Fix the reference. Build optional values in a `value` node with a fallback. |
| `PROC-GRAPH-003` | The `complete` can't be reached. | Route a path to it, or remove it. |
| `PROC-GRAPH-004` | The `complete` is followed by another step. | Move the step before it, or onto another branch. |
| `PROC-REGION-002` | Inside a choice branch, a step after the `complete` can't be reached, for example `Body #keep fence after-keep is unreachable or has invalid incoming degree.` | Move the step before the `complete`. |
| `PROC-GRAPH-006` | A referenced value isn't produced on every path before this node. | Reference only values produced on this branch. |

## See also

* [`value` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/value)
* [`choice` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice)
* [`invoke` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/invoke), which returns a child's `complete` output to its parent
* [Run procedures from your system](https://docs.canary.effectiveai.app/guides/procedures.md), which shows how to read a run's output


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