{
  "id": "p4CapitalCall001",
  "name": "P4 Capital call forecast",
  "nodes": [
    {
      "id": "e35f0283-f3b5-408e-8d3d-834c6d127db3",
      "name": "Human: input",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -110,
        -170
      ],
      "parameters": {
        "content": "## Human: input\nA person uploads the documents in the form.",
        "width": 320,
        "height": 330,
        "color": 6
      }
    },
    {
      "id": "5b79e2a2-bdc6-4b50-8900-75fb8f5c2d15",
      "name": "Human: result",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        4310,
        -170
      ],
      "parameters": {
        "content": "## Human: result\nThe same person sees the results table in the browser.",
        "width": 320,
        "height": 330,
        "color": 6
      }
    },
    {
      "id": "f8562f70-de94-44a4-87eb-40f19cc9fed0",
      "position": [
        0,
        0
      ],
      "name": "Upload",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "parameters": {
        "formTitle": "Capital call forecast",
        "formDescription": "Upload the investor register (PDF) and enter the next capital call. Each LP gets a late-payment probability; likely late payers get two reminders.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Notice date",
              "fieldName": "noticeDate",
              "fieldType": "date",
              "requiredField": true
            },
            {
              "fieldLabel": "Notice period (days)",
              "fieldName": "noticeDays",
              "fieldType": "number",
              "defaultValue": "10",
              "requiredField": true
            },
            {
              "fieldLabel": "Call (% of commitment)",
              "fieldName": "callPct",
              "fieldType": "number",
              "defaultValue": "10",
              "requiredField": true
            },
            {
              "fieldLabel": "Investor register",
              "fieldName": "files",
              "fieldType": "file",
              "multipleFiles": true,
              "acceptFileTypes": ".pdf",
              "requiredField": true
            }
          ]
        },
        "options": {
          "path": "capital-call-forecast",
          "appendAttribution": false
        }
      },
      "webhookId": "8ab04cd4-3172-4b55-8f7c-e96e2cbc4123"
    },
    {
      "id": "84bdaabb-c54e-48a6-84e7-7a457bdb568a",
      "position": [
        260,
        0
      ],
      "name": "Read document",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkReadDocument1",
          "cachedResultName": "read document (OCR)",
          "cachedResultUrl": "/workflow/blkReadDocument1"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      }
    },
    {
      "id": "7177495d-eafd-4fde-88d7-14701e1f8798",
      "position": [
        520,
        0
      ],
      "name": "Fields to extract",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "59e55374-b2d2-42a4-8ec6-7aad1d5f2262",
              "name": "schema",
              "value": "lpRegister",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "79d5faa0-0a82-4bdd-88ed-7a74708158f1",
      "position": [
        780,
        0
      ],
      "name": "Extract LP register",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkExtractFields",
          "cachedResultName": "extract fields (LLM)",
          "cachedResultUrl": "/workflow/blkExtractFields"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "notes": "LLM reads every LP: name, type, region, commitment"
    },
    {
      "id": "4dcaf038-d095-41b0-88c0-90d9d8bdbcff",
      "position": [
        1040,
        0
      ],
      "name": "One item per LP",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "parameters": {
        "fieldToSplitOut": "record.lps",
        "options": {}
      }
    },
    {
      "id": "8a983211-101d-40d5-8dee-b46630ced298",
      "position": [
        1300,
        0
      ],
      "name": "Add late payments",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByFields",
        "advanced": true,
        "mergeByFields": {
          "values": [
            {
              "field1": "name",
              "field2": "lp_name"
            }
          ]
        },
        "joinMode": "enrichInput1",
        "options": {}
      },
      "notes": "Adds count_lp_name (earlier late payments) to each LP with the same name"
    },
    {
      "id": "8ebfab8a-8c7d-4b8f-8b74-a25deafcd520",
      "position": [
        1560,
        0
      ],
      "name": "Due date",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "parameters": {
        "operation": "addToDate",
        "magnitude": "={{ $('Upload').first().json.noticeDate }}",
        "timeUnit": "days",
        "duration": "={{ $('Upload').first().json.noticeDays }}",
        "outputFieldName": "dueDate",
        "options": {
          "includeInputFields": true
        }
      }
    },
    {
      "id": "8325abd2-290b-48c1-8c73-ffc5782e1346",
      "position": [
        1820,
        0
      ],
      "name": "Feature row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9c6c29de-f747-44f6-86a4-2b7bb470ebca",
              "name": "lp",
              "value": "={{ $json.name }}",
              "type": "string"
            },
            {
              "id": "81efa0b0-9042-4522-8724-680876703a9c",
              "name": "commitment",
              "value": "={{ $json.commitment }}",
              "type": "number"
            },
            {
              "id": "df7f9f4f-4410-450c-8ed4-c83ff919025d",
              "name": "callAmount",
              "value": "={{ ($json.commitment * $('Upload').first().json.callPct / 100).round() }}",
              "type": "number"
            },
            {
              "id": "31b18660-b891-4ef5-8941-a9b4fa35bd67",
              "name": "dueDate",
              "value": "={{ $json.dueDate.toDateTime().toISODate() }}",
              "type": "string"
            },
            {
              "id": "5663f01a-6ee2-4e5f-81a4-132f3141e111",
              "name": "priorLate",
              "value": "={{ $json.count_lp_name ?? 0 }}",
              "type": "number"
            },
            {
              "id": "e7e419f4-c5fb-436e-886d-d325b2932389",
              "name": "dataset",
              "value": "capital-call-payments",
              "type": "string"
            },
            {
              "id": "dd288735-6f63-4404-8910-33d53825cd66",
              "name": "target",
              "value": "late",
              "type": "string"
            },
            {
              "id": "82d4228f-76fb-4aa9-8c7b-9580eff80a94",
              "name": "row.lp_type",
              "value": "={{ $json.type }}",
              "type": "string"
            },
            {
              "id": "6fa0c062-0ea1-4fd1-85a7-2adbc492e588",
              "name": "row.lp_region",
              "value": "={{ $json.region }}",
              "type": "string"
            },
            {
              "id": "030a3068-cd16-4b64-848b-a5b75d4dc87b",
              "name": "row.commitment_usd",
              "value": "={{ $json.commitment }}",
              "type": "number"
            },
            {
              "id": "4e9c4d0c-aaff-4035-88f1-5466ba4ea442",
              "name": "row.call_pct_of_commitment",
              "value": "={{ $('Upload').first().json.callPct }}",
              "type": "number"
            },
            {
              "id": "4f1e57c9-72cc-4c87-8c8d-111b7525eb41",
              "name": "row.notice_days",
              "value": "={{ $('Upload').first().json.noticeDays }}",
              "type": "number"
            },
            {
              "id": "31982b2f-2b18-4fa4-8325-4d205f6c962d",
              "name": "row.due_month",
              "value": "={{ $json.dueDate.toDateTime().month }}",
              "type": "number"
            },
            {
              "id": "b6a74710-c1fa-4c53-83a0-33b0d3c1df90",
              "name": "row.prior_late_count",
              "value": "={{ $json.count_lp_name ?? 0 }}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "notes": "One row in the columns of the payment history"
    },
    {
      "id": "fe513cd8-02de-434d-8b22-5bcb95deb0b4",
      "position": [
        2080,
        0
      ],
      "name": "Predict late payment",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkPredictTabPFN",
          "cachedResultName": "predict (tabular foundation model, Prior Labs API)",
          "cachedResultUrl": "/workflow/blkPredictTabPFN"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "notes": "TabPFN (Prior Labs, own key), learned from capital-call-payments; without an account: pick predict (tabular foundation model), TabICLv2 on the workshop laptop"
    },
    {
      "id": "4ad6ed34-e93e-4551-865c-ad5d4d78f17e",
      "position": [
        2340,
        0
      ],
      "name": "Late probability",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "dc9dd15a-f199-4095-8669-7b25d06e0082",
              "name": "lateProbability",
              "value": "={{ $json.predictions[0].probabilities.yes ?? 0 }}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "87fc2a04-62d7-43db-889b-fbab23e3dfc6",
      "position": [
        2600,
        0
      ],
      "name": "Likely late?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "ea43ba0f-1b04-4180-8773-34cee7440db6",
              "leftValue": "={{ $json.lateProbability }}",
              "rightValue": 0.5,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "notes": "Change the 0.5 threshold here"
    },
    {
      "id": "39c77d47-0fe9-471b-8ead-aaac51bb4df6",
      "position": [
        780,
        300
      ],
      "name": "Late payments",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "capital_call_payments",
          "cachedResultName": "capital_call_payments"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "late",
              "condition": "eq",
              "keyValue": "yes"
            }
          ]
        },
        "returnAll": true
      },
      "alwaysOutputData": true,
      "executeOnce": true,
      "notes": "Every late payment in the history"
    },
    {
      "id": "d484e18b-8f29-4bfc-8625-fcc280830ab8",
      "position": [
        1040,
        300
      ],
      "name": "Late payments per LP",
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1.1,
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "count",
              "field": "lp_name"
            }
          ]
        },
        "fieldsToSplitBy": "lp_name",
        "options": {}
      }
    },
    {
      "id": "11fa95ba-ed8f-45e5-819c-575553358dde",
      "position": [
        2860,
        -220
      ],
      "name": "First reminder",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "parameters": {
        "operation": "subtractFromDate",
        "magnitude": "={{ $json.dueDate }}",
        "timeUnit": "days",
        "duration": 5,
        "outputFieldName": "firstReminder",
        "options": {
          "includeInputFields": true
        }
      }
    },
    {
      "id": "7760da15-2f9a-489b-821e-4be875f175f3",
      "position": [
        3120,
        -220
      ],
      "name": "Second reminder",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 2,
      "parameters": {
        "operation": "subtractFromDate",
        "magnitude": "={{ $json.dueDate }}",
        "timeUnit": "days",
        "duration": 2,
        "outputFieldName": "secondReminder",
        "options": {
          "includeInputFields": true
        }
      }
    },
    {
      "id": "64be75fc-35ab-45fb-8764-a534ed95097f",
      "position": [
        3380,
        -220
      ],
      "name": "Save reminders",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "reminders",
          "cachedResultName": "reminders"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "lp": "={{ $json.lp }}",
            "dueDate": "={{ $json.dueDate }}",
            "callPct": "={{ $('Upload').first().json.callPct }}",
            "lateProbability": "={{ $json.lateProbability }}",
            "firstReminder": "={{ $json.firstReminder.toDateTime().toISODate() }}",
            "secondReminder": "={{ $json.secondReminder.toDateTime().toISODate() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "lp",
              "displayName": "lp",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "dueDate",
              "displayName": "dueDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "callPct",
              "displayName": "callPct",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "lateProbability",
              "displayName": "lateProbability",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "firstReminder",
              "displayName": "firstReminder",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "secondReminder",
              "displayName": "secondReminder",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      }
    },
    {
      "id": "ebe4bfb4-5cc0-44aa-8dc0-e298d93400e8",
      "position": [
        3640,
        0
      ],
      "name": "All LPs",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "parameters": {
        "mode": "append"
      },
      "notes": "Waits for both branches, so every LP gets a row"
    },
    {
      "id": "7f696baa-a961-4c48-8f73-39b0dd9232e3",
      "position": [
        3900,
        0
      ],
      "name": "Result row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c85e39b3-7377-49d5-8c6a-e18ddc0292af",
              "name": "LP",
              "value": "={{ $('Late probability').item.json.lp }}",
              "type": "string"
            },
            {
              "id": "de1b0947-a282-45de-8ff0-54903a9aa42b",
              "name": "Late payment",
              "value": "={{ ($('Late probability').item.json.lateProbability * 100).round() }}%",
              "type": "string"
            },
            {
              "id": "133570ac-4f7a-4e49-8b37-b3cf08cd22ad",
              "name": "Call amount",
              "value": "=USD {{ $('Late probability').item.json.callAmount.toLocaleString('en-US') }}",
              "type": "string"
            },
            {
              "id": "cccb5d81-7edb-4f24-8d28-37a3d0262431",
              "name": "Due date",
              "value": "={{ $('Late probability').item.json.dueDate }}",
              "type": "string"
            },
            {
              "id": "ace319fc-b327-48a3-80d8-94907638b632",
              "name": "Late before",
              "value": "={{ $('Late probability').item.json.priorLate }} time(s)",
              "type": "string"
            },
            {
              "id": "8c43dedd-285d-4a27-81ba-de138f5a533c",
              "name": "Reminders",
              "value": "={{ $json.firstReminder ? $json.firstReminder + ' and ' + $json.secondReminder : 'none' }}",
              "type": "string"
            },
            {
              "id": "6cc699f3-5916-46e9-8900-06540ebf0599",
              "name": "Status",
              "value": "={{ $('Late probability').item.json.lateProbability >= 0.5 ? 'review' : 'ok' }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "notes": "One row of the results table"
    },
    {
      "id": "df09c4c2-3da3-46a2-8a1f-3808a213d083",
      "position": [
        4160,
        0
      ],
      "name": "Results table",
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "parameters": {
        "operation": "convertToHtmlTable",
        "options": {
          "customStyling": true,
          "tableAttributes": "style=\"border-collapse:collapse;font-size:14px;margin:0 auto\"",
          "headerAttributes": "style=\"background:#f2f2f2;border:1px solid #ccc;padding:6px 8px;text-align:left;vertical-align:top\"",
          "cellAttributes": "style=\"border:1px solid #ccc;padding:6px 8px;text-align:left;vertical-align:top\""
        }
      }
    },
    {
      "id": "8fb79a77-0846-48bb-879c-8dcab55d876d",
      "position": [
        4420,
        0
      ],
      "name": "Show result",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "=<div style=\"font-family:system-ui,sans-serif\"><h2 style=\"text-align:center\">Capital call forecast: result</h2>{{ $json.table }}</div>"
      },
      "webhookId": "0c770d07-7300-4827-8bf2-909a0c8c6d77"
    },
    {
      "id": "b38288a9-9224-419b-823f-18727080e34b",
      "position": [
        0,
        -470
      ],
      "name": "About",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "parameters": {
        "content": "## P4 Capital call forecast (TabPFN)\nRead the investor register, the LLM extracts the LPs, one item per LP with its earlier late payments from the history table, the due date from the form, TabPFN (Prior Labs, own free key) predicts the probability of a late payment, likely late payers get reminders 5 and 2 days before the due date. No code.",
        "width": 660,
        "height": 260,
        "color": 7
      }
    }
  ],
  "connections": {
    "Upload": {
      "main": [
        [
          {
            "node": "Read document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read document": {
      "main": [
        [
          {
            "node": "Fields to extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fields to extract": {
      "main": [
        [
          {
            "node": "Extract LP register",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract LP register": {
      "main": [
        [
          {
            "node": "One item per LP",
            "type": "main",
            "index": 0
          },
          {
            "node": "Late payments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per LP": {
      "main": [
        [
          {
            "node": "Add late payments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add late payments": {
      "main": [
        [
          {
            "node": "Due date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Due date": {
      "main": [
        [
          {
            "node": "Feature row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Feature row": {
      "main": [
        [
          {
            "node": "Predict late payment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Predict late payment": {
      "main": [
        [
          {
            "node": "Late probability",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Late probability": {
      "main": [
        [
          {
            "node": "Likely late?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Late payments": {
      "main": [
        [
          {
            "node": "Late payments per LP",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "First reminder": {
      "main": [
        [
          {
            "node": "Second reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Second reminder": {
      "main": [
        [
          {
            "node": "Save reminders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "All LPs": {
      "main": [
        [
          {
            "node": "Result row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Result row": {
      "main": [
        [
          {
            "node": "Results table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Results table": {
      "main": [
        [
          {
            "node": "Show result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Late payments per LP": {
      "main": [
        [
          {
            "node": "Add late payments",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Likely late?": {
      "main": [
        [
          {
            "node": "First reminder",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "All LPs",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Save reminders": {
      "main": [
        [
          {
            "node": "All LPs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true
  }
}
