Different pipes. One standard.

Type to search this site.

Search runs in your browser against a static index built with this site (Pagefind). Nothing you type is sent to a server.

TransformExperimental

std:validate-schema #

Routes items by validity against a JSON Schema.

For example: stop malformed records before they reach a database.

A pipe is a data processing step with declared inputs and outputs; standard pipes are built into the runner.

Ports #

std:validate-schema takes in and produces valid, rejected.std:validate-schemainrecordsvalidrecordsrejectedrecords · optional
std:validate-schema takes in and produces valid, rejected.std:validate-schemainrecordsvalidrecordsrejectedrecords · optional
Named ports from the latest published contract. Dashed lines are optional ports.
Ports of std:validate-schema
PortDirectionKindRequiredDescription
ininputrecordsyes
validoutputrecordsyes
rejectedoutputrecordsnoInvalid items wrapped as {item, errors}.

Parameters #

Parameters of std:validate-schema
NameTypeDefaultRequiredDescription
schemaobjectnoneyesJSON Schema 2020-12 for one item.

When to use it #

  • Check every record against a JSON Schema before loading: valid records continue on valid.
  • Keep the bad ones for review: connect rejected and each invalid record arrives there with the list of errors.
  • Fail fast instead: leave rejected unconnected and the first invalid record stops the run.

When to use something else

  • It checks, it does not repair or convert: to turn strings into numbers use std:cast. format keywords are annotations in v0.1 and never cause a rejection.

How it works #

Valid one way, invalid the other #

Every item is checked against the JSON Schema (dialect 2020-12) given in schema. A valid item is emitted unchanged on valid. What happens to an invalid one depends on whether you connected rejected:

  • rejected connected — the item arrives there wrapped together with the reasons, and the run goes on:

    json
    {"item": <original>, "errors": [{"path": <JSON Pointer>, "message": <text>}, ...]}
  • rejected not connected — the first invalid item fails the run. Invalid data is never dropped silently.

In the example above the schema requires an integer age of at least 0: {"age":3} continues on valid, while {"age":-1} and {"name":"x"} are rejected. The test checks their number and shape rather than the literal error texts.

Details that matter #

  • A schema that is not itself a valid JSON Schema is a parameter error (E_PARAM), reported before the run.
  • format keywords are annotations in v0.1 and never cause a rejection.
  • The pipe checks and routes; it does not change items. To convert types use std:cast, which wraps its rejects in the same {item, errors} form.

A tested example #

Nothing here is invented: this is the test “routes valid and invalid items” from the pipe's own portable test file, which every conformant runner must pass.

Parameters
{
  "schema": {
    "type": "object",
    "required": [
      "age"
    ],
    "properties": {
      "age": {
        "type": "integer",
        "minimum": 0
      }
    }
  }
}
Input: in
{"age":3}
{"age":-1}
{"name":"x"}
Expected output: valid
{"age":3}
Expected output: rejected

2 items. The test checks their number and shape, not their literal text.

The same step as a node of a pipeline.yaml:

pipeline.yaml
nodes:
  validate-schema:
    pipe: std:validate-schema
    inputs:
      in: {from: inputs.in}
    parameters:
      schema: {type: "object", required: ["age"], properties: {age: {type: "integer", minimum: 0}}}

Notes from the manifest #

The pipe's manifest, OPENFLANGE.md, carries these notes.

Part of the OpenFlange standard library (std, version 0.1).

Validates every item against schema. Valid items pass to valid byte-for-byte. An invalid item is emitted on the optional output rejected as

json
{"item": <the original item>, "errors": [{"path": "/age", "message": "minimum: got -1, want 0"}]}

where path is a JSON Pointer into the item ("" for the item itself) and message is informative text that is not portable — assert on the structure. If rejected is not connected, the first invalid item fails the run with E_RUNTIME — record errors are routed as data or they stop the run; they are never dropped silently.

The schema is compiled once before the run (an invalid schema is E_PARAM). Numbers are validated from their literals, so large integers and decimals are not rounded. External $refs (files, URLs) are refused: the schema must be self-contained. format is an annotation, not an assertion.

Reference #

Maturity
Experimental
Processing scope
record
Manifest version
0.1.0