Credit Memo Generation
The Credit Memo Generation engine serves as the final synthesis layer in the LoanPilot workflow. It aggregates data from borrower profiles, bank statements, and financial statements to generate a comprehensive credit risk assessment using AI.
Overview
The credit memo is generated by calling the /api/analyze/credit-memo endpoint. This process does not just extract data; it contextualizes it. The engine retrieves the most recent analysis records for a specific application and provides them to the AI provider to perform qualitative and quantitative risk evaluation.
API Reference
Generate Credit Memo
POST /api/analyze/credit-memo
Triggers the AI-driven synthesis of all available application data into a structured credit memo.
Request Body
| Field | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| applicationId | string | Yes | The UUID of the loan application. |
| organizationId | string | Yes | The UUID of the organization (bank/lender). |
| aiProvider | string | No | The specific AI model to use (e.g., GPT-4, Claude). Defaults to the system standard. |
Example Request
const response = await fetch('/api/analyze/credit-memo', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
applicationId: 'app_12345',
organizationId: 'org_67890',
aiProvider: 'openai'
}),
});
const result = await response.json();
Data Synthesis Logic
The generation engine automatically gathers the following data points to build the context for the memo:
1. Application & Borrower Profile
- Loan Details: Type, amount, tenure, and stated purpose.
- Borrower Stats: Business constitution, industry sector, years in business, and annual turnover.
- Verification Status: CIBIL scores and verification flags for GSTIN, Udyam, and Aadhaar.
2. Bank Statement Insights
The engine pulls the most recent bank_statement_analysis record, including:
- Cash Flow: Total credits, debits, and net income.
- Stability: Average and minimum balances, and count of negative balance days.
- Behavior: Transaction categories and daily balance trends.
3. Financial Statement Metrics
Data from Balance Sheets and P&L statements are included to calculate:
- Profitability: Revenue, Gross Profit Margin, and Net Profit Margin.
- Liquidity: Current Ratio and Quick Ratio.
- Solvency: Debt-to-Equity and Debt-to-Assets ratios.
- Repayment Capacity: Debt Service Coverage Ratio (DSCR).
Usage Workflow
To ensure a high-quality credit memo, follow this sequence:
- Upload Documents: Use
/api/documents/uploadto upload bank statements and financial reports. - Run Individual Analyses:
- Trigger
/api/analyze/bank-statementfor cash flow data. - Trigger
/api/analyze/financial-statementfor P&L and Balance Sheet data.
- Trigger
- Generate Memo: Once the individual analyses are stored in the database, call the credit memo endpoint. The engine will automatically find the latest data to populate the report.
Response Handling
The endpoint returns a structured object containing the AI-generated memo content. This typically includes:
- Executive Summary: A high-level overview of the credit request.
- Financial Analysis: Interpretation of the synthesized ratios and cash flow.
- Risk Assessment: Identification of potential red flags or mitigants.
- Recommendation: A data-backed suggestion for approval or rejection.