{
  "name": "Financial Counselling: Crisis to Action",
  "version": "1.0.0",
  "description": "Complete AI-assisted financial counselling workflow for gambling harm - from intake to personalized action plan with verified research and human-in-the-loop design",
  "category": "solutions",
  "tags": ["financial-counselling", "gambling-harm", "human-centered", "multi-provider"],
  "input_schema": {
    "type": "object",
    "properties": {
      "contact_method": {
        "type": "string",
        "enum": ["email", "form", "phone_transcript", "in_person_notes"],
        "description": "How the client made contact"
      },
      "contact_content": {
        "type": "string",
        "description": "The client's initial message, form submission, or counsellor notes"
      },
      "client_location": {
        "type": "object",
        "properties": {
          "state": { "type": "string", "description": "Australian state (VIC, NSW, QLD, etc.)" },
          "suburb": { "type": "string" },
          "postcode": { "type": "string" }
        }
      },
      "known_creditors": {
        "type": "array",
        "items": { "type": "string" },
        "description": "List of known banks/lenders if mentioned"
      },
      "counsellor_id": {
        "type": "string",
        "description": "Assigned counsellor identifier"
      }
    },
    "required": ["contact_content"]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "counsellor_briefing": { "type": "object" },
      "client_materials": { "type": "object" },
      "research_citations": { "type": "array" },
      "risk_assessment": { "type": "object" },
      "action_plan": { "type": "object" }
    }
  },
  "stages": [
    {
      "id": "validate-input",
      "name": "Validate Input",
      "component_type": "schema_validate",
      "config": {
        "data": "{{input}}",
        "schema": {
          "type": "object",
          "required": ["contact_content"],
          "properties": {
            "contact_content": {
              "type": "string",
              "minLength": 10
            }
          }
        }
      },
      "depends_on": [],
      "position": { "x": 100, "y": 50 }
    },
    {
      "id": "parse-intake",
      "name": "Empathetic Intake Parser",
      "component_type": "generator",
      "config": {
        "provider": "anthropic",
        "model": "claude-sonnet-4-20250514",
        "temperature": 0.3,
        "system_prompt": "You are supporting a financial counsellor helping someone affected by gambling harm. Approach this with deep compassion - seeking help takes enormous courage.\n\nGuidelines:\n- Use person-first language (\"person experiencing gambling harm\")\n- Extract information without judgment\n- Note strengths and supports alongside challenges\n- Acknowledge the difficulty of this situation\n- If you detect crisis indicators (self-harm, suicidal thoughts, domestic violence), flag immediately with crisis_detected: true\n\nNever:\n- Use shame-based language\n- Make assumptions about character\n- Minimize the person's experience\n\nExtract and return as JSON:\n{\n  \"client_situation\": { \"summary\": \"\", \"strengths_noted\": [], \"support_systems\": [] },\n  \"financial_snapshot\": { \"debts_mentioned\": [], \"income_sources\": [], \"dependents\": 0, \"housing_status\": \"\" },\n  \"gambling_context\": { \"pattern_indicators\": \"\", \"duration_mentioned\": \"\", \"seeking_help_motivation\": \"\" },\n  \"immediate_concerns\": { \"threats\": [], \"urgency_indicators\": [] },\n  \"crisis_detected\": false,\n  \"crisis_type\": null\n}",
        "prompt": "Please carefully read this client contact and extract the relevant information with empathy and without judgment:\n\nContact Method: {{input.contact_method | default('unknown')}}\n\nClient Message:\n{{input.contact_content}}\n\nRemember: This person has shown courage in reaching out. Extract information to help the counsellor support them effectively."
      },
      "depends_on": ["validate-input"],
      "position": { "x": 100, "y": 150 }
    },
    {
      "id": "detect-crisis",
      "name": "Crisis Detection",
      "component_type": "generator",
      "config": {
        "provider": "anthropic",
        "model": "claude-sonnet-4-20250514",
        "temperature": 0.1,
        "system_prompt": "You are a crisis detection specialist. Your ONLY job is to identify if this client needs IMMEDIATE human intervention.\n\nCRISIS indicators requiring IMMEDIATE escalation:\n- Suicidal ideation or self-harm mentions\n- Domestic violence or safety concerns\n- Homelessness within 24-48 hours\n- Children at immediate risk\n- Severe mental health crisis\n\nReturn JSON:\n{\n  \"crisis_detected\": boolean,\n  \"crisis_type\": \"suicide_risk\" | \"domestic_violence\" | \"child_safety\" | \"imminent_homelessness\" | \"mental_health_crisis\" | null,\n  \"crisis_severity\": \"immediate\" | \"urgent\" | \"elevated\" | \"standard\",\n  \"escalation_required\": boolean,\n  \"escalation_reason\": string | null,\n  \"safe_to_continue_pipeline\": boolean\n}\n\nWhen in doubt, escalate. Human lives are more important than efficiency.",
        "prompt": "Review this intake assessment for crisis indicators:\n\n{{upstream.parse-intake.result}}\n\nOriginal message:\n{{input.contact_content}}\n\nDetermine if immediate human intervention is required."
      },
      "depends_on": ["parse-intake"],
      "position": { "x": 100, "y": 250 }
    },
    {
      "id": "crisis-gate",
      "name": "Crisis Routing Gate",
      "component_type": "router",
      "config": {
        "routes": [
          {
            "name": "immediate-escalation",
            "condition": "{{upstream.detect-crisis.result.escalation_required == true}}",
            "stages": ["human-escalation-immediate"]
          },
          {
            "name": "continue-assessment",
            "condition": "{{upstream.detect-crisis.result.safe_to_continue_pipeline == true}}",
            "stages": ["calculate-risk-score"]
          }
        ],
        "default_route": "continue-assessment"
      },
      "depends_on": ["detect-crisis"],
      "position": { "x": 100, "y": 350 }
    },
    {
      "id": "human-escalation-immediate",
      "name": "IMMEDIATE Human Escalation",
      "component_type": "logger",
      "config": {
        "level": "error",
        "message": "CRISIS DETECTED - IMMEDIATE HUMAN INTERVENTION REQUIRED",
        "data": {
          "crisis_type": "{{upstream.detect-crisis.result.crisis_type}}",
          "crisis_severity": "{{upstream.detect-crisis.result.crisis_severity}}",
          "escalation_reason": "{{upstream.detect-crisis.result.escalation_reason}}",
          "client_summary": "{{upstream.parse-intake.result.client_situation.summary}}",
          "action_required": "Contact client immediately via phone. Do not rely on email/async communication."
        }
      },
      "depends_on": ["crisis-gate"],
      "position": { "x": 400, "y": 350 }
    },
    {
      "id": "calculate-risk-score",
      "name": "Risk Assessment (Cross-Validation)",
      "component_type": "generator",
      "config": {
        "provider": "openai",
        "model": "gpt-4o",
        "temperature": 0.2,
        "system_prompt": "You are a financial distress risk assessor. Using a DIFFERENT model for cross-validation, calculate a risk score based on objective financial indicators.\n\nScoring Framework (0-10):\n- 0-2: Stable - manageable debt, steady income\n- 3-4: Moderate concern - some financial stress but resources available\n- 5-6: Elevated - multiple debts, uncertain income, some urgent needs\n- 7-8: High - significant distress, immediate threats, limited resources\n- 9-10: Critical - crisis level, multiple urgent threats, immediate intervention needed\n\nFactors to consider:\n- Debt-to-income indicators\n- Housing security\n- Dependent care responsibilities\n- Utility/service disconnection threats\n- Employment stability\n- Available support systems\n\nReturn JSON:\n{\n  \"risk_score\": number (0-10),\n  \"risk_level\": \"stable\" | \"moderate\" | \"elevated\" | \"high\" | \"critical\",\n  \"primary_concerns\": [top 3 concerns],\n  \"protective_factors\": [strengths/supports identified],\n  \"priority_areas\": [\"housing\", \"utilities\", \"income\", \"debts\"],\n  \"recommended_urgency\": \"standard\" | \"priority\" | \"urgent\"\n}",
        "prompt": "Assess financial distress risk for this client:\n\nIntake Summary:\n{{upstream.parse-intake.result}}\n\nProvide an objective risk assessment to help prioritize counsellor response."
      },
      "depends_on": ["crisis-gate"],
      "position": { "x": 100, "y": 450 }
    },
    {
      "id": "research-hardship-programs",
      "name": "Research: Hardship Programs",
      "component_type": "generator",
      "config": {
        "provider": "perplexity",
        "model": "sonar-pro",
        "temperature": 0.1,
        "system_prompt": "You are a research assistant finding current hardship programs. CRITICAL: Every program you mention MUST include a citation URL. If you cannot find a verifiable source, do not include the program.\n\nReturn JSON:\n{\n  \"programs\": [\n    {\n      \"name\": \"Program Name\",\n      \"provider\": \"Organization\",\n      \"eligibility\": \"Brief eligibility criteria\",\n      \"benefits\": \"What it provides\",\n      \"how_to_apply\": \"Application process\",\n      \"citation_url\": \"https://...\",\n      \"verified\": true\n    }\n  ],\n  \"research_date\": \"2024-12-15\",\n  \"location_searched\": \"state/region\"\n}",
        "prompt": "Find current utility and financial hardship programs available in {{input.client_location.state | default('Victoria')}} Australia for someone experiencing gambling-related financial hardship.\n\nSearch for:\n1. Utility relief grants (electricity, gas, water)\n2. Energy hardship programs\n3. Rental assistance programs\n4. Emergency relief funds\n\nONLY include programs with verifiable sources. Include citation URLs for each."
      },
      "depends_on": ["calculate-risk-score"],
      "position": { "x": 400, "y": 450 }
    },
    {
      "id": "research-local-services",
      "name": "Research: Local Support Services",
      "component_type": "generator",
      "config": {
        "provider": "perplexity",
        "model": "sonar-pro",
        "temperature": 0.1,
        "system_prompt": "You are a research assistant finding gambling support services. CRITICAL: Every service you mention MUST include a citation URL or official contact. If you cannot verify a service exists, do not include it.\n\nReturn JSON:\n{\n  \"services\": [\n    {\n      \"name\": \"Service Name\",\n      \"type\": \"gambling_support\" | \"financial_counselling\" | \"mental_health\" | \"emergency_relief\",\n      \"location\": \"Suburb/Region\",\n      \"contact\": \"Phone/website\",\n      \"services_offered\": [\"list of services\"],\n      \"citation_url\": \"https://...\",\n      \"verified\": true\n    }\n  ],\n  \"national_helplines\": [\n    { \"name\": \"\", \"number\": \"\", \"hours\": \"\", \"citation_url\": \"\" }\n  ]\n}",
        "prompt": "Find gambling support and financial counselling services near {{input.client_location.suburb | default('')}} {{input.client_location.state | default('Victoria')}} Australia.\n\nSearch for:\n1. Gambler's Help services with financial counselling\n2. NILS (No Interest Loan Scheme) providers\n3. Good Shepherd financial services\n4. Local community support services\n5. National gambling helpline\n\nONLY include services with verifiable contact information. Include citation URLs."
      },
      "depends_on": ["calculate-risk-score"],
      "position": { "x": 400, "y": 550 }
    },
    {
      "id": "research-legal-protections",
      "name": "Research: Legal Protections",
      "component_type": "generator",
      "config": {
        "provider": "perplexity",
        "model": "sonar-pro",
        "temperature": 0.1,
        "system_prompt": "You are a research assistant finding consumer protection information. CRITICAL: Every legal protection or right you mention MUST include a citation URL to official government or legal sources.\n\nReturn JSON:\n{\n  \"protections\": [\n    {\n      \"name\": \"Protection/Right\",\n      \"legislation\": \"Act/Regulation name\",\n      \"summary\": \"Plain language explanation\",\n      \"how_to_use\": \"How client can invoke this protection\",\n      \"citation_url\": \"https://...\"\n    }\n  ],\n  \"hardship_rights\": {\n    \"description\": \"Rights to request hardship variations\",\n    \"citation_url\": \"\"\n  },\n  \"debt_collection_limits\": {\n    \"description\": \"What debt collectors cannot do\",\n    \"citation_url\": \"\"\n  }\n}",
        "prompt": "Find current consumer protections for gambling debts in Australia.\n\nSearch for:\n1. National Consumer Credit Protection Act hardship provisions\n2. ACCC debt collection guidelines\n3. State-specific consumer protections in {{input.client_location.state | default('Victoria')}}\n4. Rights when dealing with creditors\n5. Hardship variation request rights\n\nONLY include information from official government or legal sources. Include citation URLs."
      },
      "depends_on": ["calculate-risk-score"],
      "position": { "x": 400, "y": 650 }
    },
    {
      "id": "research-creditor-policies",
      "name": "Research: Creditor Hardship Policies",
      "component_type": "generator",
      "config": {
        "provider": "perplexity",
        "model": "sonar-pro",
        "temperature": 0.1,
        "system_prompt": "You are a research assistant finding bank and lender hardship policies. CRITICAL: Every policy you mention MUST include a citation URL to the official bank/lender page.\n\nReturn JSON:\n{\n  \"creditor_policies\": [\n    {\n      \"creditor\": \"Bank/Lender name\",\n      \"hardship_program\": \"Program name\",\n      \"contact_method\": \"How to apply\",\n      \"what_they_offer\": [\"payment pause\", \"reduced payments\", etc.],\n      \"gambling_specific\": true/false,\n      \"citation_url\": \"https://...\"\n    }\n  ],\n  \"general_advice\": \"How to approach creditors about gambling-related hardship\"\n}",
        "prompt": "Find hardship policies for major Australian banks and any specific creditors mentioned.\n\nCreditors to research:\n- Commonwealth Bank (CBA)\n- NAB\n- ANZ\n- Westpac\n{{#if input.known_creditors}}\n- {{input.known_creditors | join(', ')}}\n{{/if}}\n\nSearch for:\n1. Financial hardship programs\n2. Gambling-specific hardship support\n3. How to request hardship assistance\n4. What relief options are typically available\n\nONLY include policies with verifiable official sources. Include citation URLs."
      },
      "depends_on": ["calculate-risk-score"],
      "position": { "x": 400, "y": 750 }
    },
    {
      "id": "validate-research",
      "name": "Validate Research Citations",
      "component_type": "schema_validate",
      "config": {
        "data": {
          "hardship_programs": "{{upstream.research-hardship-programs.result}}",
          "local_services": "{{upstream.research-local-services.result}}",
          "legal_protections": "{{upstream.research-legal-protections.result}}",
          "creditor_policies": "{{upstream.research-creditor-policies.result}}"
        },
        "schema": {
          "type": "object",
          "properties": {
            "hardship_programs": { "type": "object" },
            "local_services": { "type": "object" },
            "legal_protections": { "type": "object" },
            "creditor_policies": { "type": "object" }
          }
        },
        "on_fail": "warn"
      },
      "depends_on": ["research-hardship-programs", "research-local-services", "research-legal-protections", "research-creditor-policies"],
      "position": { "x": 700, "y": 600 }
    },
    {
      "id": "synthesize-action-plan",
      "name": "Synthesize Action Plan",
      "component_type": "synthesizer",
      "config": {
        "provider": "anthropic",
        "model": "claude-sonnet-4-20250514",
        "temperature": 0.3,
        "system_prompt": "You are creating an action plan for a financial counsellor to review and deliver to their client.\n\nPrioritization Framework:\n1. IMMEDIATE: Safety and crisis prevention\n2. URGENT: Income protection, essential services at risk\n3. IMPORTANT: Housing stability, utility arrangements\n4. STANDARD: Non-essential debt management\n\nTone Guidelines:\n- Hope-focused, not problem-focused\n- Acknowledge small wins and strengths\n- Build on client's existing supports\n- Frame as partnership, not prescription\n- Use plain language, avoid jargon\n\nEvery action item needs:\n- Clear, specific next step\n- Who is responsible (counsellor vs client)\n- Realistic timeline\n- Citation/source if involving external service\n\nReturn JSON:\n{\n  \"action_plan\": {\n    \"immediate_actions\": [{\"action\": \"\", \"owner\": \"counsellor|client|both\", \"timeline\": \"\", \"resources_needed\": \"\"}],\n    \"urgent_actions\": [...],\n    \"important_actions\": [...],\n    \"standard_actions\": [...]\n  },\n  \"quick_wins\": [\"Achievable steps to build momentum\"],\n  \"referrals\": [{\"service\": \"\", \"reason\": \"\", \"contact\": \"\", \"citation_url\": \"\"}],\n  \"follow_up_schedule\": {\"next_contact\": \"\", \"check_in_frequency\": \"\"}\n}",
        "inputs": [
          { "key": "intake", "value": "{{upstream.parse-intake.result}}" },
          { "key": "risk", "value": "{{upstream.calculate-risk-score.result}}" },
          { "key": "hardship_programs", "value": "{{upstream.research-hardship-programs.result}}" },
          { "key": "local_services", "value": "{{upstream.research-local-services.result}}" },
          { "key": "legal_protections", "value": "{{upstream.research-legal-protections.result}}" },
          { "key": "creditor_policies", "value": "{{upstream.research-creditor-policies.result}}" }
        ],
        "prompt": "Create a prioritized action plan based on all the research gathered.\n\nClient Situation:\n{{intake}}\n\nRisk Assessment:\n{{risk}}\n\nAvailable Hardship Programs:\n{{hardship_programs}}\n\nLocal Support Services:\n{{local_services}}\n\nLegal Protections:\n{{legal_protections}}\n\nCreditor Policies:\n{{creditor_policies}}\n\nCreate a realistic, achievable action plan that builds on the client's strengths and available resources. Include citation URLs for all external referrals."
      },
      "depends_on": ["validate-research"],
      "position": { "x": 700, "y": 750 }
    },
    {
      "id": "generate-counsellor-briefing",
      "name": "Generate Counsellor Briefing",
      "component_type": "generator",
      "config": {
        "provider": "anthropic",
        "model": "claude-sonnet-4-20250514",
        "temperature": 0.3,
        "system_prompt": "You are preparing a comprehensive briefing for a financial counsellor before their client meeting.\n\nThis briefing should help the counsellor:\n1. Understand the client's situation with empathy\n2. Have all research at their fingertips\n3. Know the recommended approach\n4. Be prepared for the conversation\n\nReturn JSON:\n{\n  \"client_summary\": {\n    \"situation_overview\": \"2-3 sentence empathetic summary\",\n    \"strengths_to_acknowledge\": [],\n    \"sensitive_areas\": [\"Topics to approach carefully\"]\n  },\n  \"research_summary\": {\n    \"key_programs\": [{\"name\": \"\", \"why_relevant\": \"\", \"citation_url\": \"\"}],\n    \"key_services\": [{\"name\": \"\", \"why_relevant\": \"\", \"contact\": \"\"}],\n    \"key_rights\": [{\"right\": \"\", \"how_to_use\": \"\"}]\n  },\n  \"conversation_guide\": {\n    \"opening_approach\": \"Suggested way to start\",\n    \"key_points_to_cover\": [],\n    \"questions_to_explore\": [],\n    \"things_to_avoid\": []\n  },\n  \"action_plan_summary\": \"Brief overview of recommended actions\",\n  \"all_citations\": [{\"source\": \"\", \"url\": \"\", \"what_for\": \"\"}]\n}",
        "prompt": "Create a counsellor briefing based on:\n\nClient Intake:\n{{upstream.parse-intake.result}}\n\nRisk Assessment:\n{{upstream.calculate-risk-score.result}}\n\nAction Plan:\n{{upstream.synthesize-action-plan.result}}\n\nAll Research:\n- Hardship Programs: {{upstream.research-hardship-programs.result}}\n- Local Services: {{upstream.research-local-services.result}}\n- Legal Protections: {{upstream.research-legal-protections.result}}\n- Creditor Policies: {{upstream.research-creditor-policies.result}}\n\nPrepare a briefing that helps the counsellor support this client with empathy and confidence."
      },
      "depends_on": ["synthesize-action-plan"],
      "position": { "x": 700, "y": 850 }
    },
    {
      "id": "generate-client-materials",
      "name": "Generate Client Materials",
      "component_type": "generator",
      "config": {
        "provider": "anthropic",
        "model": "claude-sonnet-4-20250514",
        "temperature": 0.4,
        "system_prompt": "You are creating materials that the counsellor will share with the client AFTER their conversation.\n\nThese materials should:\n- Use simple, clear language (aim for 8th grade reading level)\n- Be encouraging and hopeful\n- Include only verified, actionable information\n- Have clear next steps the client can take\n- Not overwhelm - prioritize the most important items\n\nReturn JSON:\n{\n  \"action_summary\": {\n    \"title\": \"Your Next Steps\",\n    \"intro\": \"Encouraging opening message\",\n    \"priority_actions\": [\n      {\n        \"what\": \"Clear action description\",\n        \"why\": \"Why this matters\",\n        \"how\": \"Step-by-step instructions\",\n        \"contact\": \"Phone/website if applicable\"\n      }\n    ]\n  },\n  \"helpful_contacts\": [\n    {\"name\": \"\", \"what_they_help_with\": \"\", \"contact\": \"\", \"hours\": \"\"}\n  ],\n  \"your_rights\": [\n    {\"right\": \"Plain language description\", \"how_to_use\": \"\"}\n  ],\n  \"encouragement\": \"Closing message of hope and support\",\n  \"next_appointment\": \"Placeholder for counsellor to fill in\"\n}",
        "prompt": "Create client-friendly materials based on the action plan:\n\n{{upstream.synthesize-action-plan.result}}\n\nClient Situation:\n{{upstream.parse-intake.result}}\n\nCreate clear, encouraging materials that help the client take their next steps. Keep it simple and focused on the most important actions."
      },
      "depends_on": ["synthesize-action-plan"],
      "position": { "x": 1000, "y": 850 }
    },
    {
      "id": "route-by-severity",
      "name": "Route by Severity",
      "component_type": "router",
      "config": {
        "routes": [
          {
            "name": "high-priority",
            "condition": "{{upstream.calculate-risk-score.result.risk_score >= 8}}",
            "stages": ["flag-high-priority"]
          },
          {
            "name": "standard",
            "condition": "true",
            "stages": ["prepare-output"]
          }
        ]
      },
      "depends_on": ["generate-counsellor-briefing", "generate-client-materials"],
      "position": { "x": 850, "y": 950 }
    },
    {
      "id": "flag-high-priority",
      "name": "Flag High Priority Case",
      "component_type": "logger",
      "config": {
        "level": "warn",
        "message": "HIGH PRIORITY CASE - Score {{upstream.calculate-risk-score.result.risk_score}}/10",
        "data": {
          "risk_level": "{{upstream.calculate-risk-score.result.risk_level}}",
          "primary_concerns": "{{upstream.calculate-risk-score.result.primary_concerns}}",
          "recommended_urgency": "{{upstream.calculate-risk-score.result.recommended_urgency}}",
          "action": "Schedule priority appointment within 24-48 hours"
        }
      },
      "depends_on": ["route-by-severity"],
      "position": { "x": 700, "y": 1050 }
    },
    {
      "id": "prepare-output",
      "name": "Prepare Final Output",
      "component_type": "json_transform",
      "config": {
        "data": {
          "counsellor_briefing": "{{upstream.generate-counsellor-briefing.result}}",
          "client_materials": "{{upstream.generate-client-materials.result}}",
          "risk_assessment": "{{upstream.calculate-risk-score.result}}",
          "action_plan": "{{upstream.synthesize-action-plan.result}}",
          "research": {
            "hardship_programs": "{{upstream.research-hardship-programs.result}}",
            "local_services": "{{upstream.research-local-services.result}}",
            "legal_protections": "{{upstream.research-legal-protections.result}}",
            "creditor_policies": "{{upstream.research-creditor-policies.result}}"
          }
        },
        "jmespath_expression": "@"
      },
      "depends_on": ["route-by-severity"],
      "position": { "x": 1000, "y": 1050 }
    },
    {
      "id": "log-completion",
      "name": "Log Completion (Audit Trail)",
      "component_type": "logger",
      "config": {
        "level": "info",
        "message": "Financial counselling pipeline completed",
        "data": {
          "risk_score": "{{upstream.calculate-risk-score.result.risk_score}}",
          "risk_level": "{{upstream.calculate-risk-score.result.risk_level}}",
          "action_items_count": "{{upstream.synthesize-action-plan.result.action_plan.immediate_actions | length}}",
          "referrals_count": "{{upstream.synthesize-action-plan.result.referrals | length}}",
          "research_sources": "All recommendations include citation URLs for compliance audit"
        }
      },
      "depends_on": ["prepare-output", "flag-high-priority"],
      "position": { "x": 850, "y": 1150 }
    }
  ],
  "output_stage_id": "prepare-output"
}
