Comprehensive Loan Underwriting Workflow

End-to-end loan underwriting process with document verification, income analysis, credit assessment, and compliance checks

Back
Workflow Information

ID: loan_underwriting_workflow

Namespace: financial

Version: 1.0

Created: 2025-07-15

Updated: 2025-07-15

Tasks: 31

Quick Actions
Manage Secrets
Inputs
Name Type Required Default
application_id string Required None
loan_amount integer Required None
applicant_data object Required None
uploaded_documents array Required None
min_credit_score integer Optional 650
max_debt_to_income_ratio float Optional 0.4
min_income_multiplier float Optional 3.0
compliance_threshold float Optional 0.95
Outputs
Name Type Source
final_decision object Final underwriting decision with terms
compliance_status object Overall compliance assessment
credit_assessment object Comprehensive credit assessment results
processing_summary object Complete workflow processing summary
Tasks
extract_application_info
script

Extract and structure customer information from application form

validate_application_fields
script

Check if all required fields are present and valid

application_quality_check
ai_agent

AI-powered assessment of application quality

verify_pan_card
script

Verify PAN card authenticity and details

verify_aadhaar
script

Verify Aadhaar card authenticity

verify_passport
script

Verify passport authenticity if provided

verify_address_proof
script

Verify address proof document

consolidate_document_verification
ai_agent

AI analysis of all document verification results

analyze_salary_slips
script

Analyze and extract income information from salary slips

analyze_bank_statements
script

Analyze bank statements for income patterns and financial behavior

verify_tax_returns
script

Verify and analyze tax return documents

verify_employment
script

Verify employment status and details with employer

calculate_debt_to_income
script

Calculate applicant's debt-to-income ratio

income_assessment
ai_agent

AI-powered comprehensive income and financial stability assessment

check_cibil_score
script

Retrieve and analyze CIBIL credit score

analyze_credit_history
script

Detailed analysis of credit history and patterns

assess_existing_loans
script

Assess current loan obligations and repayment capacity

evaluate_default_risk
ai_agent

AI-powered default risk assessment

calculate_credit_score
script

Calculate internal credit score based on all factors

kyc_compliance_check
script

Verify KYC compliance requirements

aml_screening
script

Anti-Money Laundering compliance screening

regulatory_compliance
script

Check compliance with banking regulations

internal_policy_check
script

Verify compliance with internal lending policies

compliance_consolidation
ai_agent

AI-powered comprehensive compliance assessment

underwriting_decision_router
conditional_router

Route to appropriate decision path based on assessments

Conditional Router
Router Type: condition
Default Route: manual_review_path
final_underwriting_analysis
ai_agent

Comprehensive AI analysis for final underwriting decision

generate_approval_terms
script

Generate loan terms and conditions for approved application

generate_conditional_terms
script

Generate conditional approval with additional requirements

generate_decline_notice
script

Generate loan decline notice with reasons

flag_for_manual_review
human_input

Flag application for senior underwriter manual review

generate_final_output
script

Generate comprehensive workflow output

YAML Source
id: loan_underwriting_workflow
name: Comprehensive Loan Underwriting Workflow
retry:
  retryOn:
  - TEMPORARY_FAILURE
  - TIMEOUT
  - NETWORK_ERROR
  maxDelay: 60s
  maxAttempts: 3
  initialDelay: 5s
  backoffMultiplier: 2.0
tasks:
- id: extract_application_info
  name: Extract Customer Information
  type: script
  script: "import json\n\n# Simulate extracting customer info\napplication_data =\
    \ {\n    \"customer_id\": \"CUST_12345\",\n    \"full_name\": \"John Doe\",\n\
    \    \"email\": \"john.doe@email.com\",\n    \"phone\": \"+1-555-0123\",\n   \
    \ \"address\": \"123 Main St, City, State 12345\",\n    \"employment_status\"\
    : \"employed\",\n    \"annual_income\": 75000,\n    \"loan_purpose\": \"home_purchase\"\
    ,\n    \"requested_amount\": ${loan_amount}\n}\n\nresult = {\n    \"extraction_success\"\
    : True,\n    \"customer_info\": application_data,\n    \"missing_fields\": []\n\
    }\n\nprint(f\"__OUTPUTS__ {json.dumps(result)}\")\n"
  description: Extract and structure customer information from application form
  timeout_seconds: 60
- id: validate_application_fields
  name: Validate Required Fields
  type: script
  script: "import json\n\ncustomer_info = ${extract_application_info.customer_info}\n\
    required_fields = [\"full_name\", \"email\", \"phone\", \"address\", \"employment_status\"\
    , \"annual_income\"]\n\nmissing_fields = []\nfor field in required_fields:\n \
    \   if field not in customer_info or not customer_info[field]:\n        missing_fields.append(field)\n\
    \nresult = {\n    \"validation_passed\": len(missing_fields) == 0,\n    \"missing_fields\"\
    : missing_fields,\n    \"completion_percentage\": ((len(required_fields) - len(missing_fields))\
    \ / len(required_fields)) * 100\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(result)}\"\
    )\n"
  depends_on:
  - extract_application_info
  description: Check if all required fields are present and valid
  previous_node: extract_application_info
  timeout_seconds: 30
- id: application_quality_check
  name: Application Quality Assessment
  type: ai_agent
  config:
    input_format: json
    output_format: json
    model_client_id: underwriting_analyst
  depends_on:
  - validate_application_fields
  - extract_application_info
  description: AI-powered assessment of application quality
  user_message: 'Please analyze this loan application:


    Customer Info: ${extract_application_info.customer_info}

    Validation Results: ${validate_application_fields}


    Provide a detailed quality assessment.

    '
  previous_node: validate_application_fields
  system_message: 'You are an expert loan underwriting analyst. Review the application
    data and assess its quality.


    Evaluate:

    1. Data completeness and accuracy

    2. Consistency of information

    3. Red flags or inconsistencies

    4. Overall application quality score (1-100)


    Return a JSON response with your assessment.

    '
- id: verify_pan_card
  name: PAN Card Verification
  type: script
  script: "import json\nimport random\n\n# Simulate PAN verification\npan_number =\
    \ \"ABCDE1234F\"  # Would be extracted from document\n\n# Simulate API call to\
    \ PAN verification service\nverification_result = {\n    \"pan_number\": pan_number,\n\
    \    \"is_valid\": True,\n    \"name_match\": True,\n    \"status\": \"active\"\
    ,\n    \"verification_score\": 95.5,\n    \"verified_name\": \"JOHN DOE\"\n}\n\
    \nprint(f\"__OUTPUTS__ {json.dumps(verification_result)}\")\n"
  depends_on:
  - application_quality_check
  description: Verify PAN card authenticity and details
  previous_node: application_quality_check
  timeout_seconds: 45
- id: verify_aadhaar
  name: Aadhaar Verification
  type: script
  script: "import json\n\n# Simulate Aadhaar verification\naadhaar_number = \"1234-5678-9012\"\
    \  # Masked for privacy\n\nverification_result = {\n    \"aadhaar_masked\": aadhaar_number,\n\
    \    \"is_valid\": True,\n    \"address_match\": True,\n    \"biometric_verified\"\
    : True,\n    \"verification_score\": 98.2,\n    \"last_updated\": \"2024-01-15\"\
    \n}\n\nprint(f\"__OUTPUTS__ {json.dumps(verification_result)}\")\n"
  depends_on:
  - application_quality_check
  description: Verify Aadhaar card authenticity
  previous_node: application_quality_check
  timeout_seconds: 45
- id: verify_passport
  name: Passport Verification
  type: script
  script: "import json\n\n# Simulate passport verification (optional document)\npassport_number\
    \ = \"A1234567\"\n\nverification_result = {\n    \"passport_number\": passport_number,\n\
    \    \"is_valid\": True,\n    \"expiry_date\": \"2030-12-31\",\n    \"issuing_authority\"\
    : \"Government of India\",\n    \"verification_score\": 96.8,\n    \"document_provided\"\
    : True\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(verification_result)}\")\n"
  depends_on:
  - application_quality_check
  description: Verify passport authenticity if provided
  previous_node: application_quality_check
  timeout_seconds: 45
- id: verify_address_proof
  name: Address Proof Verification
  type: script
  script: "import json\n\n# Simulate address proof verification\nverification_result\
    \ = {\n    \"document_type\": \"utility_bill\",\n    \"is_valid\": True,\n   \
    \ \"address_match\": True,\n    \"document_date\": \"2024-06-15\",\n    \"verification_score\"\
    : 92.3,\n    \"address_confirmed\": \"123 Main St, City, State 12345\"\n}\n\n\
    print(f\"__OUTPUTS__ {json.dumps(verification_result)}\")\n"
  depends_on:
  - application_quality_check
  description: Verify address proof document
  previous_node: application_quality_check
  timeout_seconds: 45
- id: consolidate_document_verification
  name: Document Verification Summary
  type: ai_agent
  config:
    input_format: json
    output_format: json
    model_client_id: underwriting_analyst
  depends_on:
  - verify_pan_card
  - verify_aadhaar
  - verify_passport
  - verify_address_proof
  description: AI analysis of all document verification results
  user_message: 'Please analyze these document verification results:


    PAN Verification: ${verify_pan_card}

    Aadhaar Verification: ${verify_aadhaar}

    Passport Verification: ${verify_passport}

    Address Proof: ${verify_address_proof}


    Provide a consolidated assessment.

    '
  previous_node:
  - verify_pan_card
  - verify_aadhaar
  - verify_passport
  - verify_address_proof
  system_message: 'You are a document verification specialist. Analyze all document
    verification results and provide a comprehensive assessment.


    Consider:

    1. Overall verification success rate

    2. Consistency across documents

    3. Risk factors identified

    4. Recommendation for proceeding


    Return a JSON response with your analysis.

    '
- id: analyze_salary_slips
  name: Salary Slip Analysis
  type: script
  script: "import json\n\n# Simulate salary slip analysis\nsalary_data = {\n    \"\
    monthly_gross\": 8500,\n    \"monthly_net\": 6800,\n    \"annual_gross\": 102000,\n\
    \    \"annual_net\": 81600,\n    \"employer\": \"Tech Corp Ltd\",\n    \"employment_duration\"\
    : \"2.5 years\",\n    \"salary_consistency\": True,\n    \"recent_increment\"\
    : True,\n    \"deductions\": {\n        \"tax\": 1200,\n        \"pf\": 500,\n\
    \        \"insurance\": 300\n    }\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(salary_data)}\"\
    )\n"
  depends_on:
  - consolidate_document_verification
  description: Analyze and extract income information from salary slips
  previous_node: consolidate_document_verification
  timeout_seconds: 60
- id: analyze_bank_statements
  name: Bank Statement Analysis
  type: script
  script: "import json\n\n# Simulate bank statement analysis\nbank_analysis = {\n\
    \    \"average_monthly_credits\": 7200,\n    \"salary_credits_consistent\": True,\n\
    \    \"account_balance_trend\": \"stable\",\n    \"minimum_balance\": 15000,\n\
    \    \"maximum_balance\": 45000,\n    \"bounced_transactions\": 0,\n    \"loan_emis_detected\"\
    : 2,\n    \"total_monthly_debits\": 5800,\n    \"financial_discipline_score\"\
    : 85.5,\n    \"irregular_transactions\": False\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(bank_analysis)}\"\
    )\n"
  depends_on:
  - consolidate_document_verification
  description: Analyze bank statements for income patterns and financial behavior
  previous_node: consolidate_document_verification
  timeout_seconds: 90
- id: verify_tax_returns
  name: Tax Return Verification
  type: script
  script: "import json\n\n# Simulate tax return verification\ntax_analysis = {\n \
    \   \"declared_income\": 98000,\n    \"tax_paid\": 12000,\n    \"returns_filed_consistently\"\
    : True,\n    \"income_growth_trend\": \"positive\",\n    \"discrepancies_found\"\
    : False,\n    \"verification_with_govt\": True,\n    \"tax_compliance_score\"\
    : 92.0\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(tax_analysis)}\")\n"
  depends_on:
  - consolidate_document_verification
  description: Verify and analyze tax return documents
  previous_node: consolidate_document_verification
  timeout_seconds: 60
- id: verify_employment
  name: Employment Verification
  type: script
  script: "import json\n\n# Simulate employment verification\nemployment_data = {\n\
    \    \"employment_confirmed\": True,\n    \"designation\": \"Senior Software Engineer\"\
    ,\n    \"employment_type\": \"permanent\",\n    \"probation_status\": \"confirmed\"\
    ,\n    \"employer_rating\": \"A+\",\n    \"job_stability_score\": 88.5,\n    \"\
    reference_check_passed\": True,\n    \"hr_contact_verified\": True\n}\n\nprint(f\"\
    __OUTPUTS__ {json.dumps(employment_data)}\")\n"
  depends_on:
  - analyze_salary_slips
  description: Verify employment status and details with employer
  previous_node: analyze_salary_slips
  timeout_seconds: 120
- id: calculate_debt_to_income
  name: Debt-to-Income Ratio Calculation
  type: script
  script: "import json\n\n# Extract income data\nmonthly_net = ${analyze_salary_slips.monthly_net}\n\
    existing_emis = ${analyze_bank_statements.loan_emis_detected} * 1200  # Assume\
    \ 1200 per EMI\n\n# Calculate proposed EMI (simplified calculation)\nloan_amount\
    \ = ${loan_amount}\nproposed_emi = loan_amount / 240  # 20 year loan approximation\n\
    \ntotal_debt = existing_emis + proposed_emi\ndebt_to_income_ratio = total_debt\
    \ / monthly_net\n\n# Get max allowed ratio from input parameters\nmax_allowed_ratio\
    \ = ${max_debt_to_income_ratio}\n\nresult = {\n    \"monthly_net_income\": monthly_net,\n\
    \    \"existing_debt_payments\": existing_emis,\n    \"proposed_emi\": proposed_emi,\n\
    \    \"total_debt_payments\": total_debt,\n    \"debt_to_income_ratio\": debt_to_income_ratio,\n\
    \    \"ratio_acceptable\": debt_to_income_ratio <= max_allowed_ratio,\n    \"\
    max_allowed_ratio\": max_allowed_ratio\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(result)}\"\
    )\n"
  depends_on:
  - analyze_salary_slips
  - analyze_bank_statements
  - verify_tax_returns
  description: Calculate applicant's debt-to-income ratio
  previous_node:
  - analyze_salary_slips
  - analyze_bank_statements
  - verify_tax_returns
  timeout_seconds: 30
- id: income_assessment
  name: Comprehensive Income Assessment
  type: ai_agent
  config:
    input_format: json
    output_format: json
    model_client_id: underwriting_analyst
  depends_on:
  - calculate_debt_to_income
  - verify_employment
  - analyze_salary_slips
  - analyze_bank_statements
  - verify_tax_returns
  description: AI-powered comprehensive income and financial stability assessment
  user_message: 'Please analyze this comprehensive income data:


    Salary Analysis: ${analyze_salary_slips}

    Bank Statement Analysis: ${analyze_bank_statements}

    Tax Returns: ${verify_tax_returns}

    Employment Verification: ${verify_employment}

    Debt-to-Income Calculation: ${calculate_debt_to_income}


    Provide a thorough income assessment.

    '
  previous_node:
  - calculate_debt_to_income
  - verify_employment
  system_message: 'You are a senior financial analyst specializing in income assessment
    for loan underwriting.


    Analyze the provided income data and provide:

    1. Income stability assessment

    2. Debt servicing capability

    3. Financial discipline evaluation

    4. Risk factors and recommendations

    5. Overall income adequacy score (1-100)


    Return a detailed JSON assessment.

    '
- id: check_cibil_score
  name: CIBIL Score Check
  type: script
  script: "import json\nimport random\n\n# Simulate CIBIL score check\ncibil_data\
    \ = {\n    \"credit_score\": 720,\n    \"score_range\": \"Good\",\n    \"last_updated\"\
    : \"2024-06-01\",\n    \"credit_history_length\": \"5 years\",\n    \"total_accounts\"\
    : 8,\n    \"active_accounts\": 6,\n    \"closed_accounts\": 2,\n    \"credit_utilization\"\
    : 35.5,\n    \"payment_history\": \"99% on-time\",\n    \"recent_inquiries\":\
    \ 2\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(cibil_data)}\")\n"
  depends_on:
  - income_assessment
  description: Retrieve and analyze CIBIL credit score
  previous_node: income_assessment
  timeout_seconds: 60
- id: analyze_credit_history
  name: Credit History Analysis
  type: script
  script: "import json\n\n# Simulate credit history analysis\ncredit_history = {\n\
    \    \"oldest_account_age\": \"60 months\",\n    \"average_account_age\": \"32\
    \ months\",\n    \"credit_mix\": {\n        \"credit_cards\": 3,\n        \"personal_loans\"\
    : 1,\n        \"auto_loans\": 1,\n        \"home_loans\": 0,\n        \"other\"\
    : 1\n    },\n    \"repayment_behavior\": {\n        \"never_missed\": 85.0,\n\
    \        \"30_days_late\": 12.0,\n        \"60_days_late\": 2.5,\n        \"90_days_late\"\
    : 0.5,\n        \"defaults\": 0.0\n    },\n    \"credit_limit_utilization\": 35.2,\n\
    \    \"recent_credit_behavior\": \"stable\"\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(credit_history)}\"\
    )\n"
  depends_on:
  - check_cibil_score
  description: Detailed analysis of credit history and patterns
  previous_node: check_cibil_score
  timeout_seconds: 60
- id: assess_existing_loans
  name: Existing Loan Assessment
  type: script
  script: "import json\n\n# Simulate existing loan assessment\nexisting_loans = {\n\
    \    \"total_outstanding\": 125000,\n    \"number_of_loans\": 2,\n    \"loan_details\"\
    : [\n        {\n            \"type\": \"personal_loan\",\n            \"outstanding\"\
    : 45000,\n            \"emi\": 3500,\n            \"remaining_tenure\": \"18 months\"\
    \n        },\n        {\n            \"type\": \"auto_loan\",\n            \"\
    outstanding\": 80000,\n            \"emi\": 4200,\n            \"remaining_tenure\"\
    : \"24 months\"\n        }\n    ],\n    \"total_monthly_emi\": 7700,\n    \"repayment_track_record\"\
    : \"excellent\",\n    \"loan_burden_ratio\": 0.28\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(existing_loans)}\"\
    )\n"
  depends_on:
  - analyze_credit_history
  description: Assess current loan obligations and repayment capacity
  previous_node: analyze_credit_history
  timeout_seconds: 45
- id: evaluate_default_risk
  name: Default Risk Evaluation
  type: ai_agent
  config:
    input_format: json
    output_format: json
    model_client_id: risk_assessor
  depends_on:
  - assess_existing_loans
  - check_cibil_score
  - analyze_credit_history
  description: AI-powered default risk assessment
  user_message: 'Please analyze this credit data for default risk:


    CIBIL Score: ${check_cibil_score}

    Credit History: ${analyze_credit_history}

    Existing Loans: ${assess_existing_loans}


    Calculate default risk and provide recommendations.

    '
  previous_node: assess_existing_loans
  system_message: 'You are a credit risk assessment specialist. Analyze the provided
    credit data and calculate default risk.


    Consider:

    1. Credit score and history

    2. Repayment patterns

    3. Credit utilization

    4. Existing loan burden

    5. Overall risk profile


    Provide a risk score (1-100, where 100 is highest risk) and detailed risk analysis.

    '
- id: calculate_credit_score
  name: Internal Credit Score Calculation
  type: script
  script: "import json\n\n# Simulate internal credit scoring\ncibil_score = ${check_cibil_score.credit_score}\n\
    payment_history = 99.0  # From credit history\ncredit_utilization = ${analyze_credit_history.credit_limit_utilization}\n\
    loan_burden = ${assess_existing_loans.loan_burden_ratio}\n\n# Internal scoring\
    \ algorithm (simplified)\ninternal_score = (cibil_score * 0.4) + (payment_history\
    \ * 0.3) + ((100 - credit_utilization) * 0.2) + ((1 - loan_burden) * 100 * 0.1)\n\
    \n# Get min credit score from input parameters\nmin_credit_score = ${min_credit_score}\n\
    \nresult = {\n    \"internal_credit_score\": round(internal_score, 1),\n    \"\
    cibil_score\": cibil_score,\n    \"score_acceptable\": internal_score >= min_credit_score,\n\
    \    \"min_required_score\": min_credit_score,\n    \"risk_category\": \"low\"\
    \ if internal_score >= 750 else \"medium\" if internal_score >= 650 else \"high\"\
    ,\n    \"scoring_factors\": {\n        \"cibil_contribution\": cibil_score * 0.4,\n\
    \        \"payment_history_contribution\": payment_history * 0.3,\n        \"\
    utilization_contribution\": (100 - credit_utilization) * 0.2,\n        \"loan_burden_contribution\"\
    : (1 - loan_burden) * 100 * 0.1\n    }\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(result)}\"\
    )\n"
  depends_on:
  - evaluate_default_risk
  - check_cibil_score
  - analyze_credit_history
  - assess_existing_loans
  description: Calculate internal credit score based on all factors
  previous_node: evaluate_default_risk
  timeout_seconds: 30
- id: kyc_compliance_check
  name: KYC Compliance Check
  type: script
  script: "import json\n\n# Simulate KYC compliance check\nkyc_result = {\n    \"\
    kyc_status\": \"compliant\",\n    \"identity_verified\": True,\n    \"address_verified\"\
    : True,\n    \"income_verified\": True,\n    \"documents_complete\": True,\n \
    \   \"risk_category\": \"low\",\n    \"compliance_score\": 98.5,\n    \"last_updated\"\
    : \"2024-07-15\",\n    \"regulatory_requirements_met\": True\n}\n\nprint(f\"__OUTPUTS__\
    \ {json.dumps(kyc_result)}\")\n"
  depends_on:
  - calculate_credit_score
  description: Verify KYC compliance requirements
  previous_node: calculate_credit_score
  timeout_seconds: 60
- id: aml_screening
  name: AML Screening
  type: script
  script: "import json\n\n# Simulate AML screening\naml_result = {\n    \"aml_status\"\
    : \"cleared\",\n    \"watchlist_check\": \"no_matches\",\n    \"pep_screening\"\
    : \"not_identified\",\n    \"sanctions_check\": \"cleared\",\n    \"adverse_media\"\
    : \"no_hits\",\n    \"risk_rating\": \"low\",\n    \"compliance_score\": 96.8,\n\
    \    \"screening_date\": \"2024-07-15\",\n    \"manual_review_required\": False\n\
    }\n\nprint(f\"__OUTPUTS__ {json.dumps(aml_result)}\")\n"
  depends_on:
  - kyc_compliance_check
  description: Anti-Money Laundering compliance screening
  previous_node: kyc_compliance_check
  timeout_seconds: 90
- id: regulatory_compliance
  name: Regulatory Requirements Check
  type: script
  script: "import json\n\n# Simulate regulatory compliance check\nregulatory_result\
    \ = {\n    \"rbi_guidelines_met\": True,\n    \"lending_norms_compliant\": True,\n\
    \    \"documentation_complete\": True,\n    \"disclosure_requirements_met\": True,\n\
    \    \"consumer_protection_compliant\": True,\n    \"data_privacy_compliant\"\
    : True,\n    \"compliance_score\": 97.2,\n    \"audit_trail_complete\": True,\n\
    \    \"regulatory_risk\": \"minimal\"\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(regulatory_result)}\"\
    )\n"
  depends_on:
  - aml_screening
  description: Check compliance with banking regulations
  previous_node: aml_screening
  timeout_seconds: 45
- id: internal_policy_check
  name: Internal Policy Compliance
  type: script
  script: "import json\n\n# Simulate internal policy check\npolicy_result = {\n  \
    \  \"loan_amount_within_limits\": True,\n    \"ltv_ratio_acceptable\": True,\n\
    \    \"income_criteria_met\": True,\n    \"age_criteria_met\": True,\n    \"employment_criteria_met\"\
    : True,\n    \"credit_score_threshold_met\": True,\n    \"geographic_restrictions_met\"\
    : True,\n    \"policy_compliance_score\": 95.5,\n    \"exceptions_required\":\
    \ [],\n    \"policy_version\": \"2024.1\"\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(policy_result)}\"\
    )\n"
  depends_on:
  - regulatory_compliance
  description: Verify compliance with internal lending policies
  previous_node: regulatory_compliance
  timeout_seconds: 30
- id: compliance_consolidation
  name: Compliance Assessment Summary
  type: ai_agent
  config:
    input_format: json
    output_format: json
    model_client_id: compliance_reviewer
  depends_on:
  - internal_policy_check
  - kyc_compliance_check
  - aml_screening
  - regulatory_compliance
  description: AI-powered comprehensive compliance assessment
  user_message: 'Please analyze these compliance check results:


    KYC Compliance: ${kyc_compliance_check}

    AML Screening: ${aml_screening}

    Regulatory Compliance: ${regulatory_compliance}

    Internal Policy: ${internal_policy_check}


    Provide a consolidated compliance assessment.

    '
  previous_node: internal_policy_check
  system_message: 'You are a compliance officer specializing in loan underwriting
    compliance.


    Review all compliance check results and provide:

    1. Overall compliance status

    2. Risk assessment

    3. Any compliance gaps or concerns

    4. Recommendations for proceeding

    5. Compliance confidence score (1-100)


    Return a comprehensive compliance assessment in JSON format.

    '
- id: underwriting_decision_router
  name: Underwriting Decision Router
  type: conditional_router
  conditions:
  - name: high_risk_path
    route: decline_path
    condition: ${calculate_credit_score.internal_credit_score} < 600 || ${calculate_debt_to_income.debt_to_income_ratio}
      > 0.50
  - name: conditional_approval_path
    route: conditional_path
    condition: ${calculate_credit_score.internal_credit_score} >= 600 && ${calculate_credit_score.internal_credit_score}
      < 700
  - name: standard_approval_path
    route: approval_path
    condition: ${calculate_credit_score.internal_credit_score} >= 700
  depends_on:
  - compliance_consolidation
  - calculate_credit_score
  - calculate_debt_to_income
  description: Route to appropriate decision path based on assessments
  default_route: manual_review_path
  previous_node: compliance_consolidation
- id: final_underwriting_analysis
  name: Final Underwriting Decision Analysis
  type: ai_agent
  config:
    input_format: json
    output_format: json
    model_client_id: underwriting_analyst
  depends_on:
  - underwriting_decision_router
  - application_quality_check
  - consolidate_document_verification
  - income_assessment
  - calculate_credit_score
  - evaluate_default_risk
  - compliance_consolidation
  - calculate_debt_to_income
  description: Comprehensive AI analysis for final underwriting decision
  user_message: 'Please make the final underwriting decision based on:


    Application Quality: ${application_quality_check}

    Document Verification: ${consolidate_document_verification}

    Income Assessment: ${income_assessment}

    Credit Score: ${calculate_credit_score}

    Default Risk: ${evaluate_default_risk}

    Compliance: ${compliance_consolidation}

    Debt-to-Income: ${calculate_debt_to_income}


    Provide your final recommendation with detailed reasoning.

    '
  previous_node: underwriting_decision_router
  system_message: 'You are a senior underwriting manager making final loan decisions.


    Analyze all assessment results and provide:

    1. Final recommendation (APPROVE/CONDITIONAL/DECLINE)

    2. Loan terms and conditions

    3. Risk mitigation measures

    4. Reasoning for decision

    5. Confidence level (1-100)


    Consider all factors: income, credit, compliance, and overall risk profile.

    '
- id: generate_approval_terms
  name: Generate Loan Approval Terms
  type: script
  script: "import json\n\n# Generate loan terms based on assessment\nloan_terms =\
    \ {\n    \"decision\": \"APPROVED\",\n    \"loan_amount\": ${loan_amount},\n \
    \   \"interest_rate\": 8.5,\n    \"tenure_months\": 240,\n    \"monthly_emi\"\
    : round(${loan_amount} / 240 * 1.085, 2),\n    \"processing_fee\": ${loan_amount}\
    \ * 0.01,\n    \"conditions\": [\n        \"Property insurance required\",\n \
    \       \"Auto-debit for EMI payments\",\n        \"Annual income certificate\
    \ submission\"\n    ],\n    \"disbursement_conditions\": [\n        \"Property\
    \ registration documents\",\n        \"Insurance policy copy\",\n        \"Post-dated\
    \ cheques for EMI\"\n    ],\n    \"approval_date\": \"2024-07-15\",\n    \"offer_validity\"\
    : \"2024-08-15\"\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(loan_terms)}\")\n"
  depends_on:
  - final_underwriting_analysis
  description: Generate loan terms and conditions for approved application
  previous_node: final_underwriting_analysis
  timeout_seconds: 60
  execute_on_routes:
  - approval_path
- id: generate_conditional_terms
  name: Generate Conditional Approval Terms
  type: script
  script: "import json\n\n# Generate conditional approval terms\nconditional_terms\
    \ = {\n    \"decision\": \"CONDITIONAL_APPROVAL\",\n    \"loan_amount\": ${loan_amount},\n\
    \    \"interest_rate\": 9.2,\n    \"tenure_months\": 240,\n    \"monthly_emi\"\
    : round(${loan_amount} / 240 * 1.092, 2),\n    \"processing_fee\": ${loan_amount}\
    \ * 0.015,\n    \"additional_conditions\": [\n        \"Co-applicant required\"\
    ,\n        \"Additional collateral security\",\n        \"Higher down payment\
    \ (30% instead of 20%)\",\n        \"Salary account maintenance for 2 years\"\n\
    \    ],\n    \"documents_required\": [\n        \"Co-applicant income documents\"\
    ,\n        \"Additional property papers\",\n        \"Enhanced bank statements\
    \ (12 months)\"\n    ],\n    \"approval_date\": \"2024-07-15\",\n    \"offer_validity\"\
    : \"2024-08-01\"\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(conditional_terms)}\"\
    )\n"
  depends_on:
  - final_underwriting_analysis
  description: Generate conditional approval with additional requirements
  previous_node: final_underwriting_analysis
  timeout_seconds: 60
  execute_on_routes:
  - conditional_path
- id: generate_decline_notice
  name: Generate Loan Decline Notice
  type: script
  script: "import json\n\n# Generate decline notice\ndecline_notice = {\n    \"decision\"\
    : \"DECLINED\",\n    \"primary_reasons\": [\n        \"Insufficient credit score\"\
    ,\n        \"High debt-to-income ratio\",\n        \"Inadequate income documentation\"\
    \n    ],\n    \"decline_code\": \"RISK_001\",\n    \"decline_date\": \"2024-07-15\"\
    ,\n    \"appeal_process\": \"Customer can appeal within 30 days with additional\
    \ documentation\",\n    \"suggestions\": [\n        \"Improve credit score by\
    \ 6 months\",\n        \"Reduce existing debt burden\",\n        \"Consider lower\
    \ loan amount\",\n        \"Add co-applicant with good credit\"\n    ],\n    \"\
    reapplication_eligibility\": \"2024-12-15\"\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(decline_notice)}\"\
    )\n"
  depends_on:
  - final_underwriting_analysis
  description: Generate loan decline notice with reasons
  previous_node: final_underwriting_analysis
  timeout_seconds: 30
  execute_on_routes:
  - decline_path
- id: flag_for_manual_review
  name: Senior Underwriter Manual Review
  type: human_input
  approval:
    title: Manual Underwriting Review Required
    assignee: senior_underwriter
    description: This application requires senior underwriter review due to complex
      risk factors
    sla_minutes: 480
  depends_on:
  - final_underwriting_analysis
  description: Flag application for senior underwriter manual review
  previous_node: final_underwriting_analysis
  execute_on_routes:
  - manual_review_path
- id: generate_final_output
  name: Generate Final Workflow Output
  type: script
  script: "import json\n\n# Determine final decision based on route\nfinal_output\
    \ = {\n    \"application_id\": \"${application_id}\",\n    \"processing_date\"\
    : \"2024-07-15\",\n    \"workflow_status\": \"completed\",\n    \"processing_time_minutes\"\
    : 45,\n    \"decision_summary\": {\n        \"credit_score\": ${calculate_credit_score.internal_credit_score},\n\
    \        \"debt_to_income_ratio\": ${calculate_debt_to_income.debt_to_income_ratio},\n\
    \        \"compliance_status\": \"compliant\",\n        \"risk_category\": \"\
    ${calculate_credit_score.risk_category}\"\n    },\n    \"next_steps\": [\n   \
    \     \"Customer notification\",\n        \"Document archival\",\n        \"Compliance\
    \ reporting\"\n    ]\n}\n\nprint(f\"__OUTPUTS__ {json.dumps(final_output)}\")\n"
  depends_on:
  - generate_approval_terms
  - generate_conditional_terms
  - generate_decline_notice
  - flag_for_manual_review
  - calculate_credit_score
  - calculate_debt_to_income
  description: Generate comprehensive workflow output
  previous_node:
  - generate_approval_terms
  - generate_conditional_terms
  - generate_decline_notice
  - flag_for_manual_review
  timeout_seconds: 30
inputs:
- name: application_id
  type: string
  required: true
  description: Unique loan application identifier
- name: loan_amount
  type: integer
  required: true
  description: Requested loan amount
- name: applicant_data
  type: object
  required: true
  description: Applicant personal information
- name: uploaded_documents
  type: array
  required: true
  description: List of uploaded document references
- name: min_credit_score
  type: integer
  default: 650
  required: false
  description: Minimum acceptable credit score
- name: max_debt_to_income_ratio
  type: float
  default: 0.4
  required: false
  description: Maximum debt-to-income ratio allowed
- name: min_income_multiplier
  type: float
  default: 3.0
  required: false
  description: Minimum income multiplier for loan approval
- name: compliance_threshold
  type: float
  default: 0.95
  required: false
  description: Minimum compliance score threshold
outputs:
  final_decision:
    type: object
    source: final_underwriting_analysis
    description: Final underwriting decision with terms
  compliance_status:
    type: object
    source: compliance_consolidation
    description: Overall compliance assessment
  credit_assessment:
    type: object
    source: calculate_credit_score
    description: Comprehensive credit assessment results
  processing_summary:
    type: object
    source: generate_final_output
    description: Complete workflow processing summary
version: '1.0'
metadata:
  author: Financial Services Team
  version: '1.0'
  environment: production
  last_updated: '2024-07-15'
  compliance_certified: true
namespace: financial
description: End-to-end loan underwriting process with document verification, income
  analysis, credit assessment, and compliance checks
model_clients:
- id: underwriting_analyst
  config:
    model: gpt-4o-mini
    api_key: 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
    max_tokens: 2000
    temperature: 0.1
  provider: openai
- id: compliance_reviewer
  config:
    model: gpt-4o-mini
    api_key: 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
    max_tokens: 1500
    temperature: 0.0
  provider: openai
- id: risk_assessor
  config:
    model: gpt-4o-mini
    api_key: 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
    max_tokens: 1000
    temperature: 0.2
  provider: openai
timeout_seconds: 3600
Execution ID Status Started Duration Actions
6cb664ca... WAITING_FOR_INPUT 2025-07-15
14:16:10
N/A View
0fea91d7... WAITING_FOR_INPUT 2025-07-15
13:48:54
N/A View
f7d46f06... COMPLETED 2025-07-15
12:55:24
N/A View
46c707e2... COMPLETED 2025-07-15
12:50:31
N/A View
a838fbbd... COMPLETED 2025-07-15
12:34:30
N/A View
6ad22750... COMPLETED 2025-07-15
12:33:08
N/A View
4d7ca006... COMPLETED 2025-07-15
12:32:02
N/A View
2ae9c6a6... COMPLETED 2025-07-15
12:20:26
N/A View
0ac7c1b1... COMPLETED 2025-07-15
11:58:08
N/A View
42bbd4ef... COMPLETED 2025-07-15
11:40:37
N/A View
32e42b0b... COMPLETED 2025-07-15
11:35:13
N/A View
0ce63da0... COMPLETED 2025-07-15
11:33:43
N/A View
959d6b53... COMPLETED 2025-07-15
11:28:30
N/A View
afcace5e... COMPLETED 2025-07-15
11:11:11
N/A View
b1ce6fad... COMPLETED 2025-07-15
11:10:23
N/A View
098c0d80... COMPLETED 2025-07-15
11:09:21
N/A View
de5d61e2... COMPLETED 2025-07-15
11:07:23
N/A View
cf395dc8... COMPLETED 2025-07-15
11:04:41
N/A View
b8822c7d... COMPLETED 2025-07-15
10:49:18
N/A View
d329380a... COMPLETED 2025-07-15
10:44:36
N/A View