Skip to content

Element <assert>

Purpose: Enforce a boolean data-quality invariant and stop execution when it is false.

Why: Use it to stop execution when a setup- or row-level data invariant is false.

Example

1
<assert condition="is_working_age"/>

Decision guide

Business value: Turns a data or setup requirement into a hard executable quality gate.

  • Use when

    • Execution must stop if a boolean invariant is false.
  • Choose another approach when

    • Invalid rows should be filtered or transformed instead of failing the run.
  • Prerequisites

    • Provide a boolean condition and a message that explains the violated requirement.
  • Alternatives

    • Use sourceConstraints to reject individual loaded rows before mapping. (See: <sourceConstraints>)
    • Use targetConstraints to reject individual completed rows before export. (See: <targetConstraints>)

Complete examples

Stop before generation when a requirement invariant is false

Use assert to make a business precondition executable and fail before an invalid artifact is emitted.

positive-batch-invariant/datamimic.xml
1
2
3
4
5
6
7
<setup>
    <variable name="batch_size" script="3"/>
    <assert condition="batch_size in range(1, 1000000)" message="batch size must be positive"/>
    <generate name="items" count="{batch_size}" target="LogExporter">
        <id name="id" generator="IncrementGenerator"/>
    </generate>
</setup>

Rules and invalid combinations

No additional element-specific rules. Required attributes, types, and supported values are shown below.

Allowed parents / Allowed children

Allowed parents: else, else-if, generate, if, iterate, nestedKey, setup, while

Allowed children:

None

Attributes

Show all 2 attributes

condition

Boolean expression the record (or setup context) must satisfy.

required; string.

message

Optional explanation surfaced when the assertion fails.

optional; string; Default: null.