Skip to main content

Crate oatschema

Crate oatschema 

Source
Expand description

The OATS (Open Annotation Task Schemas) JSON schemas for Rust.

OATS is a collection of strict, versioned JSON Schema 2020-12 schemas, defining and validating the structured outputs of machine learning models, workflow steps and annotation. Models, pipelines and people write the same JSON for each task, whatever produced it.

Every OATS release from 0.8.0 on is compiled into the crate, unchanged, so nothing touches the network or the filesystem. Schemas, documentation and the changelog live at oatschema.org.

use oatschema::{SchemaName, schema_json};

let text = schema_json(SchemaName::Classification, None)?;
assert!(text.contains(r#""$id": "https://oatschema.org/0.8.0/classification""#));

let name: SchemaName = "llm-output".parse()?;
let pinned = schema_json(name, Some("0.8.0"))?;
assert!(pinned.contains(r#""x-version": "0.8.0""#));

§Features

§Schema versions

Every lookup takes a version, which defaults to SCHEMA_VERSION. Versions must be exact, such as "0.8.0"; "0.8" and "latest" are rejected. available_versions lists every bundled version. Before 1.0.0, a schema version may reject records that an older one accepted, so validate a record against the version it was written for.

Each schema states its own version in its x-version keyword, and its $id includes the version (https://oatschema.org/0.8.0/classification), so versions can sit side by side in one JSON Schema registry. Releases before 0.8.0 are not bundled here; the Python package oatschema bundles them.

Enums§

Error
An unknown schema name or version.
SchemaName
The name of an OATS schema.

Constants§

SCHEMA_VERSION
The newest bundled schema version, used when no version is given.

Functions§

available_versions
Every bundled schema version, oldest first. The first is 0.8.0.
schema
Returns the schema name from schema version version, or from SCHEMA_VERSION if it is None, parsed into a new serde_json::Value on every call.
schema_json
Returns the schema name from schema version version, or from SCHEMA_VERSION if it is None, as the schema file’s text exactly as released.