Skip to content

Repository files navigation

AI Credit Memo Generator

A proof-of-concept Streamlit application that generates structured financial credit memos from loan application data using the Anthropic Claude API.

A portfolio project demonstrating AI-assisted credit analysis in financial services workflows.


What it does

Credit analysts spend hours per application pulling data from CRM systems, structuring it, and writing a memo by hand into a Word template.

This tool cuts that to under 30 seconds:

  1. Paste an email — AI extracts all application fields automatically, or fill the form manually
  2. Click Generate Credit Memo
  3. Get a structured, analyst-quality memo ready for review
  4. Refine with natural language"Upgrade the risk rating to High", "Add an FX risk bullet"
  5. Export to PDF — branded, formatted, ready for credit committee

The memo covers: Executive Summary · Borrower Profile · Loan Structure · Financial Analysis · Risk Assessment · Recommendation.


Demo

Email intake Manual entry

Or load the built-in sample (Kowalski Logistics) to see a full output in one click.


Quick Start

# 1. Clone
git clone https://github.com/MKorp7/AI-Credit-Memo-Generator
cd AI-Credit-Memo-Generator

# 2. Install dependencies
pip install -r requirements.txt

# 3. Set your API key
cp .env.example .env
# Edit .env and add your Anthropic API key

# 4. Run
streamlit run app.py

Open http://localhost:8501 in your browser.


Project Structure

credit-memo-generator/
├── app.py                 # Streamlit UI (manual entry + email intake tabs)
├── generator.py           # Claude API — memo generation, refinement, email extraction
├── pdf_export.py          # ReportLab PDF generation
├── test_agents.py         # Automated quality test suite (see below)
├── requirements.txt
├── .env.example
└── sample_data/
    ├── sample_application.json
    └── sample_raport.pdf

How it works

generator.py builds a structured prompt from application data and sends it to claude-opus-4-5 with a strict system prompt enforcing a 6-section credit memo format. The model is instructed to:

  • Follow a strict 6-section structure with no creative deviation
  • Flag missing data explicitly rather than invent numbers
  • Never produce specific numerical estimates (LTV, recovery rates) unless calculable from inputs
  • Calculate DSCR from available inputs
  • Give a clear APPROVED / DECLINED / APPROVED WITH CONDITIONS recommendation

app.py provides a split-pane Streamlit interface with two input modes:

  • 📋 Manual Entry — structured form with a one-click demo loader
  • 📧 Paste Email — paste a raw application email, AI extracts all fields automatically

After generation, an analyst refinement chat lets you update any section using plain English without re-filling the form. Output can be downloaded as .txt or formatted PDF.


Quality test suite

The project includes a two-layer automated test suite (test_agents.py):

  • Layer 1 — Deterministic: regex and math checks (all 6 sections present, DSCR in range, key input values echoed). Fast and free.
  • Layer 2 — AI Judge: one Claude call evaluating hallucinations and internal consistency, returning structured JSON with specific quotes for any issues found.
  • Layer 3 — Refinement smoke test: verifies that a follow-up instruction is applied correctly and nothing else breaks.

Latest test run — 18/18 checks passed:

==========================================================
  Credit Memo Generator — Quality Test Suite
==========================================================
Generating memo...
  ·  Generated in 24.4s  (4,327 chars)

[ Layer 1 / Deterministic ]
  ✓  Section: EXECUTIVE SUMMARY
  ✓  Section: BORROWER PROFILE
  ✓  Section: LOAN REQUEST
  ✓  Section: FINANCIAL ANALYSIS
  ✓  Section: RISK ASSESSMENT
  ✓  Section: RECOMMENDATION
  ✓  Recommendation verdict is explicit
  ✓  DSCR in reasonable range  →  memo=1.57x  expected≈1.54x
  ✓  Input echoed: Loan amount
  ✓  Input echoed: Company name
  ✓  Input echoed: Registration no.

[ Layer 2 / AI Judge ]
  ·  Sending memo to AI judge for hallucination + consistency check...
  ·  AI judge responded in 2.8s
  ✓  No hallucinations detected  →  0 found
  ✓  No consistency issues  →  0 found
  ✓  Overall quality: Good
  ·  Judge summary: The memo accurately reflects all application data with no
     hallucinations or contradictions; all calculations are mathematically derived
     from inputs and all risk assessments are appropriately qualified.

[ Layer 3 / Refinement ]
  ·  Instruction: "Change the risk rating to High and add one bullet about client concentration risk."
  ·  Refined in 15.7s
  ✓  All 6 sections survive refinement
  ✓  Risk rating updated to High
  ✓  Loan amount preserved after refinement
  ✓  Company name preserved after refinement

==========================================================
  18 passed  0 failed  / 18 checks
  ✓ All checks passed.
==========================================================

Run it yourself:

python test_agents.py

Extending this project

Extension Effort Value
CRM integration (HubSpot / Salesforce) Medium High
Analyst feedback loop for prompt fine-tuning Medium High
Batch processing from Excel / CSV upload Low Medium
Multi-language output (EN / PL) Low Medium
Audit trail & memo versioning High High

Tech stack

Component Technology
UI Streamlit
LLM Claude claude-opus-4-5 (Anthropic)
PDF generation ReportLab
API client anthropic Python SDK
Config python-dotenv

Requirements

  • Python 3.10+
  • Anthropic API key — get one here
  • No database or cloud infrastructure required — runs fully locally

License

MIT

About

A proof-of-concept Streamlit application that generates structured financial credit memos from loan application data using the Anthropic Claude API.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages