liveBook · Manning

Fuzzy matching

As explained in Build Financial Software with Generative AI (From Scratch)

A fuzzy matching algorithm compares strings approximately so that similar values can be matched despite minor differences.

Fuzzy matching compares strings approximately instead of requiring an exact or partial text match. It is useful when a name may be misspelled, formatted differently, or deliberately altered. In transaction screening, that wider comparison helps flag incoming customer names that resemble individuals on a sanctions list. section 11.7.2 section 11.10

A practical workflow first collects distinct names from ACH transaction records, removes spaces to make cleaned comparison values, and gathers sanctioned-person names and aliases in the same form. Keeping file and batch identifiers with each name preserves the context needed to investigate a result. section 11.7.2

PostgreSQL's fuzzystrmatch extension supplies several ways to compare names:

  • Soundex and Metaphone provide phonetic matching options. section 11.7.2
  • Levenshtein distance measures the difference between two strings and can be converted into a percentage similarity score by comparing the distance with the longer string length. section 11.7.2
  • Daitch-Mokotoff matching can test a cleaned transaction name against either a sanctioned name or an alias. section 11.7.2
Listing 11.28 Computing similarity scores for IAT individuals
computed_similarity_iat AS (
    SELECT
        ach_files_id, 
        ach_records_type_5_id AS ach_batch_id, 
        sdn.sdn_name,
        aicn.individual_name,
        alias,
        (1 - (LEVENSHTEIN(cleaned_individual_name, #1
sdn.cleaned_sdn_name)::FLOAT  #1
/ GREATEST(LENGTH(cleaned_individual_name),  #1
LENGTH(sdn.cleaned_sdn_name)))) * 100  #1
AS similarity_score,  #1
        CASE #2
           WHEN DAITCH_MOKOTOFF(cleaned_individual_name) &&  
               DAITCH_MOKOTOFF(sdn.cleaned_sdn_name) THEN TRUE 
           ELSE FALSE 
        END AS daitch_mokotoff_match_name,
        CASE
           WHEN daitch_mokotoff(cleaned_individual_name) &&
               DAITCH_MOKOTOFF (sdn.cleaned_sdn_alias) THEN TRUE
           ELSE FALSE
        END AS daitch_mokotoff_match_alias
    FROM ach_iat_collected_names aicn
    CROSS JOIN sdn_names sdn #3

The similarity query cross-joins collected IAT names with sanctioned names, calculates a normalized Levenshtein percentage, and records phonetic matches for names and aliases. section 11.7.2

The final screening result combines PPD and IAT comparisons, then retains rows whose similarity score is at least 80 or whose name or alias has a Daitch-Mokotoff match. Ordering by similarity places the strongest candidates first, while the retained transaction identifiers support review. section 11.7.2

Sanctions screening for ACH files

When a user starts an OFAC scan, loaded ACH files can be checked for names resembling entries on the OFAC list. The resulting matches can feed an API and a UI result component, helping the organization review potential sanctioned-party transactions and reduce compliance risk. section 11.9.3 section 11.10

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Implements PostgreSQL similarity scoring, phonetic checks, normalization, and result filtering; defers scalable strategies for larger lists and file volumes.
Examples
Uses PPD and IAT transaction names, sanctioned names and aliases, cleaned strings, similarity scores, and an 80-percent filter.
What it assumes
Introduces approximate name searching after SQL ILIKE and wildcard searching, while requiring ACH record selection for collected names.
What you can do after
Apply it via PostgreSQL fuzzystrmatch to identify candidate sanctioned-party matches in ACH transaction data.
How it connects
Connects OFAC scanning with ACH transactions, PostgreSQL, Levenshtein distance, phonetic matching, common table expressions, APIs, and UI results.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.