WorkStream Schemas
A schema names the shape of one kind of data. You publish it once in your workspace. Each step of a WorkStream then says which schema it takes and which it gives.
Schema, Record and Form
The named, versioned shape of one kind of data, such as a statement or a pay export. It is one JSON Schema 2020-12 document.
One instance of a schema. One statement for one account and one period.
What a person fills in. A form is not a schema. What the person enters becomes a record.
How a Schema Is Named
A schema's $id names it and carries its version:
<area>/<kind>[/<stage>]/<version> investment/statement/recognised/1.1 investment/ties/1.5
The Rules for an Id
The name has two or three parts. Each part starts with a letter or a digit, then letters, digits, _ or -.
The version is one to three whole numbers joined by dots, with no leading zeros: 1, 1.0, 1.10. Versions sort by number, so 1.10 comes after 1.9.
The whole id is at most 255 characters.
A version never changes. A changed shape is a new version with a new $id.
The Platform Refuses a Document Unless All of These Hold
"$schema" is https://json-schema.org/draft/2020-12/schema.
"$id" fits the pattern above.
The top level is "type": "object", because a record is an object.
Every $ref points inside the same document (for example #/$defs/row) and finds something there.
And All of These as Well
It is valid against the JSON Schema 2020-12 meta-schema.
No number has a decimal point. Write a limit on an amount as a pattern on its text.
Every pattern is a regular expression the platform can read, and no text holds a NUL character.
It is nested no more than 64 levels deep.
A refusal lists every problem, each with its place in the document as a JSON Pointer. It never repeats the value it refused.
Take the Hash Yourself
A schema's sha256 is the SHA-256 of the document alone, written as canonical JSON: keys sorted, no spaces (separators , and :), non-ASCII characters kept as they are, encoded as UTF-8. The hints described below are not part of it. You can take the hash yourself before you publish, and the platform gives the same one.
import hashlib, json
def schema_sha256(schema: dict) -> str:
text = json.dumps(schema, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
return hashlib.sha256(text.encode("utf-8")).hexdigest()Publish a Schema
schema is required. The other three are optional hints on how to read a record of this schema. They are kept beside the document, never inside it.
POST /api/v1/workstreams/schemas
Authorization: Bearer sk_...
{
"schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "sample/statement/recognised/1.0", "type": "object", ... },
"rows_at": "/rows",
"row_key": ["line_no"],
"proof_at": "/proof"
}Optional, Kept Beside the Document
Where a record's list of rows is, as a JSON Pointer.
The fields that make a row's key, a list of distinct names.
Where a record's proof list is, as a JSON Pointer.
What Publishing Answers
Published. The body is the entry: id, name, version, sha256, title, rows_at, row_key, proof_at, published_at and published_by.
The same $id already holds the same content and hints. Nothing changes, so publishing is safe to repeat.
When Publishing Is Refused
The $id holds other content or other hints. The body carries id and sha256_held. Publish a new version instead.
The body carries problems, a list of {path, problem}.
Publishing needs a signed-in workspace.
A refusal has the same body as every other refusal on the API: error, message, and the particulars under detail. Branch on detail.code. See Error handling. You publish into your own workspace only. When you read, you see your workspace's schemas, then your organisation's, then the platform's. Where one id is held at more than one of these, the narrowest wins.
Read a Schema Back
The list answers items and a pagination object (total, limit, offset, has_more). limit is 50 by default and at most 200. See Pagination. Both single reads answer the entry plus schema, the document exactly as published, or 404 schema_not_found.
# List: name matches the start of the name; latest_only keeps the highest version of each GET /api/v1/workstreams/schemas?name=investment/&latest_only=true&limit=50&offset=0 # One schema by its id GET /api/v1/workstreams/schemas/by-id?id=investment/launch/year_end/1.0 # One schema by its hash (64 lower-case hex characters) GET /api/v1/workstreams/schemas/6efc3198fb3c346d76dc5a103e7e3a7810c3323730146b17452ef9e5d9a31bfe
Every Kind of Step Can Carry Two Optional Fields
A map from a port name to {schema, sha256, many}. schema and sha256 are required.
A map from a port name to {from, schema, sha256, many}. from is required; schema and sha256 are optional.
many: true means a list of records. Left out, it means one record.
A port name is 1 to 100 letters, digits, _ or -. It has no dot, so a from path stays unambiguous.
A step without them works, and is stored, exactly as before.
Where the Value Comes From, in One of Three Forms
What an earlier step gives under that port name.
A value given when the cycle starts.
The platform does not read from yet, so this form has no fixed spelling today; it is stored as written.
When You Save a WorkStream, It Checks the Shape of These Fields Only
Every port name fits the rule above.
Every gives entry has a schema written as text and a sha256 of 64 lower-case hex characters.
Every takes entry has a from written as text, and any sha256 it has is 64 lower-case hex characters.
No entry carries a field other than the four named here.
Gives and takes are stored and read back. They are not yet enforced. Today the platform does not check that a schema id is published, or that its hash matches the store; that a from names a real step, port or input, or a step this step depends on; that what one step takes is the schema and hash the other step gives; or that a record a step hands on in a cycle fits its schema. Nothing is checked when a step finishes. Until it is, check these yourself: read each schema back by its id, compare its sha256, and validate each record against the document in your own tool before you hand it on.
One Schema
One schema and two steps, taken from a WorkStream on the development platform. The schema is the year end a firm declares when it starts a cycle. Its sha256, by the rule above, is 6efc3198fb3c346d76dc5a103e7e3a7810c3323730146b17452ef9e5d9a31bfe.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "investment/launch/year_end/1.0",
"title": "The year end declared at launch",
"description": "The last day of the year under build, as the firm declares it at launch, written YYYY-MM-DD, a real day. Required: a run with no year end stops at its first step and says so; nothing else (no paper, no workbook) sets it. Written as the launch record's own key, \"year_end\", because a schema is a record (an object); the input itself carries the bare value. Other keys of the launch record are allowed and are not read here.",
"type": "object",
"required": ["year_end"],
"properties": {
"year_end": {
"type": "string",
"format": "date",
"pattern": "^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"
}
},
"additionalProperties": true
}Two Steps
The first step takes the year end from the cycle's inputs against that schema and gives the year it works out. The second step takes that year from the first. The year port names another published schema, investment/year/1.0, by its id and hash. On the development platform the second step also takes the papers and other inputs given at the start; they are left out here.
"steps": [
{
"id": "year",
"name": "The year",
"type": "tool_call",
"tool_name": "year_end",
"tool_version": 1,
"depends_on": [],
"takes": {
"year_end": {
"from": "inputs.year_end",
"schema": "investment/launch/year_end/1.0",
"sha256": "6efc3198fb3c346d76dc5a103e7e3a7810c3323730146b17452ef9e5d9a31bfe"
}
},
"gives": {
"year": {
"schema": "investment/year/1.0",
"sha256": "9a9df19d57f309a3652f26d3b7c131a459cd64d314db3fb09f1e98137cb5223f"
}
}
},
{
"id": "papers_set",
"name": "Gather the papers",
"type": "tool_call",
"tool_name": "ledger_build_family_document_set",
"depends_on": ["year"],
"takes": {
"year": {
"from": "steps.year.year",
"schema": "investment/year/1.0",
"sha256": "9a9df19d57f309a3652f26d3b7c131a459cd64d314db3fb09f1e98137cb5223f"
}
},
"gives": {
"documents": {
"schema": "investment/paper_set/read/1.0",
"sha256": "b0e967d7dc5e5b653419a0324f7b98b27aecf2c4aff3687b28fb6a2400c305a9",
"many": true
}
}
}
]Every Route Needs a Bearer Token or a Signed-In Session, Like the Rest of the API
Publish a schema in your workspace.
List the schemas you can see, paged.
Read one schema by its id.
Read one schema by its hash.