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

# schema node

> Declare a named JSON Schema contract for inputs, the output, code, tasks and waits.

A `schema` block declares one named data contract. It never runs. Inputs, the output, function
and effect inputs and results, task answers, `value` nodes and polling waits all name a schema by
its `id`, and Effective checks data against it at each of those points.

## Syntax

```yaml schema id=policy-ref theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
type: object
additionalProperties: false
required: [policyNumber]
properties:
  policyNumber: { type: string, minLength: 1 }
```

The `id` is the schema's name. The block takes no other attributes. The body is a JSON Schema
(Draft 2020-12) using the keywords listed below.

Schema blocks are declarations, so they can sit anywhere in the document, before or after the
steps that use them. Many procedures group them under a `## Resources` heading at the end; the
heading name is a convention, not a rule.

Inside a schema body, `$`-strings, `{{ }}` and `??` are plain text, not references or templates.
The one exception is the value of `x-effective-options`.

## Fields

Only these keywords are supported. Any other keyword is an error.

| Group | Keywords |
| - | - |
| Annotations | `$schema`, `title`, `description`, `default`, `x-effective-options` |
| Reuse | `$defs`, `$ref` |
| Any value | `type`, `enum`, `const` |
| Objects | `properties`, `required`, `additionalProperties`, `minProperties`, `maxProperties` |
| Arrays | `items`, `minItems`, `maxItems`, `uniqueItems` |
| Strings | `minLength`, `maxLength`, `format` |
| Numbers | `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf` |

`$schema`, if you give it, must be `https://json-schema.org/draft/2020-12/schema`.

Not supported: `pattern`, `oneOf`, `anyOf`, `allOf`, `not`, `if`/`then`/`else`, `$id`, remote
`$ref`, recursive schemas, and custom keywords.

### Formats

| `format` | Accepts |
| - | - |
| `date-time` | An RFC 3339 date and time with a time zone offset, such as `2026-12-31T05:00:00Z`. Leap seconds are refused |
| `decimal` | An exact amount as text, such as `-2647132.45`: an optional `-`, digits without leading zeros, and an optional fraction. No exponent, `+` or thousands separators |
| `uri` | A URI as defined by RFC 3986 |
| `http-url` | An absolute HTTP or HTTPS URL |

Use `decimal` for money: it keeps the amount exact instead of turning it into a floating-point
number.

### Reusing schemas

* `$ref: '#/$defs/<name>'` points to a definition under `$defs` in the same schema.
* `$ref: '#/schemas/<schema-id>'` points to another schema block in the same document. Nothing may
  follow the schema id in the pointer.
* A `$ref` object may also carry `$defs`, `$schema`, `title`, `description` or `default`, but not
  an assertion such as `type`, `required` or `minLength`.
* References can't form a cycle.

An object schema can't combine named `properties` with a schema-valued `additionalProperties`.
Use `additionalProperties: false`, or `true`, or drop the named properties.

### Defaults

`default` is a label for forms. A task form shows it as the starting answer. It never fills in or
changes procedure data: a required member stays required even when it has a default. Only an
input's `default` in the front matter fills in a missing run input. See
[Procedure document](https://docs.canary.effectiveai.app/procedures/reference/document.md#inputs).

### Choices on a task form

In the answer schema of a [`task`](https://docs.canary.effectiveai.app/procedures/reference/nodes/task), a `type: string` schema may
take its allowed values when the task is created, with `x-effective-options`:

```yaml schema id=product-pick theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
type: array
uniqueItems: true
items:
  type: string
  x-effective-options: $analysis.value.proposedProducts
```

The value is a reference to an array of strings produced earlier in the run, or one of these
built-in lists, quoted:

| List | Values |
| - | - |
| `@effective.us-states` | The 50 US states |
| `@effective.us-states-and-dc` | The 50 states and the District of Columbia |
| `@effective.us-jurisdictions` | The 51 above, plus AS, GU, MP, PR and VI |

Built-in values are two-letter codes, shown on the form by name.

* Right before the task is created, the list becomes an ordinary `enum`, and is stored with the
  task. The answer is checked against that stored list.
* A string schema renders as a single choice. An array with `uniqueItems: true` renders as a
  multiple choice.
* A list holds 1 to 1,000 unique, nonempty strings. Each value is at most 1,024 bytes, and the
  whole list at most 64 KiB.
* `x-effective-options` can't sit beside `enum` or `const`, and only works on a string schema.
* A schema with `x-effective-options` may be used only as a task answer schema. Using it for an
  input, output, code contract, `value` node or wait is an error.

## Example

The `insured` input reuses the `address` schema, and the task answer offers a state from a
built-in list. The names and email address are illustrative.

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

inputs:
  insured: { schema: insured }
outputs:
  confirmed: { schema: confirmed-address }
---

# Confirm the insured's mailing address

## Ask underwriting to confirm

```yaml task id=confirm-address
assignees:
  - user:underwriting.lead@northwind.example
title: Confirm the mailing address for {{ $inputs.insured.name }}
instructions: |
  Check the mailing address against the application and correct the state if needed.
result:
  schema: address-review
output: review
```

```yaml complete id=confirmed
output: confirmed
value:
  name: $inputs.insured.name
  state: $review.value.state
  confirmed: $review.value.confirmed
```

## Resources

```yaml schema id=address
type: object
additionalProperties: false
required: [line1, city, state, postalCode]
properties:
  line1: { type: string, minLength: 1 }
  city: { type: string, minLength: 1 }
  state: { type: string, minLength: 2, maxLength: 2 }
  postalCode: { type: string, minLength: 5, maxLength: 10 }
```

```yaml schema id=insured
type: object
additionalProperties: false
required: [name, mailingAddress]
properties:
  name: { type: string, minLength: 1 }
  mailingAddress: { $ref: '#/schemas/address' }
```

```yaml schema id=address-review
type: object
additionalProperties: false
required: [confirmed, state]
properties:
  confirmed:
    type: boolean
    default: true
  state:
    type: string
    x-effective-options: '@effective.us-states-and-dc'
```

```yaml schema id=confirmed-address
type: object
additionalProperties: false
required: [name, state, confirmed]
properties:
  name: { type: string }
  state: { type: string }
  confirmed: { type: boolean }
```
````

## When data is checked

* Run inputs, before the first step runs.
* A function's or effect's input before each call, and its result before it is recorded.
* A task's answer, before it is bound.
* A `value` node's result, before it is bound.
* The output, before the run completes.

A value that fails its schema binds nothing: no partial object ever becomes visible. String
lengths count Unicode characters, `uniqueItems` compares values as JSON, and `multipleOf` uses
exact decimal arithmetic.

## On retry and resume

Schemas are part of the published version and never change with it. A run checks data against the
schemas of the version it runs. The choices a task offered through `x-effective-options` are
stored with the task, so the answer is checked against the list the person saw.

## Common errors

| Code | Cause | Fix |
| - | - | - |
| `PROC-SCHEMA-001` | The schema block has attributes after `id`, or its body isn't a valid schema | Keep only `id=` on the block |
| `PROC-SCHEMA-002` | An unsupported keyword, format or `$schema` value, such as `oneOf` or `pattern` | Use only the keywords and formats above |
| `PROC-SCHEMA-003` | A `$ref` that doesn't resolve, points outside the document, or forms a cycle | Point to `#/$defs/<name>` or `#/schemas/<schema-id>` |
| `PROC-SCHEMA-004` | A step names a schema id that doesn't exist, or `x-effective-options` is used outside a task answer schema | Check the id; keep option lists in task answer schemas |
| `PROC-SCHEMA-005` | A value doesn't match its schema, such as an input referenced where a narrower schema is required | Make the producing schema match the consumer's |

## See also

* [Procedure document](https://docs.canary.effectiveai.app/procedures/reference/document.md): inputs and the output.
* [`task`](https://docs.canary.effectiveai.app/procedures/reference/nodes/task): answer schemas and prefilled answers.
* [Functions and effects](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect.md): input and result
  schemas for code.
* [`wait`](https://docs.canary.effectiveai.app/procedures/reference/nodes/wait): matched schemas for polling waits.
* [`secret`](https://docs.canary.effectiveai.app/procedures/reference/nodes/secret): the other declaration that holds no data.


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