How to Build a claims processing Agent Using LlamaIndex in TypeScript for retail banking

By Cyprian AaronsUpdated 2026-04-21
claims-processingllamaindextypescriptretail-banking

A claims processing agent in retail banking takes a customer-submitted claim, classifies the issue, pulls the right policy and account context, checks required evidence, and drafts a decision or next action for a human reviewer. It matters because claims are high-volume, regulated, and expensive when handled slowly or inconsistently.

Architecture

  • Claim intake API
    • Receives structured claim data plus attachments, then normalizes it into a single request object.
  • Policy and procedure index
    • Stores bank-specific claims policies, dispute handling rules, fee reversal rules, and escalation paths in a vector index.
  • Customer context retriever
    • Pulls relevant account metadata, transaction history references, and prior case notes from approved internal systems.
  • Decisioning layer
    • Uses LlamaIndex query engines to answer: is this claim eligible, what evidence is missing, and what is the recommended action?
  • Audit logger
    • Persists prompts, retrieved sources, outputs, and human overrides for compliance review.
  • Human review queue
    • Routes low-confidence or high-risk claims to an operations analyst before any customer-facing action is taken.

Implementation

  1. Install LlamaIndex for TypeScript and wire up your model client

Use the TypeScript package with an OpenAI-compatible model provider. In banking, keep this behind your approved model gateway so you can enforce residency and logging rules.

import {
  Settings,
  VectorStoreIndex,
  Document,
} from "llamaindex";
import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY!,
});

Settings.llm = {
  chat: async (messages) => {
    const response = await openai.chat.completions.create({
      model: "gpt-4o-mini",
      messages,
      temperature: 0,
    });

    return {
      message: response.choices[0].message.content ?? "",
    };
  },
};
  1. Load banking policy documents into an index

Keep this corpus tight. For claims processing, index only approved procedures: chargeback rules, card dispute timelines, refund policy, fraud escalation criteria, and customer communication templates.

const docs = [
  new Document({
    text: `
Retail banking claims policy:
- Card-present disputes must be reviewed within 10 business days.
- Missing merchant receipt requires manual review.
- Claims over $5,000 require supervisor approval.
- AML-related indicators must be escalated immediately.
`,
    metadata: { source: "claims-policy-v3", jurisdiction: "US" },
  }),
  new Document({
    text: `
Evidence checklist:
- Transaction ID
- Claim reason code
- Customer statement
- Supporting attachment if available
`,
    metadata: { source: "evidence-checklist-v2", jurisdiction: "US" },
  }),
];

const index = await VectorStoreIndex.fromDocuments(docs);
const queryEngine = index.asQueryEngine();
  1. Build the claim processor around retrieval plus structured output

The pattern here is simple: retrieve policy context first, then ask the model to produce a decision draft with explicit fields. Don’t let the agent freewheel across arbitrary tools unless you need that later.

type ClaimRequest = {
  claimId: string;
  customerId: string;
  amount: number;
  reasonCode: string;
  transactionId?: string;
};

type ClaimDecision = {
  eligibility: "eligible" | "ineligible" | "needs_review";
  missingEvidence: string[];
  recommendedAction: string;
  auditSummary: string;
};

export async function processClaim(claim: ClaimRequest): Promise<ClaimDecision> {
  const retrievalPrompt = `
You are reviewing a retail banking claim.
Return only relevant policy facts for this claim:
${JSON.stringify(claim)}
`;

  const retrieved = await queryEngine.query({ query: retrievalPrompt });

  const decisionPrompt = `
Using the policy context below, draft a claim decision in JSON with:
eligibility, missingEvidence, recommendedAction, auditSummary.

Claim:
${JSON.stringify(claim)}

Policy context:
${retrieved.response}
`;

  const result = await Settings.llm.chat([
    { role: "system", content: "You are a retail banking claims analyst." },
    { role: "user", content: decisionPrompt },
  ]);

  return JSON.parse(result.message) as ClaimDecision;
}
  1. Add guardrails before anything leaves the service

For production banking workflows, never auto-execute on model output alone. Use deterministic checks for amount thresholds, sanctions/AML flags, duplicate claims, and missing identity verification.

export function shouldEscalate(claim: ClaimRequest, decision: ClaimDecision): boolean {
  if (claim.amount > 5000) return true;
  if (decision.eligibility === "needs_review") return true;
  if (decision.missingEvidence.length > 0) return true;
  return false;
}

Production Considerations

  • Deployment
    • Keep the agent inside your bank’s private network or VPC.
    • Pin model endpoints to approved regions to satisfy data residency requirements.
  • Monitoring
    • Log retrieved document IDs, final decisions, latency, token usage, and human override rates.
    • Track false approvals and false rejections by claim type.
  • Guardrails
    • Block PII leakage in prompts and outputs.
    • Enforce deterministic thresholds for high-value claims and suspicious activity indicators.
  • Auditability
    • Store every prompt version and source citation used in the decision path.
    • Make it easy for compliance teams to reconstruct why a claim was routed or denied.

Common Pitfalls

  1. Indexing too much internal data

    • If you dump raw CRM notes or transaction logs into retrieval without filtering, you will surface irrelevant or sensitive context.
    • Index only approved policy artifacts and fetch live customer data through controlled APIs.
  2. Letting the model decide on high-risk claims

    • Claims above threshold amounts or with fraud markers need rule-based escalation.
    • Use the model for drafting and classification; use business logic for final routing.
  3. Skipping audit trails

    • If you cannot explain which policy snippet influenced the outcome, compliance will block rollout.
    • Persist source document IDs, timestamps, prompt versions, and reviewer actions alongside each claim record.

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