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

# value node

> Build one typed value from literals, references, string templates and fallbacks, without running code.

A `value` builds one immutable named value from data the run already has, checks it against a
schema, and binds it. Nothing outside the run is contacted. Use it to reshape data, fill in a
default for a missing field, or build a string. When you need logic it can't express, such as
arithmetic, comparisons or loops, use a pure [`ts function`](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect)
through a [`call`](https://docs.canary.effectiveai.app/procedures/reference/nodes/call).

## Syntax

```yaml value id=normalize-approval theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
schema: normalized-approval
output: normalized_approval
value:
  approved: $approval.value.approved
  note: $approval.value.note ?? ""
  label: 'Release {{ $release.tag }}'
```

The fence takes no attributes after `id`.

## Fields

| Field | Type | Required | Default | What it does |
| - | - | - | - | - |
| `schema` | string | Yes | None | ID of a [schema](https://docs.canary.effectiveai.app/procedures/reference/nodes/schema.md) declared in the document. The built value must match it. |
| `output` | name | Yes | None | A new named value that holds the result, for later nodes to read as `$<name>`. |
| `value` | any | Yes | None | The value to build. Objects and arrays can nest. Every leaf is one of the forms below. |

### Leaf forms

| Form | Example | Result |
| - | - | - |
| Literal | `channels: [mail, email]` | The JSON value as written |
| Reference | `amountDue: $inputs.amount_due` | The referenced value, with its type kept |
| Template | `'Dear {{ $inputs.insured_name }},'` | Always a string |
| Fallback (`??`) | `copyTo: $inputs.agent_email ?? ""` | The first operand that is neither missing nor `null` |

There are no calls, comparisons, arithmetic or conditionals in a value node.

A template placeholder holds exactly one reference to a string, number or boolean. To keep a
value's original type, write the reference on its own, unquoted, not inside a template.

### Fallbacks

`??` is the only operator. It works only in an unquoted YAML scalar inside `value`. Each operand is
a reference or a JSON scalar: a JSON string such as `""`, a number, `true`, `false` or `null`.

* Operands are tried left to right. The first one that is neither missing nor `null` wins.
  `false`, `0` and `""` are values and are never skipped.
* Only the last member of a reference may be optional or nullable. Everything before it must be a
  required, non-null object, so `??` is not optional chaining.
* The chain must always produce a value the schema accepts. End it with a required reference or a
  non-null literal. A final `null` is allowed only when the schema field accepts `null`.
* Put at least one space on each side of `??`. A quoted scalar such as `'$x ?? fallback'` is a
  plain string.

## Example

Build the fields of a nonpayment notice. The agent's email is optional, so it falls back to an
empty string:

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

inputs:
  notice: { schema: notice-request }
outputs:
  letter: { schema: notice-letter }
---

# Notice letter

Build the fields of a nonpayment notice letter.

## Build letter

A missing agent email becomes an empty string, so later steps can rely on a
string.

```yaml value id=build-letter
schema: notice-letter
output: notice_letter
value:
  policyNumber: $inputs.notice.policyNumber
  subject: 'Notice of cancellation for policy {{ $inputs.notice.policyNumber }}'
  greeting: 'Dear {{ $inputs.notice.insuredName }},'
  amountDue: $inputs.notice.amountDue
  copyTo: $inputs.notice.agentEmail ?? ""
  channels: [mail, email]
```

```yaml complete id=done
output: letter
value: $notice_letter
```

## Resources

```yaml schema id=notice-request
type: object
additionalProperties: false
required: [policyNumber, insuredName, amountDue]
properties:
  policyNumber: { type: string }
  insuredName: { type: string }
  amountDue: { type: number }
  agentEmail: { type: [string, 'null'] }
```

```yaml schema id=notice-letter
type: object
additionalProperties: false
required: [policyNumber, subject, greeting, amountDue, copyTo, channels]
properties:
  policyNumber: { type: string }
  subject: { type: string }
  greeting: { type: string }
  amountDue: { type: number }
  copyTo: { type: string }
  channels:
    type: array
    items: { enum: [mail, email] }
```
````

With inputs `policyNumber: NW-100234`, `insuredName: Dana Reyes`, `amountDue: 412.5` and no
`agentEmail`, the procedure returns:

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "letter": {
    "policyNumber": "NW-100234",
    "subject": "Notice of cancellation for policy NW-100234",
    "greeting": "Dear Dana Reyes,",
    "amountDue": 412.5,
    "copyTo": "",
    "channels": ["mail", "email"]
  }
}
```

The named value is `notice_letter`, not `letter`, because a named value can't reuse the
procedure's output name.

## On retry and resume

* **No outside call.** A value node runs nothing outside the run, so there is nothing to retry.
* **Checked before it runs.** Validation proves that every reference exists, every type fits and
  every fallback chain is total before the procedure can be published.
* **Bound once.** The run builds the whole value, checks it against `schema`, and binds `output`
  in the same recorded step that moves the run on. A resumed run never sees a partly built value.
* **Bounded.** Building the value has fixed size, depth and compute limits. Hitting one fails the
  run; it is not a validation error.

## Common errors

| Code | Cause | Fix |
| - | - | - |
| `PROC-VALUE-001` | The body is missing `schema`, `output` or `value`, has another field, or uses a leaf form that isn't allowed. | Use exactly the three fields and the leaf forms above. |
| `PROC-DATA-005` | An optional reference is used without a fallback, for example `Optional reference $inputs.notice.agentEmail requires an allowed fallback.` | Add `?? <fallback>`, or make the field required in its schema. |
| `PROC-DATA-004` | A reference doesn't resolve. | Fix the reference, or produce the value earlier. |
| `PROC-SCHEMA-004` | The `schema` ID doesn't resolve. | Declare the schema, or fix its ID. |
| `PROC-SCHEMA-005` | The built value doesn't fit the schema, for example `value.copyTo references $inputs.notice.agentEmail, whose type is null \| string; notice-letter requires string.` | Change the value, add a fallback, or widen the schema. |
| `PROC-GRAPH-005` | The `output` name is already used, for example by the procedure's output. | Pick a name no other node, input or output uses. |
| `PROC-GRAPH-006` | A referenced value isn't produced on every path before this node. | Move the node after the one that produces the value. |

## See also

* [`complete` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/complete), which also builds a value but ends the run
* [`call` node](https://docs.canary.effectiveai.app/procedures/reference/nodes/call)
* [Function and effect declarations](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect.md)
* [`schema` declaration](https://docs.canary.effectiveai.app/procedures/reference/nodes/schema)


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