Validate a Formhaus definition
validate_definitionValidate Formhaus form definitions against JSON Schema and engine rules before simulation or publishing; get errors, warnings, and repair patches.
Instructions
Call this after writing or editing a definition and before simulate_path or publish_form; it checks the structure and engine rules, while simulate_path checks how a user moves through the form. Checks a Formhaus form definition against the JSON Schema and the engine. Returns { valid, issues }. Each issue has code, severity ("error" or "warning"), a JSON pointer path, message, hint and, when a repair is known, fixes: a list of { title, safe, patch } where patch is an RFC 6902 JSON Patch. Errors make the engine reject the definition, such as a condition with zero or two operators, a condition on a later step, a duplicate key, a route to an earlier step, a condition outside a group on a field inside it (group-scope) or a section inside a section (invalid-nesting). Warnings point to likely mistakes, such as a condition value that is not an option, a select without options or next: false without an autoAdvance radio. Fix each error at its path, or apply one of its fixes, and call again. To apply every safe fix at once, call fix_definition.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| definition | Yes | Formhaus form definition as a JSON object or a JSON string. JSON Schema: https://formhaus.dev/schema/form-definition.json. Top level: id, title, submit { label }, and fields (one step) or steps [{ id, title, fields }]. Field: { key, type, label, validation?, options?, show?, showAny? }. Rules go inside "validation": { required, minLength, maxLength, min, max, pattern, matchField }. Condition: { field, eq | neq | in | notIn | notEmpty | gt | gte | lt | lte } with exactly one operator, on a field of the same or an earlier step. Optional: lang, messages and labels catalogs, and i18n objects that map texts to translation keys. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| valid | Yes | false when at least one issue has severity "error". | |
| issues | Yes | Errors first, then warnings. Fix every error at its path and validate again. |