Skip to content

Insurance — Claims Processing & Fraud Detection ​

examples/finance/insurance-claims.halo policies |* parallel |! people

Automate the claims lifecycle — from initial filing through fraud scoring, adjuster review, payout calc, and disbursement. Replaces BPM tools (Camunda, Pega) that cost $500K+/year to license and maintain.

Open in the playground and play with it →

halo
// ============================================================
// Insurance — Claims Processing & Fraud Detection
// PURPOSE: Automate the claims lifecycle — from initial filing
//          through fraud scoring, adjuster review, payout calc,
//          and disbursement. Replaces BPM tools (Camunda, Pega)
//          that cost $500K+/year to license and maintain.
// ============================================================

// --- Policies ---
// Medical details have no detector: keep medical records out of the claim
// payload. Identifiers and contact details are masked before any model sees them.
policy ClaimsPrivacy   : Redact(SSN, CreditCard, Email, Phone)
policy FraudPolicy     : Block(DestructiveOps, PromptInjection)
// The payout is a JSON record, and never more than the policy covers.
policy PayoutLimit     : Require(JSON) & Validate("payout_amount", "<=", "context.data.verify_coverage.max_payout")
policy CostGuard       : MaxSpend(1.50)

// --- Tools ---
tool PolicyAPI     : REST("api.guidewire.com/v1/policies", apiKey: Env.GUIDEWIRE_KEY)
tool ClaimsDB      : REST("api.guidewire.com/v1/claims", apiKey: Env.GUIDEWIRE_KEY)
tool PaymentGW     : POST("api.stripe.com/v1/payouts", apiKey: Env.STRIPE_KEY)
tool AdjusterSlack : POST("hooks.slack.com/services/claims-team")

// --- Store ---
tool FraudPatterns : VectorStore(Env.PINECONE_KEY, namespace: "fraud-indicators")
tool ClaimHistory  : VectorStore(Env.PINECONE_KEY, namespace: "historical-claims")

// --- Struct ---
schema ClaimFiling {
  claim_id       : String
  policy_number  : String
  incident_date  : String
  type           : String
  claimant_name  : String
  amount         : Number
  description    : String
  metadata       : Object
  payment_method : String
}

schema ClaimDecision {
  claim_id        : String
  fraud_score     : Number
  coverage_valid  : Boolean
  payout_amount   : Number
  decision        : String
  adjuster_notes  : String
}

// --- Agents ---
agent ClaimsBot [openai/gpt-4o-mini, temp: 0.0]
  equips PolicyAPI, PaymentGW
  requires ClaimsPrivacy, CostGuard

agent FraudAnalyst [anthropic/claude-sonnet-4, temp: 0.0]
  system "Score how likely the claim is fraudulent. Answer with JSON: {\"fraud_score\": 0-100, \"reasons\": [...]}"
  equips FraudPatterns, ClaimHistory
  requires ClaimsPrivacy, FraudPolicy, CostGuard

@correct(3)
agent AdjusterAssistant [openai/gpt-4o, temp: 0.2]
  system """
    Calculate the payout from the coverage limits and the damage.
    Answer with JSON: {"claim_id": "...", "fraud_score": 0, "coverage_valid": true,
    "payout_amount": 0, "decision": "approve" | "deny", "adjuster_notes": "..."}
  """
  equips ClaimHistory
  requires ClaimsPrivacy, CostGuard, PayoutLimit

// --- The Pipeline ---
@timeout(5m)
@retry(2, 10s)
pipeline ProcessClaim(claim: ClaimFiling) -> ClaimDecision:
  claim
    // Step 1: Parallel verification — policy lookup + fraud scoring
    |* {
         ClaimsBot.verify_coverage(
           tool: PolicyAPI,
           policy_number: context.data.claim.policy_number,
           incident_date: context.data.claim.incident_date,
           claim_type: context.data.claim.type
         ),
         FraudAnalyst.score_fraud(
           claimant: context.data.claim.claimant_name,
           amount_requested: context.data.claim.amount,
           incident_description: context.data.claim.description,
           submission_metadata: context.data.claim.metadata
         )
       }

    // Step 2: A high fraud score goes to the investigators, and the claim stops here
    |? {
         (context.data.score_fraud.fraud_score > 80) => AdjusterSlack.post(
           message: "HIGH FRAUD RISK — manual review required immediately",
           claim_id: context.data.claim.claim_id,
           fraud_score: context.data.score_fraud.fraud_score,
           channel: "fraud-investigations"
         ),
       }
    |? (context.data.score_fraud.fraud_score <= 80)

    // Step 3: Gate — stop unless the policy covers this claim type
    |? (context.data.verify_coverage.covered == true)

    // Step 4: Calculate payout based on coverage limits + damage assessment
    |> AdjusterAssistant.calculate_payout(
         coverage: context.data.verify_coverage,
         claim: context.data.claim,
         fraud_assessment: context.data.score_fraud,
         comparable_claims: ClaimHistory
       )
    |? (context.data.calculate_payout.decision == "approve")

    // Step 5: Small claims pay out automatically; an adjuster approves larger ones
    |? {
         (context.data.calculate_payout.payout_amount > 5000) => AdjusterReview(context.data.calculate_payout, context.data.verify_coverage, context.data.score_fraud),
         else => System.Value(context.data.calculate_payout),
       } as review
    |? (context.data.calculate_payout.payout_amount <= 5000 || context.data.review.approved == true)

    // Step 6: Disburse payment
    |> ClaimsBot.disburse(
         tool: PaymentGW,
         claim_id: context.data.claim.claim_id,
         amount: context.data.calculate_payout.payout_amount,
         method: context.data.claim.payment_method
       )

    // Step 7: Log to claims system, and return the decision
    |> ClaimsDB.post(
         event: "CLAIM_RESOLVED",
         claim_id: context.data.claim.claim_id,
         payout: context.data.calculate_payout.payout_amount,
         fraud_score: context.data.score_fraud.fraud_score,
         decision: "approved"
       )
    |> System.Value(context.data.calculate_payout)

// An adjuster approves a payout over $5,000.
pipeline AdjusterReview(payout: JSON, coverage: JSON, fraud: JSON) -> Result:
  payout
    |! yield(AdjusterSlack, payout, [coverage, fraud], 24h)
    ~> listen(AdjusterSlack.Reaction) as adjuster
    |> System.Value(context.data.adjuster)

curl -fsSL https://halolang.com/install.sh | sh