{
  "id": "3q0cLHbJTr76ptnY",
  "name": "Auto Wealth Plan Generator",
  "tags": [],
  "nodes": [
    {
      "id": "6728a015-cce3-432a-8411-919463d2564a",
      "name": "Set - Assign Allocation",
      "type": "n8n-nodes-base.set",
      "position": [
        2512,
        496
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c124e4a8-efb1-46e9-be10-1189556577cd",
              "name": "Equity",
              "type": "number",
              "value": "={{ $json[\"Risk Appetite\"] === \"Low\" ? 30 :\n   $json[\"Risk Appetite\"] === \"Medium\" ? 50 : 70 }}"
            },
            {
              "id": "0b882a94-bdb3-4aa7-b6a9-c714cd79e1c5",
              "name": "Debt",
              "type": "number",
              "value": "={{ $json[\"Risk Appetite\"] === \"Low\" ? 50 :\n   $json[\"Risk Appetite\"] === \"Medium\" ? 30 : 20 }}"
            },
            {
              "id": "1b89fd5c-6e87-4bd3-bc5a-cd36d554e6b8",
              "name": "Gold",
              "type": "number",
              "value": "={{ $json[\"Risk Appetite\"] === \"Low\" ? 20 :\n   $json[\"Risk Appetite\"] === \"Medium\" ? 20 : 10 }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "notesInFlow": true,
      "typeVersion": 3.4,
      "alwaysOutputData": false
    },
    {
      "id": "776067f5-a82a-4ca3-9ba2-49c6da99977e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        96
      ],
      "parameters": {
        "width": 1024,
        "height": 784,
        "content": "# Auto Wealth Plan Generator\nThis automated workflow acts as a **personalized financial advisor**, instantly transforming form submissions into actionable investment plans. It evaluates user eligibility, calculates optimized portfolio allocations across equity, debt, and gold based on risk appetite, and leverages AI to draft detailed strategies tailored for the Indian market. The entire process requires zero manual intervention, seamlessly reading incoming data and writing the final reports back to Google Sheets.\n\n## How It Works\nThe process begins with **Data Intake**, which is triggered automatically whenever a new form submission is detected in the connected spreadsheet. A dedicated code node ensures efficiency by isolating only the **most recent row** for processing. The system then moves into **Validation**, where it rigorously verifies user eligibility based on age, income-to-expense ratios, and a **minimum net income threshold** of \u20b91,000; any invalid entries immediately trigger an **alert email**. For valid users, the workflow performs **Calculations** to establish a monthly investment budget\u2014set at **30% of net income**\u2014and distributes it across **Equity, Debt, and Gold** according to the user's risk appetite. This structured data is then sent for **AI Generation**, where a **Llama-3 model** via Groq acts as a financial advisor to produce a customized plan in **JSON format**. Finally, the **Storage** phase parses this output and appends the clean, formatted strategy into the designated **master Google Sheet**.\n\n\n## Setup Steps\n* **Google Sheets (Trigger)**: Connect your Google account and select your specific \"Form Responses\" spreadsheet.\n* **Gmail**: Connect your account in the \"enter valid details\" node so the workflow can send automated bounce emails for invalid inputs.\n* **Groq API**: Open the \"wealth advice\" language model node and select/add your Groq API credentials.\n* **Google Sheets (Action)**: Open the \"Save Wealth plan\" node, connect your account, and ensure the schema columns (Name, Income, Risk, Summary, etc.) match your destination sheet exactly."
      },
      "typeVersion": 1
    },
    {
      "id": "03a78a90-2bb2-4ba5-af6e-e018b6d8be97",
      "name": "validate input",
      "type": "n8n-nodes-base.if",
      "position": [
        1776,
        528
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "25568b84-1c07-43e8-8f03-1285c3477b15",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json['Monthly Income'] }}",
              "rightValue": 0
            },
            {
              "id": "46970600-8760-498c-b302-0711d0ee7e31",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json['Monthly Expenses'] }}",
              "rightValue": 0
            },
            {
              "id": "aeebd7ce-36de-4501-ab6c-9016d12f0c3c",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.Age }}",
              "rightValue": 18
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "9cfaf322-4398-4d38-8454-fa1814076e97",
      "name": "net income check",
      "type": "n8n-nodes-base.if",
      "position": [
        2192,
        512
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7b72ffd2-b816-4c28-b988-517114f4d987",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.net_income }}",
              "rightValue": 1000
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "554797a1-facb-41e2-a655-d6926064aa08",
      "name": "Investment Calculation",
      "type": "n8n-nodes-base.set",
      "position": [
        2736,
        496
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1e91af57-4dd7-4963-8cee-17133d033892",
              "name": "Monthly Investment",
              "type": "number",
              "value": "={{\n  $json.net_income * 0.3\n}}"
            },
            {
              "id": "b629953b-8427-4bd4-ab8b-28a771b820f5",
              "name": "Equity Amount",
              "type": "number",
              "value": "={{   ($json.net_income * 0.3) * ($json.Equity / 100) }}"
            },
            {
              "id": "30b0f635-b117-4996-ab17-82c0b5f038c8",
              "name": "Debt Amount",
              "type": "number",
              "value": "={{\n  ($json.net_income * 0.3) * ($json.Debt / 100)\n}}"
            },
            {
              "id": "6ca7c79e-adbd-47ad-aa35-fab1548937d0",
              "name": "Gold Amount",
              "type": "number",
              "value": "={{   ($json.net_income * 0.3) * ($json.Gold / 100) }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "d9404c51-f429-49c0-bcaa-3178c7e4919f",
      "name": "AI Wealth Advisor",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3104,
        496
      ],
      "parameters": {
        "text": "={{\n`You are a professional financial advisor.\n\nIMPORTANT RULES:\n- Use ONLY real values from input\n- No placeholders\n- Give VERY SPECIFIC and PRACTICAL advice\n- Include exact fund categories and real examples decided by AI\n- Maintain numerical consistency in all calculations\n- Round all monetary values to the nearest rupee\n- Output MUST be in valid JSON\n\n----------------------------------\n\nCLIENT DETAILS:\nName: ${$json.Name}\nAge: ${$json.Age}\n\nFINANCIAL DATA:\nMonthly Income: \u20b9${$json[\"Monthly Income\"]}\nMonthly Expenses: \u20b9${$json['Monthly Expenses']}\nNet Income: \u20b9${$json.net_income}\n\nRISK PROFILE:\n${$json[\"Risk Appetite\"]}\n\nPORTFOLIO ALLOCATION:\nEquity: ${$json.Equity}%\nDebt: ${$json.Debt}%\nGold: ${$json.Gold}%\n\nINVESTMENT PLAN:\nMonthly Investment: \u20b9${$json[\"Monthly Investment\"]}\nEquity Investment: \u20b9${$json[\"Equity Amount\"]}\nDebt Investment: \u20b9${$json[\"Debt Amount\"]}\nGold Investment: \u20b9${$json[\"Gold Amount\"]}\n\nFINANCIAL GOALS:\n${$json[\"Financial Goals\"]}\n\n----------------------------------\n\nReturn ONLY valid JSON in this format:\n\n{\n  \"investment_summary\": \"\",\n  \"asset_allocation\": \"\",\n  \"monthly_strategy\": \"\",\n  \"fund_recommendations\": \"\",\n  \"financial_advice\": \"\",\n  \"advanced_strategy\": \"\"\n}\n\n----------------------------------\n\nDETAILED INSTRUCTIONS:\n\n1. investment_summary:\n- Include income, expenses, net income, and investment amount\n- Mention financial goal clearly\n\n2. asset_allocation:\n- Explain WHY allocation fits risk profile\n- Link allocation to goal timeline\n\n3. monthly_strategy:\n- MUST include exact breakdown with correct math\n- Round all amounts to nearest rupee\n- Ensure the sum of splits equals total investment\n- Example format:\n  Equity \u20b95040 split into Large cap \u20b92520, Mid cap \u20b91260, Index \u20b91260\n  Debt \u20b91440 split into Liquid \u20b9720, Short-term \u20b9720\n  Gold \u20b9720\n\n4. fund_recommendations:\n- Include only real fund examples chosen by AI as best fit\n- Examples can include large cap, mid cap, index funds, debt, liquid funds, or Gold ETF\n\n5. financial_advice:\n- Give step-by-step actions\n- Include SIP, goal tracking, expense optimization\n\n6. advanced_strategy:\n- MUST include:\n  SIP discipline\n  Rebalancing every 6\u201312 months\n  Emergency fund (3\u20136 months expenses)\n  Tax-saving suggestion (ELSS if relevant)\n\n----------------------------------\n\nSTRICT RULES:\n\n- No markdown\n- No bullet symbols (*, -, #)\n- No text outside JSON\n- Ensure JSON is valid and parsable\n- Round all monetary values to nearest rupee\n- Do NOT give generic advice\n- If unsure, return empty strings but keep JSON format\n\n`}}",
        "options": {
          "systemMessage": "You are an expert financial advisor specializing in Indian personal finance.\n\nCRITICAL RULES:\n- Always return output in valid JSON only when requested\n- Never return markdown (no **, no #, no bullet symbols)\n- Never add text outside JSON\n\nADVISORY RULES:\n- Give highly practical and actionable advice\n- Use real numbers provided in input\n- Suggest specific mutual fund categories AND real example funds\n- Focus on SIP-based investing\n- Include goal-based planning\n- Keep advice realistic for Indian investors\n\nOUTPUT QUALITY:\n- Be detailed, not generic\n- Include exact allocation breakdowns\n- Include clear investment strategy\n- Include advanced planning (rebalancing, emergency fund, tax saving)"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "800c2bf1-8cea-4936-8cfb-bbe933ca2c73",
      "name": "Save Wealth plan",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3600,
        496
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('Investment Calculation').item.json.Name }}",
            "Risk": "={{ $('Investment Calculation').item.json['Risk Appetite'] }}",
            "Advice": "={{ $json.advice }}",
            "Income": "={{ $('Investment Calculation').item.json.net_income }}",
            "Summary": "={{ $json.investment_summary }}",
            "Strategy": "={{ $json.strategy }}",
            "Allocation": "={{ $json.allocation }}",
            "Recommendations": "={{ $json.funds }}",
            "advanced Strategy": "={{ $json.advanced_strategy }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Income",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Income",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Risk",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Risk",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Allocation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Allocation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Strategy",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Strategy",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Recommendations",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Recommendations",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Advice",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Advice",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "advanced Strategy",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "advanced Strategy",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1837873263,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17LHhfIzn3XM_LjY87HKAj3vD4qA8oV9hpI2ORD2RqcM/edit#gid=1837873263",
          "cachedResultName": "Sheet5"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "17LHhfIzn3XM_LjY87HKAj3vD4qA8oV9hpI2ORD2RqcM",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17LHhfIzn3XM_LjY87HKAj3vD4qA8oV9hpI2ORD2RqcM/edit?usp=drivesdk",
          "cachedResultName": "wealth planner sheet"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b6e4af6c-0de2-4010-bb12-0c1abfd7da27",
      "name": "enter valid details",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2080,
        720
      ],
      "parameters": {
        "sendTo": "={{ $json.Email }}",
        "message": "=Please enter valid details the monthly amount should be more than 1000 you enterted {{ $json['Monthly Income'] }} also check net income should be more than 1000 your net income is {{ $json.net_income }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "Invalid details",
        "emailType": "text"
      },
      "typeVersion": 2.2
    },
    {
      "id": "65ea92e3-5954-410e-a3c1-717223728781",
      "name": "wealth advice",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        3104,
        656
      ],
      "parameters": {
        "model": "llama-3.3-70b-versatile",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "476aa3a1-4b25-44f2-ac88-10639934c140",
      "name": "AI output parser",
      "type": "n8n-nodes-base.code",
      "position": [
        3392,
        496
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  let parsed;\n\n  try {\n    parsed = JSON.parse(item.json.output);\n  } catch (e) {\n    parsed = {};\n  }\n\n  return {\n    json: {\n      ...item.json,\n\n      investment_summary: parsed.investment_summary || \"\",\n      allocation: parsed.asset_allocation || \"\",\n      strategy: parsed.monthly_strategy || \"\",\n      funds: parsed.fund_recommendations || \"\",\n      advice: parsed.financial_advice || \"\",\n      advanced_strategy: parsed.advanced_strategy || \"\",\n\n      status: \"generated\",\n      created_at: new Date().toISOString()\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "3076b531-29f6-4155-a1b6-dc474e0c1cdc",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 560,
        "content": "# Data Intake\nTriggers every time a new response is added to the Google Form and isolates the most recent submission data for processing."
      },
      "typeVersion": 1
    },
    {
      "id": "aec99458-0e6b-4e1f-bd96-a8647c1579c0",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2448,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 560,
        "content": "# Risk-Based Calculations\nSegregates users into Risk Buckets. It then applies the 30% investment rule to the net income and splits the capital across Equity, Debt, and Gold based on the assigned risk percentages."
      },
      "typeVersion": 1
    },
    {
      "id": "563cac51-1de0-4d95-a8ec-835af6df1c67",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3056,
        336
      ],
      "parameters": {
        "color": 7,
        "width": 752,
        "height": 544,
        "content": "# AI Generation & Export\nPasses the raw calculations to a Llama-3 model to draft a professional financial report in JSON. The 'AI Output Parser' cleans the text before appending the final strategy to the Google Sheet."
      },
      "typeVersion": 1
    },
    {
      "id": "2a147426-95b4-4e35-9b0b-155094b56d32",
      "name": "Last row of sheet",
      "type": "n8n-nodes-base.code",
      "position": [
        1504,
        528
      ],
      "parameters": {
        "jsCode": "return [items[items.length - 1]];"
      },
      "typeVersion": 2
    },
    {
      "id": "b6923dc6-2c49-4ef3-8fe3-94af0a2a829b",
      "name": "net income calculation",
      "type": "n8n-nodes-base.set",
      "position": [
        1984,
        512
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "112eb7dd-de66-4f58-8b8f-71806f85e91f",
              "name": "net_income",
              "type": "number",
              "value": "={{ $json['Monthly Income']- $json['Monthly Expenses']}}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "3b01bf92-2984-4080-a1a3-13cb3c79b85f",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1728,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 560,
        "content": "# Validation & Logic\nValidates user eligibility (age 18+ and positive income), calculates net monthly income, and ensures the available funds meet the minimum \u20b91000 threshold for investment."
      },
      "typeVersion": 1
    },
    {
      "id": "01ca6210-50d7-4390-b1ed-af3db1d1d24e",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1120,
        528
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3c0859a6-46bb-4a3c-a10f-d06e4bbd4d40",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1312,
        528
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1545407485,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17LHhfIzn3XM_LjY87HKAj3vD4qA8oV9hpI2ORD2RqcM/edit#gid=1545407485",
          "cachedResultName": "Form Responses 2"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "17LHhfIzn3XM_LjY87HKAj3vD4qA8oV9hpI2ORD2RqcM",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17LHhfIzn3XM_LjY87HKAj3vD4qA8oV9hpI2ORD2RqcM/edit?usp=drivesdk",
          "cachedResultName": "wealth planner sheet"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "2c17b47c-d0b1-46e9-ade1-cefba107ed24",
  "nodeGroups": [],
  "connections": {
    "wealth advice": {
      "ai_languageModel": [
        [
          {
            "node": "AI Wealth Advisor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "validate input": {
      "main": [
        [
          {
            "node": "net income calculation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "enter valid details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI output parser": {
      "main": [
        [
          {
            "node": "Save Wealth plan",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "net income check": {
      "main": [
        [
          {
            "node": "Set - Assign Allocation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "enter valid details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Wealth Advisor": {
      "main": [
        [
          {
            "node": "AI output parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Last row of sheet": {
      "main": [
        [
          {
            "node": "validate input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Last row of sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Investment Calculation": {
      "main": [
        [
          {
            "node": "AI Wealth Advisor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "net income calculation": {
      "main": [
        [
          {
            "node": "net income check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set - Assign Allocation": {
      "main": [
        [
          {
            "node": "Investment Calculation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}