Result schema reference
A result schema describes the data a last step of a playbook hands back when it finishes. You write it once, on the step; the agent must return JSON in exactly that shape, the shape is checked, and the run carries the result as data that a program can read.
This page is the whole definition. It is written to be read by a person or by an AI that is writing a schema for you: every keyword, every type, every rule and the exact message you get when you break it.
In one minute
- A result schema is a small subset of JSON Schema. It uses seven keywords:
type,properties,required,items,enum,descriptionandadditionalProperties. Nothing else is allowed. - The top level is always an object with at least one property.
- Every field has a
type, written as one word. - Give every field a
description. The agent reads it to know what to write. - Problems are reported all at once, each with the path of the field it is about, when you validate or deploy a version. Saving never refuses a schema; it is checked when you validate.
{
"type": "object",
"required": ["summary", "risk"],
"properties": {
"summary": { "type": "string", "description": "Two sentences about the project." },
"risk": { "type": "string", "enum": ["low", "medium", "high"], "description": "Overall risk." }
}
}
What the result is for
By default a run answers in words: each last step finishes with a short summary. That is fine for a person reading it, and awkward for a program. A result schema turns the answer into data:
- The agent ends the step by returning JSON that matches the schema. If it does not match, the agent is told what is wrong and gets one more try; after that the run ends
failedwith the stop reasonresult_invalid. - The run's
resultis an object keyed by the id of the last step, for example{ "reply": { "priority": "high", "text": "hello" } }. See The result of a run. - The schema also instructs the agent. The field names, the types, the allowed values and above all the descriptions are what the agent sees when it decides what to write.
A schema goes only on an instruction step that is a last step (no line leaves it). A condition cannot return a result, and a step with a line out cannot either.
The keywords
Seven keywords are allowed. Anything else is refused (see Common mistakes).
| Keyword | On which types | Meaning | Example |
|---|---|---|---|
type |
every field | What kind of value this is. One word: object, array, string, number, integer or boolean. Never a list. Required on every field, including the top level. |
"type": "string" |
description |
every field | What the agent should put in this field, in plain words. Text, at most 500 characters. Optional, and always worth writing. | "description": "Two sentences about the project." |
properties |
object only |
The named fields the object holds, each a schema of its own. A name is 1 to 64 letters, digits, _ or -, and starts with a letter. The top level needs at least one. |
"properties": { "name": { "type": "string" } } |
required |
object only |
The names of the fields that must always be present. Each name must be in properties and listed once. A field not listed here may be left out. |
"required": ["name"] |
items |
array only, and an array must have it |
The schema every element of the list follows. | "items": { "type": "string" } |
enum |
string, number, integer only |
The complete list of values the field may take. Not empty, no repeats, and every value of the field's own type. | "enum": ["low", "medium", "high"] |
additionalProperties |
object only |
false: the agent may not add fields that are not in properties. true (the default): it may. A boolean only, never a schema. |
"additionalProperties": false |
Limits
| Limit | Value |
|---|---|
| Depth | At most 5 levels. The top level is level 1; each object or array inside it adds one. |
| Size | At most 8 KB of JSON for the whole schema. |
| Description | At most 500 characters per field. |
| Problems reported | At most 20 per step. Fix those and validate again to see the rest. |
The types
| Type | A value of this kind | Notes |
|---|---|---|
object |
Named fields: { "name": "Ana", "age": 31 } |
Describe the fields under properties. |
array |
A list: ["a", "b"] |
Must have items, the schema of each element. |
string |
Text: "hello" |
enum allowed. There is no date type: use a string and say in the description how to write it (for example "a date as YYYY-MM-DD"). |
number |
Any number: 3, 0.25, -12.5 |
enum allowed; values are numbers, fractions included. |
integer |
Whole numbers only: 3, 0, -12 |
enum allowed; values must be whole. 2.5 is not an integer. |
boolean |
true or false |
No enum: there is nothing to list. |
Numbers and whole numbers. number accepts any number, so 3 and 3.5 both pass. integer accepts only whole numbers, so 3 passes and 3.5 does not. Use integer for counts, ages and positions; use number for prices, scores and averages. The same holds inside enum: an integer field's enum must hold whole numbers, and a number field's enum may hold fractions.
There is no null. A field that may be missing is simply left out of required; the agent omits it. There is no date type either, as above.
The rules, with their messages
Every problem is reported as:
{
"code": "result_schema_invalid",
"node_id": "reply",
"field": "checks[].name",
"message": "Step \"Answer the ticket\": field 'checks[].name': the name is not allowed; use 1 to 64 letters, digits, _ or -, starting with a letter."
}
codeis alwaysresult_schema_invalid(the other problem about a schema isresult_schema_not_at_end, for a schema on a step that has a line out).node_idis the id of the step.fieldis the path of the field the problem is about: a dot between object fields,[]for the elements of an array, for exampleaddress.cityorchecks[].name. It is empty for the top level.messagestarts withStep "<title>":(the step's id when it has no title), then the problem. The problem itself starts withfield '<path>':or, at the top level,the result:.
The messages below are exact. Parts in the examples that depend on your schema (names, types, counts) are shown with the example's own values.
The schema as a whole
| Problem | Message |
|---|---|
| The schema is not an object (for example a list or text). | the result: the schema must be a JSON object. |
| It is more than 8 KB. | the result: the schema is too big (at most 8 KB). |
The top level has no type, or it is not object. |
the result: the top level must be an object, with "type": "object". |
The top level has no properties, or an empty one. |
the result: it needs at least one property under "properties". |
A keyword other than the seven, at the top (for example $schema). |
the result: '$schema' is not supported. Use only type, properties, required, items, enum, description and additionalProperties. |
Types
| Problem | Message |
|---|---|
A field has no type. |
field 'when': it needs a "type": object, array, string, number, integer or boolean. |
The type is not one of the six. |
field 'when': unknown type 'date'; use object, array, string, number, integer or boolean. |
The type is a list or an object. |
field 'name': the type must be one word, not a list or an object: object, array, string, number, integer or boolean. |
| Nested more than 5 levels. | field 'a.a.a.a.a': nested too deeply (at most 5 levels). |
The same, inside lists of objects ([] is a list's elements). |
field 'a[].b[].c': nested too deeply (at most 5 levels). |
Keywords
| Problem | Message |
|---|---|
| A keyword that is not one of the seven. | field 'when': 'format' is not supported. Use only type, properties, required, items, enum, description and additionalProperties. |
additionalProperties is not true or false. |
the result: additionalProperties must be true or false. |
description is not text. |
field 'a': the description must be text. |
description is over 500 characters. |
field 'a': the description is too long (at most 500 characters). |
Objects: properties and required
| Problem | Message |
|---|---|
properties is not an object of named fields. |
the result: properties must be an object of named fields. |
| A property is not a schema object. | field 'a': it must be a schema object, like {"type": "string"}. |
| A property name has a dot, a space or a bracket. | field 'user.name': the name is not allowed; use 1 to 64 letters, digits, _ or -, starting with a letter. |
| A property name starts with a digit. | field '1st': the name is not allowed; use 1 to 64 letters, digits, _ or -, starting with a letter. |
| A property name is longer than 64 characters. | field 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': the name is not allowed; use 1 to 64 letters, digits, _ or -, starting with a letter. |
properties on something that is not an object. |
field 't': only an object can have properties. |
required is not a list of names. |
the result: required must be a list of field names. |
required names a field that is not in properties. |
the result: required lists 'x', which is not among its properties. |
| The same, in an object inside another. | field 'o': required lists 'q', which is not among its properties. |
required lists a name twice. |
the result: required lists 'a' more than once. |
required on something that is not an object. |
field 't': only an object can have required. |
Arrays: items
| Problem | Message |
|---|---|
An array has no items. |
field 'tags': an array needs items, so the agent knows what each element is. |
items is not a schema object. |
field 'tags': items must be a schema object, like {"type": "string"}. |
items on something that is not an array. |
field 't': only an array can have items. |
enum
| Problem | Message |
|---|---|
enum on a boolean. |
field 'ok': enum is only for string, number or integer fields. |
enum on an object (or an array). |
field 'o': enum is only for string, number or integer fields. |
enum is empty. |
field 'r': the allowed values (enum) must be a non-empty list. |
enum is not a list. |
field 'r': the allowed values (enum) must be a non-empty list. |
enum repeats a value. |
field 'r': the allowed values (enum) must not repeat a value. |
A string enum holds something other than text. |
field 'risk': the allowed values must be text, like its type. |
A number enum holds something other than numbers. |
field 'n': the allowed values must be numbers, like its type. |
An integer enum holds a fraction. |
field 'n': the allowed values must be whole numbers, like its type. |
Several at once
Every field is checked, not just the first. A schema with three mistakes in three fields gives three problems, in one go, in order of field name:
[
{ "field": "a", "message": "Step \"Report\": field 'a': an array needs items, so the agent knows what each element is." },
{ "field": "b", "message": "Step \"Report\": field 'b': unknown type 'date'; use object, array, string, number, integer or boolean." },
{ "field": "c", "message": "Step \"Report\": field 'c': the allowed values must be text, like its type." }
]
Common mistakes
These are the mistakes people and AI tools make most, because they are valid JSON Schema that this subset deliberately leaves out. Each is refused with the message shown, and each has a plain fix.
format
Refused: field 'when': 'format' is not supported. Use only type, properties, required, items, enum, description and additionalProperties.
Fix: drop format; say it in the description.
nullable, or a type list
Refused: field 'name': the type must be one word, not a list or an object: object, array, string, number, integer or boolean. and field 'name': 'nullable' is not supported. Use only type, properties, required, items, enum, description and additionalProperties.
Fix: there is no null. Use one type, and leave the field out of required when it may be missing.
$ref, $defs
Refused: field 'v': '$ref' is not supported. Use only type, properties, required, items, enum, description and additionalProperties. followed by field 'v': it needs a "type": object, array, string, number, integer or boolean.
Fix: write the shape out where it is used. If the same shape is needed twice, write it twice.
oneOf, anyOf, allOf
Refused: field 'v': 'oneOf' is not supported. Use only type, properties, required, items, enum, description and additionalProperties. followed by field 'v': it needs a "type": object, array, string, number, integer or boolean.
Fix: pick one type for the field. If it truly can be either, use a string and describe how to write the number in its description, or use two fields.
minimum, maximum, pattern, minLength, maxItems and the like
Refused: field 'n': 'minimum' is not supported. Use only type, properties, required, items, enum, description and additionalProperties., and for pattern: field 'id': 'pattern' is not supported. Use only type, properties, required, items, enum, description and additionalProperties.
Fix: remove it and put the limit in the description ("a whole number from 1 to 5"). Use enum when the allowed values are a short list.
An array without items
Refused: field 'tags': an array needs items, so the agent knows what each element is.
Fix: say what each element is.
{ "tags": { "type": "array", "items": { "type": "string" }, "description": "Up to five short tags." } }
enum on a boolean
Refused: field 'ok': enum is only for string, number or integer fields.
Fix: remove the enum. A boolean is already true or false.
A wrong kind of value in an enum
Refused: field 'risk': the allowed values must be text, like its type.
Fix: make the values match the type. Either write text (["low", "medium", "high"]) or change the field to "type": "integer".
A date type, or any other type that is not one of the six
Refused: field 'when': unknown type 'date'; use object, array, string, number, integer or boolean.
Fix: use string and describe the date format.
A field name with a dot, space or bracket
Refused: field 'user.name': the name is not allowed; use 1 to 64 letters, digits, _ or -, starting with a letter.
Fix: use letters, digits, _ or -, starting with a letter: user_name. Or make user an object with a name field.
required naming a field that is not there
Refused: the result: required lists 'x', which is not among its properties.
Fix: add the field to properties, or take the name out of required.
Writing descriptions the agent follows
The agent decides what to write in each field from three things: the step's text, the field's name and type, and the field's description. A good description is the cheapest way to get the answer you want.
- Say what goes in the field, not what the field is. "The reply that was sent to the customer, in the customer's language" beats "reply".
- Give the format when a type is not enough. A string that holds a date: "The due date, written as YYYY-MM-DD." A number: "The price in euros, with two decimals."
- Name the choices and when to pick each. With an
enum, the values are the options and the description is the rule: "highif the customer cannot work at all, otherwiselow." - Say what to do when there is nothing to put. "Leave this out when there is no deadline." (and keep the field out of
required) - Say how long. "At most two sentences." Remember the limit is 500 characters for the description itself, not for the answer.
- Describe every field, including inside
items, so each element is as clear as the whole. - Keep field names meaningful and short.
customer_emailtells the agent more thane.
| Weak | Better |
|---|---|
"description": "status" |
"description": "Where the order is now: pending until it ships, then shipped." |
"description": "date" |
"description": "The ship date, written as YYYY-MM-DD. Leave out if it has not shipped." |
"description": "score" |
"description": "How well the answer matches the question, from 1 (not at all) to 5 (fully)." |
Worked examples
1. A flat result
Three fields, one of them limited to a list of values.
{
"type": "object",
"required": ["summary", "risk", "needs_review"],
"properties": {
"summary": { "type": "string", "description": "Two sentences about the project." },
"risk": {
"type": "string",
"enum": ["low", "medium", "high"],
"description": "Overall risk. high if anything blocks the release, otherwise medium or low."
},
"needs_review": { "type": "boolean", "description": "True when a person should look at it before it goes out." }
}
}
A result the agent might return:
2. A nested object
An object inside the result, with its own required fields, and no fields beyond the ones listed.
{
"type": "object",
"required": ["customer", "priority"],
"properties": {
"customer": {
"type": "object",
"description": "Who wrote the ticket.",
"required": ["name"],
"additionalProperties": false,
"properties": {
"name": { "type": "string", "description": "The customer's full name." },
"email": { "type": "string", "description": "Their email address. Leave out if the ticket does not give one." }
}
},
"priority": { "type": "integer", "description": "How urgent it is: 1 (can wait) to 5 (customer cannot work)." }
}
}
A result:
3. An array of objects with an enum
A list where every element is an object, and one field of each element is limited to a few values.
{
"type": "object",
"required": ["checks"],
"properties": {
"checks": {
"type": "array",
"description": "One entry for every check you ran.",
"items": {
"type": "object",
"required": ["name", "outcome"],
"properties": {
"name": { "type": "string", "description": "What was checked." },
"outcome": {
"type": "string",
"enum": ["passed", "failed", "skipped"],
"description": "passed if it met the requirement, failed if not, skipped if it could not be run."
},
"details": { "type": "string", "description": "What went wrong. Leave out when it passed." }
}
}
}
}
}
A result:
{
"checks": [
{ "name": "Login works", "outcome": "passed" },
{ "name": "Export to CSV", "outcome": "failed", "details": "The file is empty." }
]
}
The field paths in a problem for this schema read checks, checks[].name, checks[].outcome.
The definition itself
The rules above are the human-readable version of one JSON Schema (draft 2020-12) that describes what a result schema may look like. Every keyword in it has a description, so a tool or an AI can read it directly. Download it (result_schema.schema.json).
The meta-schema in full
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://protokol.cloud/schemas/workforce-result-schema.json",
"title": "Workforce result schema",
"description": "The shape of the data an end step of a playbook returns. Write it as a JSON Schema using only the keywords below: type, properties, required, items, enum, description and additionalProperties. Anything else (format, minimum, pattern, oneOf, $ref, nullable, a type written as a list) is refused. The top level is always an object with at least one property. At most 5 levels deep and 8 KB in size. Give every field a description: the agent reads it to know what to write.",
"examples": [
{
"type": "object",
"required": ["summary", "risk", "checks"],
"properties": {
"summary": {"type": "string", "description": "Two sentences about the project"},
"risk": {"type": "string", "enum": ["low", "medium", "high"], "description": "Overall risk"},
"checks": {
"type": "array",
"description": "Checks you made",
"items": {
"type": "object",
"required": ["name", "passed"],
"properties": {
"name": {"type": "string", "description": "What was checked"},
"passed": {"type": "boolean", "description": "Whether it passed"}
}
}
}
}
}
],
"$ref": "#/$defs/node",
"required": ["type", "properties"],
"properties": {
"type": {"const": "object"},
"properties": {"minProperties": 1}
},
"$defs": {
"node": {
"description": "One field of the result (or the whole result, at the top). It is a schema with a type and, as the type needs, properties, items or enum.",
"type": "object",
"additionalProperties": false,
"required": ["type"],
"properties": {
"type": {
"description": "What kind of value this is. One word, never a list: object (named fields, use properties), array (a list, use items), string (text), number (any number), integer (whole numbers only), boolean (true or false). There is no null and no date: use a string for a date, written the way the description says.",
"enum": ["object", "array", "string", "number", "integer", "boolean"]
},
"description": {
"description": "What the agent should put in this field, in plain words. Up to 500 characters. Always worth writing: it is the instruction the agent follows.",
"type": "string",
"maxLength": 500
},
"properties": {
"description": "Only on an object. The named fields it holds, each a schema of its own. A field name is 1 to 64 letters, digits, _ or -, and starts with a letter (no dots, spaces or brackets). The top level needs at least one.",
"type": "object",
"propertyNames": {"pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"},
"additionalProperties": {"$ref": "#/$defs/node"}
},
"required": {
"description": "Only on an object. The names of the fields that must always be present. Each name must appear in properties and be listed once. Fields not listed here may be left out.",
"type": "array",
"uniqueItems": true,
"items": {"type": "string"}
},
"items": {
"description": "Only on an array, and an array must have it. The schema every element of the list follows.",
"$ref": "#/$defs/node"
},
"enum": {
"description": "Only on a string, number or integer. The complete list of values the field may take. Not empty, no repeats, and every value of the field's own type (text for string, numbers for number, whole numbers for integer).",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {"type": ["string", "number"]}
},
"additionalProperties": {
"description": "Only meaningful on an object. false means the agent may not add fields that are not in properties; true (the default) allows them.",
"type": "boolean"
}
},
"allOf": [
{
"if": {"required": ["type"], "properties": {"type": {"const": "object"}}},
"else": {"not": {"anyOf": [{"required": ["properties"]}, {"required": ["required"]}]}}
},
{
"if": {"required": ["type"], "properties": {"type": {"const": "array"}}},
"then": {"required": ["items"]},
"else": {"not": {"required": ["items"]}}
},
{
"if": {"required": ["type"], "properties": {"type": {"enum": ["string", "number", "integer"]}}},
"else": {"not": {"required": ["enum"]}}
},
{
"if": {"required": ["type", "enum"], "properties": {"type": {"const": "string"}}},
"then": {"properties": {"enum": {"items": {"type": "string"}}}}
},
{
"if": {"required": ["type", "enum"], "properties": {"type": {"const": "number"}}},
"then": {"properties": {"enum": {"items": {"type": "number"}}}}
},
{
"if": {"required": ["type", "enum"], "properties": {"type": {"const": "integer"}}},
"then": {"properties": {"enum": {"items": {"type": "integer"}}}}
}
]
}
}
}
The meta-schema covers the structure. A few rules are checked by the server in plain words and are not expressed by it (a name in required that is not in properties, the 5 levels and 8 KB limits). Validate a version to run them all.
Where it is checked
| When | What happens |
|---|---|
| Saving a version | Nothing is refused about the schema, so you can save a draft. |
| Validating a version, and deploying it | Every problem is listed at once, as shown above. A deploy with a problem is refused. |
The command line, ptkl kortex playbook validate |
The same rules are checked offline, with the same messages. |
| The dashboard editor | The same rules are checked as you type. |
| A run | The agent's answer is checked against the schema. One retry, then result_invalid. |