Skip to content

Schema Overview

A FormSchema describes what the form needs from the user and what the backend will return.

import type { FormSchema } from "mlform/schema";
const schema: FormSchema = {
fields: [
{ id: "prompt", kind: "text", label: "Prompt", required: true },
{ id: "threshold", kind: "number", label: "Threshold", min: 0, max: 1 },
],
reports: [{ id: "prediction", kind: "classifier", label: "Prediction" }],
};
TypePurpose
FormSchemaTop-level object with fields and optional reports.
FieldConfigOne user input. Built-ins use kind values such as text, number, and series.
ReportConfigOne model output panel. Built-ins use classifier and regressor.
FieldConditionDeclarative or function-based rule for hiddenWhen, disabledWhen, or readOnlyWhen.

MLForm normalizes every field and report before rendering:

  • explicit id values are preserved
  • missing field ids are generated from the field label when possible
  • missing report ids are generated from the report label or kind
  • duplicate explicit ids throw a registry/schema error

Use explicit ids in production. Generated ids are useful for demos, but stable ids make UI state, layout refs, focus, validation, tests, and analytics predictable. Backend payload keys belong in mappedTo. User-facing persistence, review, and export keys belong in displayKey; labels are copy and may change. Fields without displayKey are omitted from displayValues.

getField(id), getReport(id), layout refs, validation errors, and report states stay id-keyed because they are runtime APIs. For external contracts, use getFieldByDisplayKey(key), getFieldByMappedTo(target, { backend }), submission displayValues, and submission modelValues.

OptionTypeNotes
idstringStable UI/schema identity. Recommended.
kindstringField kind resolved through the engine registry.
labelstringUser-facing label copy.
displayKeystringStable display/review/export key.
descriptionstringHelp text rendered near the control.
requiredbooleanBuilt-in validation.
defaultValueunknownSchema-level initial value.
hidden, disabled, readOnlybooleanStatic inactive states.
hiddenWhen, disabledWhen, readOnlyWhenFieldConditionDynamic inactive states.
mappedTostring | number | recordBackend input key, position, or backend map.
uiRecord<string, unknown>Renderer-specific metadata.
OptionTypeNotes
idstringStable UI/schema identity.
kindstringReport kind resolved through the engine registry.
labelstringUser-facing heading.
descriptionstringHelp text for the report region.
mappedTostring | number | recordBackend output key, position, or backend map.
uiRecord<string, unknown>Renderer-specific metadata.