Tutorials

Building an AI-Powered KYC Upload Checker

In this tutorial, we’ll guide you on creating a KYC Upload Checker for an Account object using CloudFiles Document AI and Salesforce Integration. We will leverage CloudFiles AI in conjunction with Salesforce flow to create this functionality. This checker will automatically scan uploaded passports and driving licenses, extract key details, and update corresponding fields in Salesforce, significantly enhancing the efficiency and accuracy of your KYC processes.

What To Expect

By the end of this tutorial, you can expect to -

  1. Set up a system to verify KYC document uploads, for Passport & Driver’s License.
  2. Automatically extract key information from the documents and update corresponding custom fields in the Salesforce Account object

The GIF below shows the expected output. If you have a basic grasp of these concepts, you can expect to finish the tutorial in under 10 minutes.

Document image


1 - Pre-requisites

Before you start with the set-up, please ensure these steps are completed.

Install CloudFiles in Salesforce

CloudFiles is available on the Salesforce AppExchange and can be installed using the standard app installation process. Check out Installation Guide to know more.

Document image


Add CloudFiles Widget to Account Record

To add the CloudFiles widget to the Account record in Salesforce, first, navigate to the Account page and click on the "Edit Page" button. Once in the Lightning Builder, insert a new tab and drag and drop the "CloudFiles" widget onto the page. Save the changes and exit the builder. Refresh the Salesforce record page, and the widget should now be visible, allowing easy access to view files and folders within Salesforce.

Document image


Create custom fields for Account object in salesforce

  • AI Output - This field captures whether the uploaded document is a passport or a driving license or none, as detected by the AI.
  • Driving License Number - Stores the extracted driving license number from the uploaded document.
  • Passport Number - Holds the extracted passport number from the uploaded document.
  • Passport Country - Records the country of issuance for the passport.

Refer to the image below to have a visual understanding of these custom fields -

Document image


To create the AI-powered KYC Upload Checker, we set up a platform-triggered flow that activates upon receiving a 'CloudFiles Event' message. We ensured the uploaded file is associated with the Salesforce Account object and then extracted KYC document details using specified parameters like Context, Drive Id, File Id, and Library. After confirming document processing, we applied CloudFiles AI to classify the document as a driving license or passport and extracted relevant details. Finally, we updated the Salesforce Account object with the extracted information. This is the final flow that has been created.

Document image


These steps have been discussed below in detail -

2 - Create a Platform Event-Triggered Flow

We will create a platform-triggered flow that will fire when a ‘CloudFiles Event’ message is received. Refer to the GIF below for a visual understanding of this step -

Document image


‘CloudFiles event’ messages can be generated for various events, we will first filter out the messages only for the event when a file is uploaded to an Account Object. We will proceed to retrieve & process the uploaded document.

Retrieve Document Details for Processing

We will add a decision outcome to filter out events where the file is uploaded to the Salesforce Account object. Then, we will use two CloudFiles actions to first retrieve the account details and then the file details for further processing.

1 - Use ‘Decision’ to filter event messages for files uploaded to Account Object

We will add a decision element to ensure that the file to be processed is uploaded to the Salesforce Account object. It will ask you to fill in certain parameters. We will add 2 resources as given below -

{!$Record.cldfs__Object_Type__c} Equals 'Account'
{!$Record.cldfs__Type__c} Equals 'file-uploaded'

This is how the Outcome Detail looks like -

Document image


Refer to the gif below for a visual understanding of this step -

Document image


In order to get the Account ID of the account for which the file upload has happened, we will use the CloudFiles action - “Get Events Details’.

2 - Retrieve the uploaded KYC document details using the "Get Event Details" action

To retrieve event details, we'll use the 'Get Event Details' action, which provides various information about the event, including the content version and uploaded file details. Outputs from this action will be used in the next action. In the ‘Get Event Details’ action, put {!$Record} as an event.

Refer to the GIF below to have a visual understanding of this step -

Document image


3 - Retrieve File Details for Further Processing using “Process Document” action

Once we have received the event details, we will use the 'Process Document' action to obtain the uploaded file details for further processing. To do this, you need to fill in the following parameters

  • Context - This relates the uploaded file details with the Account record and will be used later to find the corresponding Account record. You can use the outputs from Get File Upload Details > Uploaded File Details > RecordId
  • Drive Id - The storage drive where the uploaded Salesforce file is stored. Use outputs from Get File Upload Details > Uploaded File Details > DriveId
  • File Id - The unique identifier assigned to the uploaded file. Use outputs from Get File Upload Details > Uploaded File Details > Id
  • Library - The library to which the uploaded file belongs. Use outputs from Get File Upload Details > Uploaded File Details > Library

This is how the action looks like -

Document image


Refer to the GIF below to have a visual understanding of this action -

Document image


Use ‘Decision’ Element’ to categorize the KYC Documents

Once the file is processed, we will proceed to ask a series of prompts to obtain the required details from the file. First, we will add a second decision outcome to fetch the previously processed files. Then, we will retrieve all the file details using the ‘Get Event Details’ action. Once we have the required details, we will ask a series of prompts to the document through the ‘Query Document’ action, which will classify the document as a specific KYC type. The following steps outline this process in detail -

1 - Retrieve processed files using ‘Decision’ outcome

We will add a ‘File Processed’ outcome in the decision element to fetch the previously processed files for further processing. Fill in the parameters as given below -

{!$Record.cldfs__Type__c}, Triggering CloudFiles Event > Type Equals 'document-processed'

This is how the final decision outcome looks like -

Document image


2 - Get Processed Event Details using ‘Get Event Details’ action

In order to apply CloudFiles Document AI on the desired document, we now need to first get processed event details. In order to do so, add a ‘Get Event Details’ action and put {!Record} as an event.

Refer to the GIF below to have a visual understanding of this step -

Document image


3 - Apply CloudFiles AI to Check and Classify KYC Documents Using the 'Query Document' Action

We will use CloudFiles' AI-enabled action ‘Query Document’ to classify the KYC document type - as Passport, Driver's License, or Other. There are two inputs required for this action: Process Document ID and Query. Please refer below to understand how to fill these input fields -

  • Process Document ID - This is necessary to retrieve all details of the processed document and to locate the correct document for the KYC upload checker to function. Here, we are inputting the following value in this field - {!Get_Processed_Event_Details.DocumentProcessed.ProcessedDocumentId}, Outputs from Get Processed Event Details > Document Processed > ProcessedDocumentId

Refer to the gif to have a visual understanding of this step -

Document image

  • Query - It is the prompt we will provide to CloudFiles AI to obtain the desired results. To write the query, it is advisable to use text constants that are objective and highly specific to achieve the best results from CloudFiles AI.

We have used the following Classification Prompt Query. You can customize it to suit your needs.

KYC Document classification prompt "Classify the file as either a driving license or a passport. If the file does not match either of these types, classify it as other. Based on the classification, give the output as one of the following - Driving License, Passport, or Other."

Please refer to the GIF below to have a visual understanding of this step -

Document image


Retrieve KYC Document Details and Update the Record Field

Once the KYC documents are processed and classified into different document types, we will prompt for specific details about these documents, such as Passport ID and Passport Country. First, we will add a decision element to determine whether a document is a Driving License or a Passport based on the earlier classification query, and direct the flow accordingly. Then, we will add KYC-specific queries using the ‘Query Document’ action to retrieve crucial KYC details. Finally, we will populate these details into the relevant custom fields of the Account object. The detailed steps are given below -

1- Add ‘Decision’ element to classify KYC document type for retrieving details

We will add a decision element to classify whether the document is a Driving License, Passport, or neither. We will create two outcomes for this decision element, one for each document type, as shown below -

  • Outcome 1 - For Driver’s License Text from Classification Query Equals Driving License
  • Outcome 2 - For Passport Text from Classification Query Equals Passport

Refer to the GIF below for visual understanding -

Document image


2 - Retrieve KYC-specific details using the ‘Query Document’ action

Once the document is classified as a specific KYC type, we will use relevant prompts fed to the CloudFiles AI using the ‘Query Document’ action to extract specific information from the uploaded document. Different relevant queries can be written as text constants and applied as needed. It is advisable to make these queries highly objective and specific. The steps for this are the same as those used in the KYC classification query steps

For this tutorial, we have used three queries: one to fetch the Passport number, another for the Passport country, and a third for the Driver's license number. Refer to the queries below for an understanding of prompt writing. You can customize these queries to suit your requirements.

Prompt to fetch Driver’s License Number - "Given document is a driving license. Extract the Driving License number from this and only output the driving license number. If Driving License number cannot be read, give output as Not Available."

Prompt to fetch Passport Country' - "Given document is a passport. Extract the Passport country from this and classify is as one of the following - USA, UK, Germany, Australia, India. If passport country cannot be classified as one of the given options then output Other."

Prompt to fetch Passport Number - "Given document is a passport. Extract the Passport number from this and only output the passport number. If passport number cannot be read, give output as Not Available."

3 - Update the AI Output Details in the Account Object Fields

We will use ‘Update Records’ action for updating the above fetched information in the relevant fields of the Account object record. Follow these configurations for possible cases -

Update Records > Check Specify conditions to identify records, and set fields individually > Fill Account as Object

Note - Here we are using earlier mentioned context of the uploaded file to find the right Account record by comparing Account ‘Id’ with the ‘Context’. In order to do so use Id Equals Outputs from Get Processed Event Details > DocumentProcessed > Context field-value pair to filter account records in ‘Update Records’.

Input following Field-Value parameters to update records for various outcomes -

Default Outcome AI Output ← Neither Driving License, nor Passport detected For Driver’s License AI Output ← Driving License Detected Driving License NumberText from DL Number Query For Passport AI Output ← Neither Driving License, nor Passport detected Passport CountryText from Passport Country Query Passport Number ← Text from Passport Number Query Refer to the video given below for visual understanding -



3 - Test the AI-powered KYC Checker in action

Now that everything is setup, let’s test our flow. Follow the steps below to see this AI automation in action.

  1. Simply create a new Account record in Salesforce and then go the ‘Files’ tab that we added previously.
  2. Upload KYC document(s) using the ‘Files’ tab. You can upload the files one by one or multiple files at once. You can choose to upload passports, driver's licenses, or any other document types.
  3. The flow may take a few seconds to run so click on the refresh page on the top.
  4. Navigate to the ‘Details’ tab. You will find the relevant fields updated if the desired documents are uploaded, or the AI output will indicate if the Passport or Driver's License was not detected.

Congratulations! You've successfully created an AI-powered KYC Documents checker using CloudFiles AI & Salesforce flow.