Tutorials
Document AI Tutorials
Using AI for Simple Data Extraction from KYC Files
overview in this tutorial, we will see how cloudfiles can be used with salesforce flow automations to extract data from uploaded documents each time a file is uploaded into salesforce or external storage, the following actions will occur the file is processed using cloudfiles document ai a natural language query executes to extract information from the driving license information is automatically updated in its respective fields in order to setup this automation, you first need to have some pre requisites after this you can start setting up some query automations and updates to achieve your use case check the sections below for more information pre requisites before starting with this tutorial, you need to ensure that cloudfiles document ai is properly installed & configured in your system additionally, you also need to create some initial automations to process the files before you can query them check the 2 sections below carefully installation & configuration ensure the following before starting cloudfiles document ai installation docid\ rfxciqrbejmpsmbczexam and configuration docid\ amnhmxwixyngnaxerbkwd are complete you have an active subscription or trial of cloudfiles document ai the cloudfiles event mode setting is set to custom object initial automation setup there are 2 flows you will need to setup to process the uploaded files the first flow is triggered when the document is uploaded into salesforce or external storage this flow sends the file to ai for processing this might take a few seconds once the ai is done with processing, the second flow will trigger which will contain the processed document you can then run queries on this processed document flow 1 send document for processing triggered when file is uploaded into salesforce or external storage sends the file for processing which may take a few seconds to a minute flow 2 document processing complete triggered when the file has been processed by ai performs queries on the file to extract the data all information related to setting up these flows is given in the ai flows initial setup guide docid\ sxn79rxu7gw7bb6ogpuix article please go through this article carefully to set up these flows once your flow setup is complete, your flows should look like the following read the article on ai flows initial setup guide docid\ sxn79rxu7gw7bb6ogpuix carefully to setup both the flows once your initial flows are setup as shown above, you are ready to move to the next step query automation setup now that you have the initial automation setup, we can take the document processed flow and extend it to query the document and update the required fields in this section, we show how to query the processed document, check the results and perform the necessary updates querying the document in order to query the document, we will simply use the query document docid\ dm3eh gzaocyoqd5y0r8d flow action this action taken in a processed document id and a text query as input the processed document id is available as output of the get event details action here are the full inputs used in the images below processed document id = triggering cldfs cloudfilesevent c" ( {!get triggering event details documentprocessed processeddocumentid} ) query = enter a clear natural language data extraction prompt such as return the full name including the first and last name of the driving license holder processed document id = triggering cldfs cloudfilesevent c" ( {!get triggering event details documentprocessed processeddocumentid} ) query = enter a clear natural language data extraction prompt such as return the driving license issue date in dd mm yyyy format processed document id = triggering cldfs cloudfilesevent c" ( {!get triggering event details documentprocessed processeddocumentid} ) query = enter a clear natural language data extraction promptsuch as return the driving license expiry date in dd mm yyyy format the extracted date is returned as a text string but can be converted to a date type data type using salesforce formulas processed document id = triggering cldfs cloudfilesevent c" ( {!get triggering event details documentprocessed processeddocumentid} ) query = enter a clear natural language classification prompt such as return the driving license number updating contact record the query document action above outputs text variables which is the full response of ai for the given query to find the right contact record compare ‘ 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 contact records in ‘ update records ’ now set the field values manually as shown in the below image see it in action now that everything is set up, you can test your flows when a driver's license is uploaded into a contact folder from cloudfiles lwc on contact record page, the mapped fields should be updated automatically note as flow automation executions and document processing via ai may take a short time, the field updates will not reflect immediately to view the updates, wait briefly and refresh the page flow 2 debug whenever a file is processed using the process document using ai docid 31ujx1ligtkwfkjuanbzt action, a document processed docid\ xrr pnbpocwwcmyg6qgk9 object record is published you can query these event object records to verify successful file processing and debug the flow example soql query to check document processed events sorted by the most recent select id, name, createddate, cldfs data c from cldfs cloudfilesevent c where cldfs type c = 'document processed' order by createddate desc you can check the context and file details in the data field of the record when a flow runs in debug mode and executes query document docid\ dm3eh gzaocyoqd5y0r8d actions, you can check the results and modify the queries if required