WorkLensDocs
    Studio
    guide

    Best practices

    The 21 rules the engine gives an AI agent before it drafts a recipe — 6 of them critical — as useful to a person as to a model.

    Last updated 2026-09-13 · Generated from get_recipe_schema (rules, critical_rules) · Markdown

    Summary

    When an agent asks for the recipe schema, it also receives 21 rules: what to confirm before generating, how to declare a foreign key, what a scalar column is, why entity names must be unique. They are written for a model, but they are the same mistakes a person makes. The 6 marked critical come first.

    Read the schemaget_recipe_schema
    Draftfollow the rules
    Validatevalidate_recipe
    Generate

    Critical

    Break one of these and the run either fails validation or produces data that quietly means something else.

    • FIELDS ARE SCALAR COLUMNS. Never emit an object or array field. A reference to another entity is a scalar id field with ref; a one-to-many list is a foreign key on the CHILD entity.
    • FOREIGN KEYS NEED BOTH: ref: "Parent.field" on the child field AND a matching relationships[] entry (without one, a warning: no line is drawn).
    • CROSS-FIELD RULES GO IN entities[].constraints, never on a field. "end after start" is a constraint, not a field property.
    • NEVER PUT REAL VALUES IN A RECIPE. It describes shape — names, types, ranges, rules. No sample data, ever.
    • THE RECIPE COMES FROM THE CODE, NOT FROM HABIT. With repository access, run the task_discovery.procedure sweep: note what the code DOES (parses a file, joins on an id, verifies a check digit, reconciles a total, walks a status column), match it against task_discovery.evidence, and declare every match. Record your…
    • RESTATE BEFORE GENERATING. validate_recipe returns a declaration — the recipe in plain English. Show it to the user and get confirmation before generate_from_graph. A recipe can be perfectly valid and still say the wrong thing.

    All rules

    The full list, in the order the engine states them.

    • The declaration validate_recipe returns is generated BY THE SERVER, not paraphrased by you: every row count, mix as percentages, branch, row rule, scenario and the seed. It is the only check that catches a recipe that is valid and says the wrong thing — 30/70 where they said 70/30, a rule on the wrong table. Read…
    • Entity names unique across the recipe; field names unique within their entity.
    • type 'enum' REQUIRES values; weights (if given) must be the same length.
    • min must be <= max when both are given.
    • An unknown type is an error: use a listed type, or declare an identifier with type_def.
    • Generate parents implicitly: declare relationships and the engine orders generation; you do NOT need to order the entities array.
    • Cross-field rules (a.k.a. assertions / invariants) hide in the source's HUMAN-READABLE corners — descriptions, validation-error examples ('scheduledEnd must be later than scheduledStart'), required-together notes. Extract them into entities[].constraints — you write the rule once; the deterministic engine enforces…
    • Cross-row totals: NEVER fake a total with a generator type — give the parent a field with aggregate: 'sum(Child.field)' and the engine fills it from the real child rows after generation (aggregates_report proves it reconciles). Patterns: conditional totals = sum a derived helper on the child (settled_amount = status…
    • EXECUTION ORDER, per row: base values → weights_when/params_when → bindings → dates → from → flow → derive → the branches that read a derive → present_when. A branch may condition on a derived column — key a mix on a DATE via a derived flag (admitted < date(2026, 4, 1) ? 1 : 0); operators compare numbers. Aggregates…
    • Business journeys: when statuses have an ORDER (scheduled → confirmed → completed), declare entities[].flow instead of relying on enum weights — the engine walks the transition map deterministically, orders the mapped timestamp fields along the walk, blanks the fields of states never reached (no 'cancelled but…
    • Declared correlations: when the source says 'X shifts GIVEN Y' — Friday evening lifts snacks +35%, premium customers order pricier, nappies imply wipes 72% — put weights_when on the DEPENDENT enum: branches keyed by the condition field's value, each with a full weights vector over this field's values. Do NOT split…
    • Realistic shapes: flat randomness is the default, but real data is lopsided — money and amounts want shape: 'long_tail', ages and durations want 'normal', business dates want shape: 'weekday' or month_weights (e.g. 8x December). Link related columns with derive + noise(): 'salary = 30000 + age * 1200 + noise(5000)'.…
    • Hierarchies: for org charts, account trees and single-parent BOMs, declare entities[].tree (deliberate level-by-level construction — depth guaranteed, cycles impossible) and put rollup: 'count' or 'sum(cost)' on the fields that must total through the tree (hierarchy_report proves every node equals itself plus its…
    • THE REF-COPY CHAIN (copy a parent's value onto the child): give the child a field whose ref names the parent's DATA column, next to its FK — { name: 'customer_id', ref: 'Customer.customer_id' } and { name: 'customer_tier', ref: 'Customer.tier' }. All refs to the SAME parent resolve from ONE parent row, so the copy…
    • Multi-parent graphs (shared BOM components, quantity-weighted edges): model parts + a connections entity, declare entities[].graph { edges, parent, child, qty } on the PART entity, and reuse rollup — totals travel through the edges multiplying by qty (4 wheels x $100 = $400; a shared bolt counts once per use —…
    • Fixed-width layouts hide in Pentaho/Hop output-step XML, COBOL copybooks, sample files and spec prose — lift every position into skeleton_def + overlay. With ONE real sample, compare your line against it column-for-column first. format_report is structural proof only — never claim bank acceptance. EBCDIC and…
    • Custom fixed-width layouts (skeleton_def / record_length): the RECIPE is the physical contract — the engine writes exactly what you declare, knows no standard and re-derives nothing. Declare it completely: (1) record_length stated explicitly; (2) every byte accounted for — constants and fillers as field defaults or…
    • Hidden multi-field relationships: when the source states one ('older home-owners get bigger loan limits'), express it. Two constructs: params_when on the numeric field when a SEGMENT has its own distribution ({ all: [conditions], min, max, shape }), and derive with a formula + noise() when the relationship is smooth…
    • Planted defects vs chaos rates: when a TEST needs one exact wrong case ('P_18 asserts the invalid-account row'), use scenarios[].defects — { row, field, kind } lands every single run and defects_report labels it, so a failing test points straight at the cause. When the goal is statistical mess (5% nulls, 2% broken…
    • One dataset, many file formats: determinism IS the multi-format mechanism — the same recipe + the same seed produces byte-identical values, so run once per output block (e.g. ABA, then NACHA, then CSV) and the amounts/references match across all of them by construction. Declare each layout fully; do not hand-sync…
    • Distribution realism check: distributions_report already compares the DECLARED profile (weights/shape/dist learned from a real sample at import) against the GENERATED mix every run — read it after generating instead of re-profiling by hand; drift between recipe and a NEWER schema/sample is the freshness check's job…