Talk with Archie
WorkStreams

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.

Three words

Schema, Record and Form

Schema
JSON Schema 2020-12

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.

Record
one instance

One instance of a schema. One statement for one account and one period.

Form
not a schema

What a person fills in. A form is not a schema. What the person enters becomes a record.

The id and the version

How a Schema Is Named

A schema's $id names it and carries its version:

text
<area>/<kind>[/<stage>]/<version>

investment/statement/recognised/1.1
investment/ties/1.5
The id

The Rules for an Id

Name
two or three parts

The name has two or three parts. Each part starts with a letter or a digit, then letters, digits, _ or -.

Version
whole numbers

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.

Length
at most 255

The whole id is at most 255 characters.

Never changes
a new version

A version never changes. A changed shape is a new version with a new $id.

What a schema must be

The Platform Refuses a Document Unless All of These Hold

$schema
dialect

"$schema" is https://json-schema.org/draft/2020-12/schema.

$id
name

"$id" fits the pattern above.

type
top level

The top level is "type": "object", because a record is an object.

$ref
references

Every $ref points inside the same document (for example #/$defs/row) and finds something there.

What a schema must be

And All of These as Well

Meta-schema
valid

It is valid against the JSON Schema 2020-12 meta-schema.

Numbers
no decimal point

No number has a decimal point. Write a limit on an amount as a pattern on its text.

pattern
readable

Every pattern is a regular expression the platform can read, and no text holds a NUL character.

Depth
at most 64

It is nested no more than 64 levels deep.

A refusal

A refusal lists every problem, each with its place in the document as a JSON Pointer. It never repeats the value it refused.

The hash

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.

python
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

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.

bash
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"
}
The hints

Optional, Kept Beside the Document

rows_at
JSON Pointer

Where a record's list of rows is, as a JSON Pointer.

row_key
list of names

The fields that make a row's key, a list of distinct names.

proof_at
JSON Pointer

Where a record's proof list is, as a JSON Pointer.

The answers

What Publishing Answers

201
published

Published. The body is the entry: id, name, version, sha256, title, rows_at, row_key, proof_at, published_at and published_by.

200
already held

The same $id already holds the same content and hints. Nothing changes, so publishing is safe to repeat.

Refusals

When Publishing Is Refused

409
schema_version_exists

The $id holds other content or other hints. The body carries id and sha256_held. Publish a new version instead.

422
schema_refused

The body carries problems, a list of {path, problem}.

403
workspace_required

Publishing needs a signed-in workspace.

Refusals and whose schemas you see

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 it back

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.

bash
# 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
Gives and takes on a step

Every Kind of Step Can Carry Two Optional Fields

gives
what the step hands on

A map from a port name to {schema, sha256, many}. schema and sha256 are required.

takes
what the step expects

A map from a port name to {from, schema, sha256, many}. from is required; schema and sha256 are optional.

many
true or left out

many: true means a list of records. Left out, it means one record.

Port name
1 to 100 characters

A port name is 1 to 100 letters, digits, _ or -. It has no dot, so a from path stays unambiguous.

A step without them

A step without them works, and is stored, exactly as before.

from

Where the Value Comes From, in One of Three Forms

steps.<step id>.<port>
an earlier step

What an earlier step gives under that port name.

inputs.<name>
the cycle start

A value given when the cycle starts.

A value kept for the client
no fixed spelling

The platform does not read from yet, so this form has no fixed spelling today; it is stored as written.

What the platform checks today

When You Save a WorkStream, It Checks the Shape of These Fields Only

Port names
the rule above

Every port name fits the rule above.

gives entries
schema and sha256

Every gives entry has a schema written as text and a sha256 of 64 lower-case hex characters.

takes entries
from, and any sha256

Every takes entry has a from written as text, and any sha256 it has is 64 lower-case hex characters.

No other fields
four named

No entry carries a field other than the four named here.

Stored, not yet enforced

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.

A worked example

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.

json
{
  "$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
}
A worked example

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.

json
"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
      }
    }
  }
]
Routes

Every Route Needs a Bearer Token or a Signed-In Session, Like the Rest of the API

POST /api/v1/workstreams/schemas
publish

Publish a schema in your workspace.

GET /api/v1/workstreams/schemas
list

List the schemas you can see, paged.

GET /api/v1/workstreams/schemas/by-id?id=<$id>
by id

Read one schema by its id.

GET /api/v1/workstreams/schemas/{sha256}
by hash

Read one schema by its hash.