KYC and identity verification engineering

23 articles, in reading order.

Identity verification turns a photo of a document and a selfie into a decision: is this a real document, does it belong to this person, and is the person present? I've worked on these pipelines at ShuftiPro, and these articles cover the engineering behind each step, with code you can run.

Start with the overview, then follow the pipeline in order: getting a clean image, reading the document's data, checking the face, looking for fraud, and screening the person.

How verification works

  1. How KYC identity verification works: document capture, OCR, face match and liveness, step by step

    What happens between 'take a photo of your ID' and 'verified': document detection, classification, OCR and MRZ checks, face matching, liveness, and the decision. An AI engineer's walkthrough of each stage and where it fails.

  2. KYC vs AML vs KYB vs CDD: what each means, and where AI fits in each

    KYC verifies who a customer is, AML is the wider programme against money laundering, KYB verifies businesses, and CDD/EDD set how deep checks go. A plain-English guide for founders and engineers, with where automation and AI help.

  3. Real-time KYC card verification over MQTT: a pub-sub pipeline explained

    A three-service KYC pipeline on MQTT: a client publishes ID card data, a verifier checks each field and publishes reasons, an analyst stores and charts results. Design choices and what QoS 1 implies.

Capturing a usable image

  1. Validating file uploads in Node.js: check magic bytes, not the file name or Content-Type

    A file called passport.jpg with Content-Type image/jpeg can be HTML or SVG with a script inside. How to validate uploads in Node.js by their first bytes, cap the size while streaming, hash the content, and why images should still be re-encoded. Tested code for JPEG, PNG and PDF.

  2. Why your OCR sees ID photos sideways: EXIF orientation, and fixing it with Pillow

    Phones store photos in the sensor's orientation and add an EXIF tag saying how to rotate them for display. OCR and face detection read raw pixels, so they see the document sideways. How to apply the orientation with Pillow's exif_transpose, and why re-encoding first loses it for good. Tested Python.

  3. Preparing ID card photos for OCR with OpenCV: find the card, flatten it, and reject blur and glare

    Most OCR errors on identity documents come from the photo, not the model. Tested OpenCV code to detect a card's corners, correct perspective to a flat ID-1 rectangle, and score sharpness and glare before OCR runs.

  4. Why OCR struggles with Arabic, Urdu and other non-Latin scripts, and what helps

    Connected letters with up to four shapes, Urdu's sloping Nastaliq baseline, right-to-left text with left-to-right numbers, Eastern Arabic digits, and scripts without spaces. What breaks OCR on identity documents and how pipelines handle it.

Reading and checking document data

  1. How passport MRZ check digits work, with code to validate them

    The two lines of chevrons on a passport are the machine-readable zone. How ICAO 9303 check digits work (weights 7, 3, 1), how to validate the document number, dates and composite digit in Python, and why OCR pipelines rely on them.

  2. Correcting MRZ OCR errors with check digits: O vs 0, I vs 1, and when not to guess

    OCR misreads passport MRZ characters such as O and 0, I and 1, B and 8. How to repair the document number by trying confusable swaps until the check digit matches, why a single check digit lets wrong repairs pass one time in ten, and the rule that decides between fixing and asking for a new photo. Tested Python.

  3. Which century is 74? Parsing MRZ dates of birth and expiry correctly

    Passport MRZ dates have two-digit years, so 740812 could be 1974 or 2074. The rules that resolve the century for birth and expiry dates, how to compute age and expiry checks, and the cases where the visual zone has to decide. Tested Python.

  4. How NFC passport chip verification works: BAC, PACE, passive and chip authentication

    E-passports carry a chip with a signed copy of the data page and photo. How a phone reads it (BAC or PACE using the MRZ), how passive authentication proves the data is genuine, and how chip authentication stops cloning.

  5. OCR vs NFC chip reading for passport verification: what each one actually proves

    The key differences between OCR-based document verification and reading a passport's NFC chip: what each proves, what each misses, and how passive, active and chip authentication fit in. With a tested Python model of passive authentication showing an edited MRZ, a swapped photo, a forged signature and a clone.

  6. Validating a Pakistani CNIC number: the 13-digit format, what the digits mean, and what format checks can't tell you

    How to validate and normalise a Pakistani CNIC number (12345-1234567-1) in Python: hyphens, Urdu digits from OCR, the region and gender digits, and why there's no check digit, so a well-formed number still needs verification.

  7. Luhn and IBAN check digits explained: validating card numbers and bank accounts in Python

    How the Luhn algorithm validates card numbers and how IBAN's mod-97 check works, with tested Python, the one transposition Luhn can't catch, and why a valid check digit doesn't mean the account exists.

Face match, liveness and fraud signals

  1. Face match thresholds: how false accepts trade against false rejects in identity verification

    Face verification compares two embeddings and applies a threshold. What FMR and FNMR (FAR and FRR) mean, how to choose a threshold from data with code, and why image quality, ageing and demographics move the numbers.

  2. Face liveness detection explained: presentation attacks, injection attacks and how they're measured

    Liveness detection checks that a live person, not a photo, screen replay or mask, is in front of the camera. Active vs passive liveness, the ISO 30107-3 metrics APCER and BPCER, and why deepfake injection needs a separate defence.

  3. Liveness detection certification explained: ISO/IEC 30107-3, APCER, BPCER and what a test report should show

    What 'certified liveness' means: presentation attack detection testing under ISO/IEC 30107-3, how APCER is computed per attack type and why pooling hides weak spots, BPCER at the same threshold, and what to ask a vendor for. Tested Python for the metrics.

  4. Catching reused ID photos with perceptual hashing: dHash in Python for KYC fraud

    Fraudsters reuse the same ID card photo across many accounts, resized and recompressed. How a perceptual hash (dHash) finds near-duplicates, why you should hash the portrait instead of the whole card, and what cropping and rotation do to the distance. Tested Python with Pillow.

  5. When a model says 95%, is it right 95% of the time? Calibration, ECE and temperature scaling in Python

    A fraud or face-match model can rank cases well and still report confidence that's badly off. How to measure calibration with a reliability table and expected calibration error (ECE), and fix overconfidence with one-parameter temperature scaling. Tested NumPy code: ECE from 0.126 to 0.011.

Screening and personal data

  1. Fuzzy name matching for sanctions screening: normalisation, transliteration and Jaro-Winkler

    Why exact matching fails for KYC and AML name screening, and how to build a matcher that handles accents, titles, word order and Arabic transliterations such as Muhammad and Mohamed. Tested Python, plus why secondary identifiers matter more than the threshold.

  2. Detecting homoglyph names in Python: Cyrillic look-alikes, fullwidth letters and zero-width spaces

    pаypal with a Cyrillic а looks identical to paypal. How to catch look-alike usernames, brand names and customer names in Python: NFKC normalisation, mixed-script detection from Unicode names, a confusables skeleton, and zero-width characters, with tests and the legitimate cases you must not block.

  3. Redacting personal data from logs and LLM prompts in Python: emails, CNICs, cards, IBANs and phone numbers

    KYC and support systems leak personal data into logs and LLM prompts. A tested Python redactor with typed placeholders, a Luhn check so order numbers aren't mistaken for card numbers, and the phone-number pattern that redacted my test's order ID. Plus where redaction belongs and what regex can't catch.

  4. Are KYC verification photos deleted? How long identity data is kept, and a retention policy in code

    What happens to your selfie and ID photos after KYC: why some records must be kept for years under anti-money-laundering rules while raw images can often be deleted much sooner, and a tested Python retention policy with legal holds and abandoned applications.

Common questions

What are the steps in KYC identity verification?

Capture a photo of the identity document and a selfie, check image quality, read the document with OCR and the machine-readable zone, check the document's security features or NFC chip, compare the selfie with the document photo, confirm the person is live, then screen the name against sanctions and PEP lists. Each failed check should carry a reason the user can act on.

Does a valid MRZ check digit prove a passport is genuine?

No. Check digits only catch misreads and typos; anyone can compute them. Authenticity comes from the document's physical security features or, on e-passports, from the digitally signed data on the NFC chip.

Does a Pakistani CNIC number have a check digit?

No. A CNIC is 13 digits (12345-1234567-1): a locality code whose first digit is the region, a serial, and a final digit that is odd for men and even for women. Format checks catch malformed input, but only verification against NADRA's records confirms the number belongs to the person.

How do you choose a face match threshold?

Measure false accepts and false rejects on labelled pairs at several thresholds, then pick the point that matches the risk: a lower false accept rate for high-value accounts, a lower false reject rate where friction loses customers. Check the rates per segment, such as device type, because one global number can hide a group that fails far more often.

Other guides