WorkLensDocs
    Studio
    tool

    generate_from_graph

    Generate every entity from a recipe with cross-entity foreign-key integrity. Use with a recipe validate_recipe accepts (yours, or one from derive_graph). By…

    Last updated 2026-09-13 · Generated from mcp-schemas/tools/07-generate_from_graph · Markdown

    Summary

    Generate every entity from a recipe with cross-entity foreign-key integrity. Use with a recipe validate_recipe accepts (yours, or one from derive_graph). By default one CSV per table is WRITTEN LOCALLY (./worklens-output, or $WORKLENS_OUT_DIR) and you receive row counts, all proof receipts (constraints/flows/distributions/aggregates/unique/defects…) and file handles with SHA-256 — not the bulk rows. Report the receipts to the user; point them at the files.

    Agentcalls
    generate_from_graphGenerate
    Resultas data

    Inputs and outputs

    Goes in
    • graph_json (string, required) — see the input schema
    • n_rows (number) — Omit to honour the recipe’s per-entity rows; a number overrides every entity.
    • seed (number | string) — Optional. A number pins the run — same recipe + seed + packs + engine = byte-identical (all in the receipt). "today" uses YYYYMMDD, so every run today matches and tomorrow differs. "now" gives a fresh dataset each run. Both are recorded in the receipt as the number they resolved to, so any…
    • scenario (string) — see the input schema
    • recipe_path (string) — Optional: where the recipe file is saved (e.g. worklens/claims.wl.json). The run's lock file, <project>.lock, is written beside it. Without it, the lock goes to the project's worklens/ folder.
    • return_mode (string) — 'metadata' (default) — receipts + file handles, no rows; 'preview' — plus header and first 5 rows per table; 'full' — every row inline, at most 50 rows. 'preview' and 'full' ask the PERSON first, in their client; without their yes (or a client that cannot ask) the reply is metadata with…

    When to call it

    Generates every entity with cross-entity foreign-key integrity, writes one CSV per table, and returns receipts and file handles rather than rows.

    Report the receipts to the user and point them at the files. return_mode: "full" inlines every row and will fill an agent's context on anything but a small run.

    Every receipt array is documented in ../../RECEIPTS.md. They are pre-seeded, so a construct that never fired reads 0/0 rather than being absent - "checked and clean" stays distinguishable from "never checked".

    Omit n_rows to honour the recipe's own per-entity counts, which preserves parent/child ratios. Passing a number overrides every entity.

    Example request

    {
      "_comment": "The base recipe under `orphans`: metadata-first, so receipts and file handles come back rather than rows.",
      "name": "generate_from_graph",
      "arguments": {
        "graph_json": {
          "project": "Suncorp-shaped general insurance group",
          "region": "AU",
          "seed": 20260826,
          "output": {
            "format": "csv"
          },
          "entities": [
            {
              "name": "Intermediary",
              "rows": 400,
              "fields": [
                {
                  "name": "intermediary_id",
                  "type": "id",
                  "unique": true
                },
                {
                  "name": "trading_name",
                  "type": "company.name"
                },
                {
                  "name": "abn",
                  "_note": "Declared here rather than named from a pack: a checksum is a rule, and a rule belongs to the recipe. Same values either way.",
                  "type_def": {
                    "pattern": "N##########",
                    "checksum": {
                      "algorithm": "weighted_mod",
                      "weights": [
                        10,
                        1,
                        3,
                        5,
                        7,
                        9,
                        11,
                        13,
                        15,
                        17,
                        19
                      ],
                      "modulus": 89,
                      "check_digit": "last",
                      "remainder_from": "zero",
                      "first_digit_offset": -1
                    },
                    "display": "## ### ### ###"
                  }
                },
                {
                  "name": "acn",
                  "type_def": {
                    "digits": 9,
                    "checksum": {
                      "algorithm": "weighted_mod",
                      "weights": [
                        8,
                        7,
                        6,
                        5,
                        4,
                        3,
                        2,
                        1
                      ],
                      "modulus": 10,
                      "check_digit": "last"
                    },
                    "display": "### ### ###",
                    "defects": {
                      "invalid": {
                        "at": 0,
                        "replace_with": "0",
                        "breaks": "checksum",
                        "note": "One digit off, so the mod-10 weighted sum fails."
          

    Truncated for the page; the full request sits beside the tool’s schema in the repository.

    Example response

    {
      "status": "completed",
      "contract_version": 3,
      "return_mode": "metadata",
      "rows_generated": 600,
      "tables": [
        {
          "aggregates_report": [],
          "bindings": [],
          "branches_report": [
            {
              "branch_index": 0,
              "condition": "intermediary_type = aggregator",
              "construct": "params_when",
              "entity": "Intermediary",
              "field": "commission_rate_pct",
              "rows_changed": 1,
              "rows_matched": 1
            },
            {
              "branch_index": 1,
              "condition": "intermediary_type = affinity_partner",
              "construct": "params_when",
              "entity": "Intermediary",
              "field": "commission_rate_pct",
              "rows_changed": 2,
              "rows_matched": 2
            }
          ],
          "constraints_report": [],
          "defects_report": [],
          "derived": [],
          "distributions_report": [],
          "entity": "Intermediary",
          "fanout_report": [],
          "fillers": [],
          "flows_report": [],
          "graph_report": [],
          "hierarchy_report": [],
          "locales": [],
          "overlap_report": [],
          "provenance": [
            {
              "basis": "Hand-authored for the AU launch region. Suburb/postcode/state rows are checked against the official Australia Post postcode ranges by locale_pack::every_suburb_postcode_matches_its_state, which runs on every build — so unlike the drafted packs, the address rows carry a mechanical guarantee rather than a claim.",
              "caveats": [
                "BSB prefixes are the well-known institution codes. The full APCA register is larger and changes with mergers.",
                "Name pools reflect a multicultural Australia but are illustrative, not census-weighted.",
                "reviewed_by is null: the postcode ranges are machine-verified, but nobody has signed off on the name and company pools."
              ],
              "drafted_by": "worklens",
              "engine_notes": [
                "this pack declares no valid_until, so nothing can tell you when its contents went out of date",
                "this pack's streets carry no region, so a street may appear in a suburb hundreds of kilometres away — give the streets dataset an address.region column to fix it"
              ],
              "freshness": "undeclared",
              "method": "bundled",
              "pack": "au-locale",
              "pack_hash": "9118072102a8bf6ee5ed44bab52bb180104a3fba1b117

    Truncated for the page; the full response sits beside the tool’s schema in the repository.

    Same step