{
  "content": {
    "icon": "bi-file-earmark-code",
    "id": "templates-core",
    "intro": "This section covers the template and how an instance is raised from it. A template record has four parts, a declared document type, the slots an instance fills, the constraints every instance must satisfy, and a body in which every slot appears by name, as shown in [template record]. [template and sibling] shows how a template differs from a sibling instance. Raising an instance is a resolution in which each slot is substituted, a slot left unresolved is reported rather than guessed, and a value outside a slot's declared set is a violation. [resolution] lists the three outcomes. The record and [workflow body] are the grammar's own workflow template, read from its records rather than restated here.",
    "subsections": [
      {
        "blocks": [
          {
            "application": "In practice, a template is written the second time a shape occurs, before the second instance is written, in the order shown in [second instance]. It declares its type, names every slot with whether it is required and, where the values form a closed set, that set, and it names the constraints every instance must satisfy so a check can read them. The body keeps only what every instance shares, with every varying value as a slot. Each new instance is raised by resolving the slots, and an instance whose resolution reports an unresolved slot or a violation is refused.",
            "boundary": "A shape seen once has no template, because one instance cannot show which of its parts are invariant. A template raised from one instance is [premature abstraction](/records/architecture/premature-abstraction).",
            "cause": "A sibling carries one instance's choices and a template carries the constraint, and a reader copying a sibling cannot tell which is which.",
            "decision": "Shared structure is extracted once a pattern repeats, rather than copied from an earlier example.",
            "failureMode": "Four parties produce four formats for one surface, each derived from a different sibling, and the check that later reads them derives its schema from a fifth.",
            "kind": "lesson",
            "principle": "For this reason what every instance must share is stated once, where a tool can hold each new one to it.",
            "problem": "An instance derived from a sibling inherits that sibling's accidents as a contract.",
            "validation": "To check this, take a template and find a value in it that would be wrong for the next instance. That value is content rather than contract, and a slot is the repair. Then resolve the template with one slot missing, and a resolution that raises the instance anyway has guessed."
          },
          {
            "kind": "text",
            "text": "The slots fall into two kinds by who supplies the value. An instance slot is what this document is for, supplied when it is raised. A host slot is a fact about the tree the document will be walked in, namespaced by its subject and filled by the adapter, so one template works in any tree."
          },
          {
            "kind": "text",
            "text": "The constraints are the family's acceptance criteria, and a check over an instance reads them from the template, as [the drop-in](/disciplined-methodology#onboarding) describes. What the template excludes is as deliberate as what it carries, so it names no model, no path and no tool, for the reasons described in [semantic operations](/pag/guide#tool-invocation). A correction lands in the template and reaches every later instance, never in the instance where only its author would see it."
          },
          {
            "code": "template:\n  type:        WORKFLOW                       # a declared document type · nothing else\n  title:       <what the family is for>\n  slots:\n    - name:        {WORKFLOW_NAME}             # the value an instance supplies\n      description: <what the slot holds>\n      required:    true\n      kind:        string\n    - name:        {project.governance_policy}   # a host fact · resolved by the adapter, never typed\n      required:    true\n    - name:        {limits.max_lines}            # a bound · resolved from the host's limits\n      required:    false\n    - name:        {scope}\n      required:    true\n      enum:        [<investigate>, <action>]     # a closed set · a value outside it is a violation\n  constraints:                                  # what every instance must satisfy · named, checkable\n    - declaration_required\n    - gate_per_node\n    - contract_reads_prior_output\n    - population_declared\n    - refusal_before_write\n    - invariant_has_objector\n    - no_autonomous_spawn\n    - single_source_of_truth\n  body: |\n    <the document, with every slot as {name}>",
            "kind": "code",
            "language": "text",
            "title": "template record"
          },
          {
            "code": "---\nname: {WORKFLOW_NAME}\ntype: WORKFLOW\nversion: 1.0.0\n---\n\nTHIS WORKFLOW EXECUTES {WORKFLOW_PURPOSE}\n\n%% META %%:\n    intent: \"{WORKFLOW_INTENT}\"\n    objective: \"{OBJECTIVE}\"\n    jurisdiction: {INPUT_SOURCE} and {OUTPUT_TARGET} | external: every other surface\n    recursion_limit: 2\n\n# NODE 1 — {NODE_ONE_TITLE}   [epistemic · analysis · set-theory · yields: set]\n@purpose: \"read the input and see it through the analysis the workflow is for\"\n@genesis: existence\nCONTRACT:\n  input:     {INPUT_SOURCE}\n  transform: READ_RESOURCE {INPUT_SOURCE} INTO input; ANALYZE_CONTENT input AGAINST {ANALYSIS_TARGET} INTO analysis\n  output:    analysis\nHANDOFF GATE (evidence-bearing):\n  [check] input read from {INPUT_SOURCE} (evidence: the read returned content) over: {INPUT_SOURCE} measured: <read> / <declared>\n  [check] analysis produced (evidence: a count above zero)\n  [check] every entry of analysis names its source in input (evidence: no entry with an empty source)\n  result: pass → NODE 2 | empty → REPAIR (owner: NODE 1) | unknown → BLOCKED\n\n# NODE 2 — {NODE_TWO_TITLE}   [epistemic · formalization · computation · yields: procedure]\n@purpose: \"transform every item by one rule, preserving what the next node needs\"\n@genesis: transformation\nCONTRACT:\n  input:     analysis from NODE 1\n  transform: FOR EACH item IN analysis: COMPOSE_ARTIFACT result FROM item USING {TRANSFORM_RULE}; APPEND result TO results\n  preserves: the source of every item\n  output:    results\nHANDOFF GATE:\n  [check] one result per item (evidence: the two counts match) over: analysis measured: <transformed> / <items>\n  [check] every result conforms to {TRANSFORM_RULE} (evidence: VALIDATE_ARTIFACT passed on each)\n  [check] analysis unchanged (evidence: a witness read)\n  result: pass → NODE 3 | mismatch → REPAIR (owner: NODE 2) | unknown → BLOCKED\n\n# NODE 3 — FINALIZATION   [evaluative · representation · information-theory · yields: artifact]\n@purpose: \"persist the results once, refuse a stale destination, and report to the parties whose next work they create\"\n@genesis: constraint\nCONTRACT:\n  input:     results from NODE 2\n  transform: PERSIST_ARTIFACT results TO {OUTPUT_TARGET}; REPORT_RESULT completion TO <the parties whose next work it creates>\n  output:    {OUTPUT_TARGET}\n  freshness: fingerprint(results) + fingerprint(this document)\nHANDOFF GATE:\n  [check] {OUTPUT_TARGET} persisted (evidence: a read returns it) over: results measured: <persisted> / <results>\n  [check] completion reported (evidence: the report)\n  [check] entry count of {OUTPUT_TARGET} matches results (evidence: the two numbers)\n  refuse: {OUTPUT_TARGET} changed since it was read before PERSIST_ARTIFACT\n  standing: moved-set none\n  result: pass → TERMINATE | loss → REPAIR (owner: NODE 3) | unknown → BLOCKED\n\n# CROSS-NODE INVARIANTS\nINVARIANT prior-output-only: a node reads only the prior node's output over: every node binds: the workflow objector: [check] input names NODE n-1 or a slot\nINVARIANT one-truth: one fact has one home across the nodes over: every artifact binds: the workflow objector: [check] entry count of the output matches results\nINVARIANT no-spawn: no autonomous party is spawned over: every node binds: the workflow objector: none\n\nREPORT:\n  subject: NODE 3\n  verdict: pass | fail | unknown\n  domain: declared <results> measured <persisted>\n  completion: saturated <bool> complete <bool> verified <bool>\n",
            "kind": "code",
            "language": "pag",
            "title": "workflow body"
          },
          {
            "code": "resolve <template> WITH <the values an instance supplies>\n\n  substituted   every {name} the instance supplied, replaced in the body\n  unresolved    [{OUTPUT_TARGET}]                        # still in the body · the instance is not ready\n  violations    [missing_required_slot:{OBJECTIVE},       # a required slot with no value\n                 enum_violation:{scope}]                  # a value outside the slot's closed set\n\n# an instance with a non-empty unresolved or violations list is not raised · nothing guesses a value",
            "kind": "code",
            "language": "text",
            "title": "resolution"
          },
          {
            "caption": "template and sibling",
            "kind": "mermaid",
            "text": "flowchart TB\n    template[\"A template record · type, slots, constraints, body\"]\n    raised[\"An instance · raised by resolving every slot\"]\n    check[\"A check · reads the constraints and the slot declarations\"]\n    sibling[\"A sibling instance\"]\n    copied[\"An instance copied from the sibling · inherits its accidents\"]\n    template --> raised\n    template --> check\n    sibling -. the tempting path .-> copied"
          },
          {
            "caption": "second instance",
            "kind": "mermaid",
            "text": "flowchart LR\n    one[\"One instance · an artifact\"]\n    two[\"A second · the invariant half is now visible\"]\n    template[\"The template is written before the second is\"]\n    later[\"Every later instance is raised from it\"]\n    one --> two --> template --> later"
          }
        ],
        "title": "Contract, not content"
      }
    ],
    "title": "Core templates"
  },
  "graph": {
    "requires": [
      "declare-before-instructing",
      "drop-in-onboarding"
    ],
    "teaches": [
      "a-template-carries-the-contract"
    ],
    "traces": [
      "recurring_shape_is_a_template",
      "template_is_the_contract_not_a_copy_of_it"
    ]
  },
  "href": "https://banes-lab.com/pag/templates#templates-core",
  "number": "87",
  "page": "pag",
  "ref": "chapter:/pag/templates#templates-core",
  "relations": [
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-premature-abstraction",
          "json": "https://banes-lab.com/json/records/architecture/premature-abstraction",
          "label": "Premature Abstraction",
          "markdown": "https://banes-lab.com/records/architecture/premature-abstraction.md",
          "ref": "architecture:premature-abstraction"
        },
        {
          "href": "https://banes-lab.com/disciplined-methodology#onboarding",
          "json": "https://banes-lab.com/json/disciplined-methodology/start/onboarding",
          "label": "The drop-in",
          "markdown": "https://banes-lab.com/disciplined-methodology/start/onboarding.md",
          "ref": "chapter:/disciplined-methodology#onboarding"
        },
        {
          "href": "https://banes-lab.com/pag/guide#tool-invocation",
          "json": "https://banes-lab.com/json/pag/guide/tool-invocation",
          "label": "Semantic operations",
          "markdown": "https://banes-lab.com/pag/guide/tool-invocation.md",
          "ref": "chapter:/pag/guide#tool-invocation"
        }
      ],
      "relation": "links-to"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/pag/patterns#algorithm-integration",
          "json": "https://banes-lab.com/json/pag/patterns/algorithm-integration",
          "label": "Integrating algorithms",
          "markdown": "https://banes-lab.com/pag/patterns/algorithm-integration.md",
          "ref": "chapter:/pag/patterns#algorithm-integration"
        },
        {
          "href": "https://banes-lab.com/disciplined-methodology#three-encodings",
          "json": "https://banes-lab.com/json/disciplined-methodology/start/three-encodings",
          "label": "Three encodings",
          "markdown": "https://banes-lab.com/disciplined-methodology/start/three-encodings.md",
          "ref": "chapter:/disciplined-methodology#three-encodings"
        },
        {
          "href": "https://banes-lab.com/disciplined-methodology/plan#execute-the-template",
          "json": "https://banes-lab.com/json/disciplined-methodology/plan/execute-the-template",
          "label": "Execute the template",
          "markdown": "https://banes-lab.com/disciplined-methodology/plan/execute-the-template.md",
          "ref": "chapter:/disciplined-methodology/plan#execute-the-template"
        }
      ],
      "relation": "linked-from"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/anatomy/coordination#file-coordination-provider-templates-pattern-protocol-template-md",
          "json": "https://banes-lab.com/json/source/coordination/.provider/templates/pattern.protocol.template.md",
          "label": ".{provider}/templates/pattern.protocol.template.md",
          "markdown": "https://banes-lab.com/source/coordination/.provider/templates/pattern.protocol.template.md.md",
          "ref": "anatomy:file-coordination-provider-templates-pattern-protocol-template-md"
        }
      ],
      "relation": "evidence"
    }
  ],
  "route": {
    "next": {
      "href": "https://banes-lab.com/pag/templates#templates-coordination",
      "json": "https://banes-lab.com/json/pag/templates/templates-coordination",
      "label": "88 - Coordination templates",
      "markdown": "https://banes-lab.com/pag/templates/templates-coordination.md",
      "ref": "chapter:/pag/templates#templates-coordination"
    },
    "position": 87,
    "previous": {
      "href": "https://banes-lab.com/pag/orchestration#orchestration-invariants",
      "json": "https://banes-lab.com/json/pag/orchestration/orchestration-invariants",
      "label": "86 - Orchestration invariants",
      "markdown": "https://banes-lab.com/pag/orchestration/orchestration-invariants.md",
      "ref": "chapter:/pag/orchestration#orchestration-invariants"
    },
    "requires": [
      {
        "href": "https://banes-lab.com/pag/guide#document-structure",
        "json": "https://banes-lab.com/json/pag/guide/document-structure",
        "label": "16 - Document structure",
        "markdown": "https://banes-lab.com/pag/guide/document-structure.md",
        "ref": "chapter:/pag/guide#document-structure"
      },
      {
        "href": "https://banes-lab.com/disciplined-methodology#onboarding",
        "json": "https://banes-lab.com/json/disciplined-methodology/start/onboarding",
        "label": "11 - The drop-in",
        "markdown": "https://banes-lab.com/disciplined-methodology/start/onboarding.md",
        "ref": "chapter:/disciplined-methodology#onboarding"
      }
    ],
    "stop": "ap87",
    "total": 102
  },
  "section": "templates-core",
  "summary": "This section covers the template and how an instance is raised from it.",
  "tab": "templates",
  "title": "Core templates",
  "siblings": {
    "next": {
      "href": "https://banes-lab.com/pag/templates#templates-coordination",
      "json": "https://banes-lab.com/json/pag/templates/templates-coordination",
      "label": "Coordination templates",
      "markdown": "https://banes-lab.com/pag/templates/templates-coordination.md",
      "ref": "chapter:/pag/templates#templates-coordination"
    },
    "previous": null
  },
  "up": {
    "href": "https://banes-lab.com/pag/templates",
    "json": "https://banes-lab.com/json/api/pages/pag/templates",
    "label": "PAG · Templates",
    "markdown": "https://banes-lab.com/api/pages/pag/templates.md",
    "ref": "api:/pag/templates"
  }
}
