How to Build a claims processing Agent Using AutoGen in Python for lending
A claims processing agent for lending takes in borrower disputes, insurance claims tied to loans, payment exception requests, and supporting documents, then classifies, extracts facts, routes the case, and drafts the next action for a human reviewer or downstream system. It matters because lending operations are full of time-sensitive decisions with compliance exposure: you need consistent triage, an audit trail, and tight control over what the agent can decide on its own.
Architecture
- •
Ingress layer
- •Receives claim text, PDFs, emails, or ticket payloads.
- •Normalizes input into a structured case object.
- •
Triage agent
- •Uses an LLM to classify the claim type.
- •Detects urgency, missing fields, and whether the case needs human review.
- •
Extraction agent
- •Pulls out borrower name, account ID, loan number, dates, amounts, and claim reason.
- •Returns structured JSON for downstream rules.
- •
Policy/rules layer
- •Applies lending-specific checks like document completeness, jurisdiction rules, and SLA thresholds.
- •Prevents the model from making final eligibility decisions.
- •
Human review handoff
- •Escalates exceptions to a loan operations analyst or compliance officer.
- •Captures rationale for auditability.
- •
Audit logger
- •Stores prompts, outputs, timestamps, model versions, and decision metadata.
- •Supports dispute handling and regulatory review.
Implementation
1) Install and initialize AutoGen agents
For this pattern, use AssistantAgent for reasoning and UserProxyAgent as the orchestrator. In lending workflows, keep tool execution explicit and avoid letting the model call arbitrary code.
from autogen import AssistantAgent, UserProxyAgent
llm_config = {
"model": "gpt-4o-mini",
"api_key": "YOUR_OPENAI_API_KEY",
"temperature": 0,
}
triage_agent = AssistantAgent(
name="triage_agent",
llm_config=llm_config,
system_message=(
"You triage lending claims. "
"Classify the claim type, identify missing fields, "
"and return concise JSON only."
),
)
extract_agent = AssistantAgent(
name="extract_agent",
llm_config=llm_config,
system_message=(
"You extract structured fields from lending claims. "
"Return valid JSON with borrower_name, account_id, loan_number, "
"claim_type, amount_claimed, incident_date, and confidence."
),
)
orchestrator = UserProxyAgent(
name="orchestrator",
human_input_mode="NEVER",
code_execution_config=False,
)
2) Define a strict case payload and ask for structured output
AutoGen works best when you keep each agent narrow. For lending claims processing, ask for classification first so your rules engine can decide whether to continue or escalate.
claim_text = """
Borrower: Maya Chen
Account ID: ACCT-88341
Loan Number: LN-55219
Issue: Payment posted twice on 2026-03-14 after ACH reversal.
Amount: $425.00
Requested action: Refund duplicate payment.
"""
triage_prompt = f"""
Analyze this lending claim and return JSON with:
- claim_type
- urgency
- missing_fields
- needs_human_review
- short_reason
Claim:
{claim_text}
"""
triage_result = orchestrator.initiate_chat(
triage_agent,
message=triage_prompt,
)
print(triage_result.chat_history[-1]["content"])
At this point you should parse the response and enforce schema validation in your application code. Don’t trust free-form model output in a loan ops workflow.
3) Extract fields with a second agent and apply deterministic routing
Use a second pass only if triage says the case is worth processing. That keeps token spend down and reduces accidental extraction from irrelevant cases.
import json
def route_claim(triage_json: str):
data = json.loads(triage_json)
if data["needs_human_review"]:
return {"route": "human_review", "reason": data["short_reason"]}
return {"route": "extract"}
triage_json = triage_result.chat_history[-1]["content"]
route = route_claim(triage_json)
if route["route"] == "extract":
extract_prompt = f"""
Extract structured fields from this claim as valid JSON only:
{claim_text}
"""
extract_result = orchestrator.initiate_chat(
extract_agent,
message=extract_prompt,
)
extracted_json = extract_result.chat_history[-1]["content"]
print(extracted_json)
else:
print(route)
4) Add an audit record before handing off
In lending, every decision needs traceability. Log the raw input hash, model version, output payloads, and who approved the final action.
from datetime import datetime
from hashlib import sha256
def build_audit_record(claim_text: str, triage_output: str):
return {
"timestamp_utc": datetime.utcnow().isoformat(),
"input_hash": sha256(claim_text.encode("utf-8")).hexdigest(),
"model": llm_config["model"],
"triage_output": triage_output,
"status": "pending_review",
"domain": "lending_claims",
}
audit_record = build_audit_record(claim_text, triage_json)
print(audit_record)
If you need multi-agent collaboration later — for example one agent classifies while another drafts customer correspondence — AutoGen’s GroupChat and GroupChatManager are the next step. Keep that behind policy gates so only approved actions reach borrowers.
Production Considerations
- •
Deployment
- •Run the agent behind an internal API with mTLS and role-based access control.
- •Keep lender-specific prompts and policy logic in versioned config so changes are reviewable.
- •
Monitoring
- •Track claim type distribution, escalation rate, extraction confidence, latency per stage, and human override rate.
- •Alert on spikes in “needs_human_review” because that usually means upstream document quality dropped or prompt drift started.
- •
Guardrails
- •Never let the model approve payments or deny claims directly.
- •Use deterministic rules for eligibility thresholds, duplicate detection, and jurisdiction checks.
- •Force schema validation on every model response before storage or routing.
- •
Data residency
- •Keep borrower PII inside approved regions.
- •Redact account numbers and SSNs before sending text to the model if your hosting setup requires it.
- •Store prompts and outputs in encrypted audit storage with retention aligned to lending policy.
Common Pitfalls
- •
Letting the model make final business decisions
- •Fix: constrain AutoGen agents to classification and extraction only; put approval logic in code.
- •
Skipping schema validation
- •Fix: validate every response with Pydantic or JSON Schema before using it in routing or persistence.
- •
Ignoring audit requirements
- •Fix: log input hashes, prompt versions, outputs, timestamps, and reviewer actions for every case.
- •
Mixing sensitive data into unconstrained prompts
- •Fix: redact PII where possible and keep data residency controls aligned with your lender’s compliance boundaries.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
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