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";
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
  • missing report source defaults to the report id
  • duplicate explicit ids throw a registry/schema error

Use explicit ids in production. Generated ids are useful for demos, but stable ids make backend payloads, tests, and analytics predictable.

OptionTypeNotes
idstringStable backend key. Recommended.
kindstringField kind resolved through the engine registry.
labelstringUser-facing label.
descriptionstringHelp text rendered near the control.
requiredbooleanBuilt-in validation.
defaultValueunknownSchema-level initial value.
hidden, disabled, readOnlybooleanStatic inactive states.
hiddenWhen, disabledWhen, readOnlyWhenFieldConditionDynamic inactive states.
uiRecord<string, unknown>Renderer-specific metadata.
OptionTypeNotes
idstringReport id and default backend response key.
kindstringReport kind resolved through the engine registry.
labelstringUser-facing heading.
descriptionstringHelp text for the report region.
sourcestringBackend response key when it differs from id.
uiRecord<string, unknown>Renderer-specific metadata.