Add a validation rule¶
Add a rule to a workflow type, method, or data type so the platform rejects bad configurations / invalid data instances at the boundary instead of failing mid-run.
Prerequisites¶
- A component with a
configurationSchema(workflow type or method) or adataSchema/metadataSchema(data type) that has at least one field. - SimKit CLI installed (see installation).
Decide where the rule lives¶
| Component | Block | Validates |
|---|---|---|
| Workflow type | validationRuleSet { … } |
the workflow's configuration |
| Method | validationRuleSet { … } |
the method's configuration |
| Data type | dataSchemaValidationRuleSet { … } |
data instances |
| Data type | metadataSchemaValidationRuleSet { … } |
metadata instances |
Inside, the body sees the corresponding value model
(configValueModel, valueModel, or metadataValueModel) typed to
the relevant schema.
Example: bound a length between 1 mm and 100 mm with helpers¶
The bound-check helpers cover the most common case — a numeric field between two bounds — without you writing the conditions yourself:
validationRuleSet {
ValidationRuleSet(
listOf(
ValidationRule(
code = "edge_length",
name = "Edge length check",
valueReference = configValueModel.edgeLength.reference(),
cases = listOf(
checkLowerBound(configValueModel.edgeLength, lowerBound = 1.millimeter, includeBound = false),
checkUpperBound(configValueModel.edgeLength, upperBound = 100.millimeter, includeBound = false),
checkUpperBound(configValueModel.edgeLength, upperBound = 50.millimeter, includeBound = false,
severityLevel = SeverityLevel.WARNING),
),
),
),
)
}
Three cases here: hard lower bound (ERROR if below 1 mm), hard upper
bound (ERROR if above 100 mm), soft upper bound (WARNING if above 50
mm). Generated from the framework's
com.simscale.workflows.framework.values.validation.checkLowerBound /
checkUpperBound / checkRange.
Example: a custom condition¶
When the bound-check helpers don't fit (you need a multi-field condition, a list predicate, an enum check), write the case yourself:
ValidationRuleCase(
code = "iterations_too_low",
condition = configValueModel.maxIterations greaterThan 10.asValueModel(),
severityLevel = SeverityLevel.ERROR,
message = "maxIterations must be > 10; got: ".asValueModel() + configValueModel.maxIterations,
)
Read the condition as the predicate that must hold: > 10 means
"fail if not greater than 10."
How conditions and messages work¶
conditionis aBooleanValue— built from comparison operators (greaterThan,equal,oneOf, …), boolean composition (and,or,not), and select (select(c1 to v1, c2 to v2, …)).messageis aStringValue— re-evaluated against user data at validation time, so you can splice in the offending value (aDimensionalScalarValuebecomes"5 mm"via implicit conversion).severityLevel:ERROR(blocks the user),WARNING(warns but allows). NoINFO.
See concepts: validation rules for the anatomy and concepts: value models for the operator surface.
Build and verify¶
The validation rule set is bundled into the component's JSON
envelope (in the package field, alongside the schema and other
metadata); the registry stores it; the platform consults it on every
configuration write. To see a case fire, configure the component in
Workbench with a value that violates the rule — the failing case's
message appears on the configuration form.
Cross-references¶
- Concepts: validation rules.
- Concepts: value models.
- Reference: validation helpers
—
checkLowerBound,checkUpperBound,checkRangefor every numeric value type. - Reference: value-model catalogue — every operator, exhaustive.