How to Build a loan approval Agent Using CrewAI in Python for healthcare

By Cyprian AaronsUpdated 2026-04-21
loan-approvalcrewaipythonhealthcare

A healthcare loan approval agent evaluates financing requests for patients, clinics, or providers by gathering the right data, checking policy rules, and producing an approval recommendation with an audit trail. It matters because healthcare lending is not generic lending: you need tighter controls around protected data, explainability, consent, and jurisdictional storage.

Architecture

  • Intake layer
    • Receives the loan request payload: applicant details, treatment type, amount, repayment terms, and consent flags.
  • Policy retrieval component
    • Pulls underwriting rules specific to healthcare financing, such as minimum income thresholds, procedure eligibility, and excluded treatments.
  • Risk analysis agent
    • Scores affordability, repayment risk, and policy fit using structured inputs only.
  • Compliance reviewer agent
    • Checks for HIPAA-aligned handling, consent presence, adverse-action explanation requirements, and data minimization.
  • Decision orchestrator
    • Coordinates agents through CrewAI and produces one of three outputs: approve, reject, or manual review.
  • Audit logger
    • Stores inputs, intermediate findings, final decision, and rationale in an immutable log for review.

Implementation

1) Install CrewAI and define your domain inputs

Use a small set of structured fields. In healthcare lending, unstructured free text creates unnecessary compliance risk.

from pydantic import BaseModel
from typing import Literal

class LoanApplication(BaseModel):
    applicant_id: str
    requested_amount: float
    monthly_income: float
    monthly_debt: float
    treatment_category: str
    state: str
    consent_to_process_phi: bool
    data_residency_region: str

class LoanDecision(BaseModel):
    decision: Literal["approve", "reject", "manual_review"]
    reason: str

2) Create the agents with explicit responsibilities

CrewAI’s Agent class should stay narrow. Don’t give one agent every job; split analysis from compliance.

from crewai import Agent

risk_agent = Agent(
    role="Healthcare Loan Risk Analyst",
    goal="Assess repayment ability and policy fit for healthcare financing applications",
    backstory="You evaluate structured loan applications for affordability and treatment eligibility.",
    verbose=True,
)

compliance_agent = Agent(
    role="Healthcare Compliance Reviewer",
    goal="Validate consent, data handling constraints, and auditability requirements",
    backstory="You check whether the application can be processed under healthcare privacy and lending policies.",
    verbose=True,
)

3) Define tasks and wire them into a crew

Use Task, Crew, and Process.sequential. The first task produces a risk assessment; the second turns that into a compliant decision recommendation.

from crewai import Task, Crew, Process

risk_task = Task(
    description=(
        "Review this healthcare loan application:\n"
        "{application}\n\n"
        "Calculate debt-to-income ratio, assess affordability, "
        "and flag any obvious policy violations."
    ),
    expected_output="A concise risk summary with recommendation and key drivers.",
    agent=risk_agent,
)

compliance_task = Task(
    description=(
        "Review the risk summary and the original application for compliance issues.\n"
        "Check consent_to_process_phi, data_residency_region alignment with policy,\n"
        "and whether the case needs manual review due to missing or sensitive data."
    ),
    expected_output="A compliant final decision with explanation suitable for audit logs.",
    agent=compliance_agent,
)

crew = Crew(
    agents=[risk_agent, compliance_agent],
    tasks=[risk_task, compliance_task],
    process=Process.sequential,
    verbose=True,
)

4) Run the crew with a structured input payload

Keep the payload JSON-like so it’s easy to validate before it reaches the model. In production I’d validate this at the API boundary before calling kickoff.

application = LoanApplication(
    applicant_id="app_10291",
    requested_amount=12000.0,
    monthly_income=6500.0,
    monthly_debt=1800.0,
    treatment_category="orthopedic surgery",
    state="CA",
    consent_to_process_phi=True,
    data_residency_region="us-west-2",
)

result = crew.kickoff(inputs={"application": application.model_dump_json()})
print(result)

If you want a cleaner contract for downstream systems, wrap the output in your own parser. CrewAI returns text by default; your service layer should normalize that into LoanDecision before persistence or API response.

Production Considerations

  • Enforce PHI minimization
    • Only send fields needed for underwriting. Do not pass full medical records when a treatment category and cost estimate are enough.
  • Pin data residency
    • Route workloads to approved regions only. If your policy says US-only processing for patient-linked financial decisions, enforce that at the infrastructure layer before CrewAI runs.
  • Log every decision path
    • Store input hashes, task outputs, model version, prompt version, timestamp, and final decision. You need this for audits and adverse-action reviews.
  • Add human review gates
    • Any case with missing consent, high loan amount, inconsistent income data, or sensitive treatment categories should go to manual review instead of auto-decision.

Common Pitfalls

  • Using free-text medical notes as agent input
    • This is how teams accidentally expand their compliance scope. Pass structured fields only unless legal has explicitly cleared PHI processing.
  • Letting one agent make both risk and compliance decisions
    • That creates brittle prompts and weak auditability. Separate underwriting logic from policy checks so you can explain failures cleanly.
  • Skipping deterministic validation before CrewAI
    • Validate schema fields like income ranges, residency region codes, and consent flags in Python first. The LLM should not be your first line of defense.
  • Ignoring adverse-action explanations
    • If the loan is rejected or sent to manual review because of debt-to-income ratio or missing consent, capture that reason in a form your ops team can use directly.

Keep learning

By Cyprian Aarons, AI Consultant at Topiax.

Want the complete 8-step roadmap?

Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.

Get the Starter Kit

Related Guides