Skip to main content
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

schema id=policy-ref
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. $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

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.

Choices on a task form

In the answer schema of a task, a type: string schema may take its allowed values when the task is created, with x-effective-options:
schema id=product-pick
The value is a reference to an array of strings produced earlier in the run, or one of these built-in lists, quoted: 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.
confirm-insured-address.procedure.md

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

See also