Skip to content

Fintech — KYC/AML Compliance Pipeline ​

examples/finance/kyc-aml-compliance.halo policies |* parallel |! people

Onboard new customers with automated identity verification, sanctions screening, and risk scoring. Replaces 6-week manual review with 3-minute automation.

Open in the playground and play with it →

halo
// ============================================================
// Fintech — KYC/AML Compliance Pipeline
// PURPOSE: Onboard new customers with automated identity
//          verification, sanctions screening, and risk scoring.
//          Replaces 6-week manual review with 3-minute automation.
// ============================================================

// --- Policies ---
// Dates of birth and passport numbers have no detector, so the compliance
// agent is never given them: it gets the verification results and the country.
policy KYCPrivacy     : Redact(SSN, CreditCard, Email, Phone)
// Application text is untrusted. A sanctions match is stopped by a gate, not a policy.
policy BSACompliance  : Block(PromptInjection)
policy CostGuard      : MaxSpend(2.00)

// --- Tools ---
tool IdentityAPI   : REST("api.plaid.com/identity/verify", apiKey: Env.PLAID_KEY)
tool SanctionsAPI  : REST("api.ofac.treasury.gov/search", apiKey: Env.OFAC_KEY)
tool CreditAPI     : REST("api.experian.com/credit/v1", apiKey: Env.EXPERIAN_KEY)
tool ComplianceLog : POST("api.example.com/compliance-audit")
tool CompSlack     : POST("hooks.slack.com/services/compliance-team")

// --- Store ---
tool RiskProfiles  : VectorStore(Env.PINECONE_KEY, namespace: "customer-risk-profiles")
tool RegPatterns   : VectorStore(Env.PINECONE_KEY, namespace: "regulatory-patterns")

// --- Struct ---
schema CustomerApplication {
  customer_id   : String
  full_name     : String
  ssn           : String
  ssn_last4     : String
  date_of_birth : String
  country       : String
  consent_id    : String
}

// --- Agents ---
agent IdentityAgent [openai/gpt-4o-mini, temp: 0.0]
  equips IdentityAPI, SanctionsAPI, CreditAPI
  requires KYCPrivacy, CostGuard

agent ComplianceAgent [anthropic/claude-sonnet-4, temp: 0.0]
  system "Assess AML risk. Answer with JSON: {\"risk_tier\": \"low\" | \"medium\" | \"high\", \"reasons\": [...]}"
  equips RiskProfiles, RegPatterns
  requires KYCPrivacy, BSACompliance, CostGuard

// --- The Pipeline ---
@timeout(5m)
@retry(3, 10s)
pipeline OnboardCustomer(application: CustomerApplication) -> Result:
  application
    // Step 1: Parallel identity verification — hit all APIs at once
    |* {
         IdentityAgent.verify_identity(
           tool: IdentityAPI,
           name: context.data.application.full_name,
           ssn_last4: context.data.application.ssn_last4,
           dob: context.data.application.date_of_birth
         ),
         IdentityAgent.screen_sanctions(
           tool: SanctionsAPI,
           name: context.data.application.full_name,
           country: context.data.application.country
         ),
         IdentityAgent.pull_credit(
           tool: CreditAPI,
           ssn: context.data.application.ssn,
           consent_token: context.data.application.consent_id
         )
       }

    // Step 2: A sanctions match is logged, and onboarding stops. Only an
    // explicit "no match" goes on, so a missing answer stops too.
    |? {
         (context.data.screen_sanctions.match_found == true) => ComplianceLog.post(
           event: "SANCTIONS_MATCH",
           customer: context.data.application.full_name,
           details: context.data.screen_sanctions
         ),
       }
    |? (context.data.screen_sanctions.match_found == false)

    // Step 3: Risk assessment — synthesize all signals
    |> ComplianceAgent.assess_risk(
         identity: context.data.verify_identity,
         sanctions: context.data.screen_sanctions,
         credit: context.data.pull_credit,
         country: context.data.application.country
       )

    // Step 4: Low-risk (Tier 1) customers are approved automatically;
    // a compliance officer approves medium and high risk
    |? {
         (context.data.assess_risk.risk_tier != "low") => ComplianceReview(context.data.assess_risk, context.data.verify_identity, context.data.screen_sanctions, context.data.pull_credit),
         else => System.Value(context.data.assess_risk),
       } as review
    |? (context.data.assess_risk.risk_tier == "low" || context.data.review.approved == true)

    // Step 5: Log final decision for regulatory audit
    |> ComplianceLog.post(
         event: "KYC_COMPLETE",
         customer_id: context.data.application.customer_id,
         risk_tier: context.data.assess_risk.risk_tier,
         approved: true
       )

// A compliance officer approves a medium- or high-risk customer.
pipeline ComplianceReview(risk: JSON, identity: JSON, sanctions: JSON, credit: JSON) -> Result:
  risk
    |! yield(CompSlack, risk, [identity, sanctions, credit], 2h)
    ~> listen(CompSlack.Reaction) as officer
    |> System.Value(context.data.officer)

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