WorkLensDocs
    Studio
    concept

    Rules & constraints

    What must hold on every row — ranges, uniqueness, date order, conditional presence, and constraints across columns.

    Last updated 2026-09-13 · Generated from recipe-rules.ts · Markdown

    Summary

    Rules are the keys the engine enforces rather than merely draws from. On a field: unique, nullable, min, max, after and present_when. On a table: constraints across columns, and a flow that keeps a status and its dates in order. Rows that fail a constraint are re-rolled, and the receipt reports how often, so a rule that never fires is visible rather than assumed.

    Ruledeclared
    Generaterows drawn
    Checkre-roll failures
    Receipthow often
    A rule is enforced at generation and reported in the receipt.

    On a field

    • unique — Never repeats.
    • nullable — Whether the cell may be empty — false survives a blank rate. Turning this off protects the column from a scenario’s blank rate.
    • min — The lowest a number or date may go.
    • max — The highest a number or date may go.
    • after (e.g. created_at) — This date never falls before another one. A column on this table, or one hop through a link — member_id.joined_on.
    • present_when — Filled in only when a condition holds — blank by rule, not by chance. Every condition must hold. Applied last, so it wins over calculations.
    • expect (e.g. not_exercised) — Says a rule here is meant to sit idle, so a count of zero reads as intended. A rule that guards a case your data never contains is correct and silent. Marking it stops the receipt reporting it as a dead rule. It does not excuse a condition that could never match anything.

    On a table

    • constraints (e.g. dispatched_on >= ordered_on) — A rule across columns that every row must satisfy. One per line. Dates compare as dates. Rows that fail are re-rolled, and the receipt says how often.
    • flow — A status that is the end of a real journey, with dates in order. Names the status column, the legal moves between states, and which date column marks each one.

    On the recipe

    • seed — Same recipe, same seed, same bytes — every time. Leave it empty and every run differs. Set it and the run is reproducible forever.

    A date that never precedes another, and a cross-column rule

    {
      "name": "Order",
      "rows": 200,
      "constraints": [
        "dispatched_on >= ordered_on"
      ],
      "fields": [
        {
          "name": "ordered_on",
          "type": "date",
          "min": "2025-01-01",
          "max": "2025-12-31"
        },
        {
          "name": "dispatched_on",
          "type": "date",
          "after": "ordered_on",
          "nullable": true
        },
        {
          "name": "cancel_reason",
          "type": "text",
          "present_when": [
            {
              "field": "status",
              "eq": "cancelled"
            }
          ]
        }
      ]
    }

    Common questions

    A rule of mine never fires — is that a problem?

    Only if it should. A rule that guards a case the data never contains is correct and silent; mark it expect: "not_exercised" so the receipt reads a count of zero as intended rather than as a dead rule.

    How do I write a rule across two columns?

    Put it in the table’s constraints, one per line, e.g. dispatched_on >= ordered_on. Dates compare as dates. Rows that fail are re-rolled and the receipt says how often.