Platform

Refine a Ledger Schema

Review a Ledger schema in the Formance Studio editor, change it with the schema assistant, and insert it into a ledger.

The Studio editor is where you review a schema, change it, and save it. When it is ready, you download it and insert it into a ledger.

Review the schema#

The editor shows the schema as code, in YAML or JSON, next to a preview of its sections. Switch format with Code format.

Studio runs technical checks as you edit. Besides the schema's shape, the checks catch errors that would make the Ledger reject the schema, for example:

  • a filter on a map-typed field, such as a balance, needs a literal key (balance[USD/2], not balance);
  • Numscript variable names must be lowercase snake_case ($bank_id, not $bankId);
  • a script that builds an account address from a variable cannot run on the machine interpreter;
  • a query with params must repeat its resource.

Fix the errors the checks report before you save or export the schema.

Change it with the schema assistant#

The Schema assistant panel works in two ways:

  • Ask about this schema. Ask a question, such as "Explain the accounts in this model". Asking does not change the schema.
  • Describe a change. Write the change you want in plain English. The assistant drafts a proposed change and shows it as a diff, resource by resource. Review it, then apply it to your draft. You can undo an applied change.

A proposal is drafted against the schema as it stood when you asked. If you edit the schema in the meantime, the proposal is marked out of date.

Save and keep versions#

Save stores the schema in your organization, under Ledger schemas. Each save is a revision, and the side panel keeps the version history.

Insert the schema into a ledger#

Studio does not insert schemas into a ledger itself. To use a schema, take it out of Studio and insert it with fctl or the Ledger API:

  1. In the editor menu, choose Download draft to save the schema as a file, or API commands to copy the equivalent API calls.
  2. Insert it into a ledger. We recommend a ledger on a Sandbox first.

With fctl, pass a version name and the file:

bash
fctl ledger schemas insert v1 ./schema.yaml --ledger <ledger-name>

Schemas are immutable. To change one, insert it again under a new version. Writes to the ledger select a version with schemaVersion. What happens to a write that breaks the schema depends on the Ledger module's validation mode: audit reports the failure, while strict rejects it. See Ledger schema.