How to Build a KYC verification Agent Using LangGraph in TypeScript for banking

By Cyprian AaronsUpdated 2026-04-21
kyc-verificationlanggraphtypescriptbanking

A KYC verification agent automates the boring but high-risk parts of customer onboarding: document intake, identity extraction, sanctions/PEP screening, risk scoring, and escalation when something looks off. In banking, that matters because you need fast approvals without losing control over compliance, auditability, and data residency.

Architecture

A production KYC agent in LangGraph needs a small set of hard boundaries:

  • Input intake layer

    • Receives customer-submitted documents and metadata
    • Normalizes file references, jurisdiction, product type, and customer segment
  • Document extraction node

    • Pulls structured fields from passport, national ID, proof of address, or business registration docs
    • Outputs JSON with confidence scores and missing-field flags
  • Compliance screening node

    • Checks against sanctions, PEP, adverse media, and internal watchlists
    • Produces a clear pass/fail/review result with reasons
  • Risk scoring node

    • Combines document quality, geography, customer type, and screening results
    • Assigns low/medium/high risk for downstream decisioning
  • Human review / escalation node

    • Routes ambiguous or high-risk cases to an analyst queue
    • Preserves all evidence for audit
  • Audit persistence layer

    • Stores every state transition, input hash, model output, and final decision
    • Supports regulator queries and internal controls

Implementation

1. Define the state shape for the KYC workflow

LangGraph works best when your state is explicit. For banking workflows, keep the state small but complete enough to support audit and reprocessing.

import { StateGraph, START, END } from "@langchain/langgraph";

type KycState = {
  customerId: string;
  jurisdiction: string;
  documentType: "passport" | "national_id" | "utility_bill" | "company_registry";
  documentText?: string;
  extracted?: {
    fullName?: string;
    dateOfBirth?: string;
    idNumber?: string;
    address?: string;
    confidence: number;
  };
  screening?: {
    sanctionsHit: boolean;
    pepHit: boolean;
    adverseMediaHit: boolean;
    reason: string[];
  };
  riskScore?: number;
  decision?: "approve" | "reject" | "manual_review";
};

This is the contract between nodes. In regulated systems, that contract matters more than clever prompts.

2. Build each node as a deterministic function

Use pure functions where possible. If you call external services for OCR or screening, wrap them in a thin adapter so retries and observability stay under your control.

const extractDocument = async (state: KycState): Promise<Partial<KycState>> => {
  // Replace with OCR / document AI service call.
  const text = state.documentText ?? "";

  const extracted = {
    fullName: text.includes("JOHN DOE") ? "JOHN DOE" : undefined,
    dateOfBirth: text.includes("1990-01-01") ? "1990-01-01" : undefined,
    idNumber: text.match(/[A-Z0-9]{8,12}/)?.[0],
    address: text.includes("LONDON") ? "LONDON" : undefined,
    confidence: text.length > 50 ? 0.91 : 0.42,
  };

  return { extracted };
};

const screenCustomer = async (state: KycState): Promise<Partial<KycState>> => {
  // Replace with sanctions/PEP/vendor API calls.
  const name = state.extracted?.fullName ?? "";
  const hit = name === "JOHN DOE";

  return {
    screening: {
      sanctionsHit: hit,
      pepHit: false,
      adverseMediaHit: false,
      reason: hit ? ["Possible match on sanctions list"] : ["No watchlist match"],
    },
  };
};

const scoreRisk = async (state: KycState): Promise<Partial<KycState>> => {
  let score = 10;

  if ((state.extracted?.confidence ?? 0) < 0.8) score += 30;
  if (state.screening?.sanctionsHit) score += 80;
  if (!state.extracted?.address) score += 15;

  
The user asked for only article body; continue with code block and steps etc. Need ensure valid code blocks. Let's craft concise.

---

## Keep learning

- [The complete AI Agents Roadmap](/blog/ai-agents-roadmap-2026) — my full 8-step breakdown
- [Free: The AI Agent Starter Kit](/starter-kit) — PDF checklist + starter code
- [Work with me](/contact) — I build AI for banks and insurance companies

*By Cyprian Aarons, AI Consultant at [Topiax](https://topiax.xyz).*

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