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
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$defsin 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
$refobject may also carry$defs,$schema,title,descriptionordefault, but not an assertion such astype,requiredorminLength. - References can’t form a cycle.
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 atask, a type: string schema may
take its allowed values when the task is created, with x-effective-options:
schema id=product-pick
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: truerenders 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-optionscan’t sit besideenumorconst, and only works on a string schema.- A schema with
x-effective-optionsmay be used only as a task answer schema. Using it for an input, output, code contract,valuenode or wait is an error.
Example
Theinsured 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
valuenode’s result, before it is bound. - The output, before the run completes.
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 throughx-effective-options are
stored with the task, so the answer is checked against the list the person saw.
Common errors
See also
- Procedure document: inputs and the output.
task: answer schemas and prefilled answers.- Functions and effects: input and result schemas for code.
wait: matched schemas for polling waits.secret: the other declaration that holds no data.