Use Pega GenAI Connect to process incoming email and attached document

This knowledge sharing article demonstrates how Pega GenAI Connect can automatically classify and summarize incoming emails, as well as parse PDF attachment and map extracted data to case fields for further review and processing.

Pega Infinity orchestrates the AI-driven digital workers to streamline case management, delivering faster results, higher accuracy, and accelerated time-to-value.

Pega Infinity version used: 25.1.2

Runtime behavior

Step 1 - User sends a medical claim email.

Behind the scene, an email channel in Pega platform will detect the incoming email and create a case.

Step 2 - Claim processor opens a new case created.

Step 3 - The case is displayed with the incoming email details.

Behind the scene, a Pega GenAI Connect rule automatically classified and summarized the email based on the email content.

Click Submit.

Step 4 - The claim details are displayed.

Behind the scene, another Pega GenAI Connect rule automatically parsed the email attachment file and mapped to the case fields for review.

Here is the email attachment file:

HealthcareClaim.pdf (2.5 KB)

Click Submit.

Step 5 - Claim processor approves the claim.

Step 6 - Case is resolved.

How to configure

Step 1 (Email) - Set up an Email Account instance.

Configure both Sender and Receiver and test the connectivity.

Step 2 - Login to App Studio.

Step 3 (Email) - Create an email channel.

Select the Default email account configured above.

Add a suggested case type under the Behavior tab. This is the case type to be created for an incoming email.

Add an intelligent routing rule to create a new case.

Step 4 (Email) - Check for the email listener (auto generated) in Admin Studio.

Go back to App Studio.

Step 5 (Data model) - Create an Email data object with related fields.

Note: We often design data models first before designing case and workflow, and UI will be redered based on the data models in Constellation.

Step 6 (Data model) - Create a HealthClaim data object with related fields.

Step 7 (Data model) - Define necessary data models under ProcessClaim case type.

  • ClaimFile (Attachment) - Contains the medical claim document attached to the email.
  • HealthClaim (Embedded Data) - Contains the claim details parsed from the claim document.
  • EmailInfo (Embedded Data) - Contains the incoming email details.

Step 8 (GenAI) - Create the EmailParser GenAI Connect rule.

In User prompt, we are referencing .EmailInfo embedded data defined in the ProcessClaim case type. When the system create a new case for an incoming email, .EmailInfo fields will be set dynamically and sent to the GenAI Connect for processing.

In Response, we added .EmailInfo.QuickSummary and .Email.Classification properties which will be auto populated by this GenAI Connect rule after processing the prompt.

Here are the prompts:

System prompt: You are an email processing specialist responsible for analyzing email data to accurately classify and provide a quick summary.
User prompt: Process the following email received and provide a quick summary and classify the email.

Subject: {.EmailInfo.Subject}
Sender address: {.EmailInfo.SenderEmailAddress}
Sender name: {.EmailInfo.SenderName}
Received date and time: {.EmailInfo.EmailReceivedOn}
Email message: {.EmailInfo.EmailMessage} 

GenAI model used:

Step 9 (GenAI) - Create Process claim GenAI Connect rule.

We selected the Include attachment field for analysis checkbox and added .ClaimFile attachment-type property in order to process the claim document (attached to the incoming email).

In the Response section, we are mapping the GenAI response to the .HealthClaim embedded data fields.

Here are the prompts:

System prompt: You are a healthcare claims processing specialist with expertise in claim data extraction and validation. Your role is to carefully review healthcare claim documents and ensure accurate data mapping to standard case data models.

Instructions:
* Map the case HealthcareClaim.PDF attachment to the attachment field of this GenAI Connect rule.
* Extract all relevant claim information from the attached HealthcareClaim.PDF file, including but not limited to: claimant details, provider information, service dates, diagnosis codes, procedure codes, claim amounts, and authorization details.
* Map the extracted information to standard case data model fields, ensuring consistency and accuracy in field assignments.
* Identify and flag any missing information, incomplete fields, or data inconsistencies that require attention or follow-up.
* Validate extracted data against common healthcare claim standards and formats.
* Organize the extracted data in a clear, structured format that is easy for users to review.
* Highlight any potential issues, discrepancies, or anomalies that may impact claim processing or approval.
* Provide a comprehensive summary that includes both successfully extracted data and any flagged concerns. 
User prompt: Review the HealthcareClaim.PDF file attached to case and extract all claim data. Map the extracted information to the standard case data model fields and prepare a structured summary for review, including all flagged issues and missing information that requires attention. .

GenAI model used:

Step 10 (Case design) - Define Process claim case type, stages and steps.

Step 11 (Workflow) - Set the email data and call EmailParser GenAI Connect rule in the pre-processing activity of the Verify incoming email step.

Here are the activity steps:

Activity step 1 - Get the email instance key by passing the current case instance key. The case-to-email relationship is stored in the Link-Association-RelatedWork class.

Activity step 2 - Open the email instance (of class: Work-Channel-Triage).

This is where the email metadata such as sender address, subject, and received date/time are stored.

InstanceHandle = EmailLink.pxResults(1).pxLinkedRefFrom

Activity step 3 - Get the email message which is stored in the PegaSocial-Message class. This contains the email body.

Activity step 4 - Set the email data to the case.

  • Recall that the .EmailInfo embedded data is used in the user prompt of the EmailParser GenAI Connect rule.

Activity step 5 - Call the EmailParser GenAI Connect rule.

(Note: I was hoping that the EmailParser GenAI Connect rule was able to access the email content with a proper instruction and without having to manually write all those activity steps above, but it wasn’t able to when I tried. Hopefully, they can be abstracted in a future platform version.)

Step 12 (UI) - Configure the UI of the Veriy incoming email step.

Display the .EmailInfo embedded fields that were set in the pre-processing activity of the Verify incoming email step.

Step 13 (Workflow) - Set the .ClaimFile attachment field in the Post-processing data transform of the Verify incoming email step.

This DT is called after user submits from the Verify incoming email step.

.ClaimFile.pxAttachmentKey = D_AttachmentFieldInfoWC[LinkRefFrom: .pzInsKey].pxResults(1).pyAttachmentLink

D_AttachmentFieldInfoWC was copied and renamed from OOTB D_AttachmentFieldInfo data page in order to make the first parameter Not required.

We’re passing the case instance key to get the attachment key and set the .ClaimFile attachment property, which is referenced by the ProcessClaim GenAI Connect rule in order to process the email attachment (PDF document).

Step 13 (Case design) - Add the GenAI Connect step and call the ProcessClaim GenAI Connect rule.

Step 14 (UI) - Configure the Review claim details UI.

Add .HealthClaim embedded data.

Drilldown the .HealthClaim embedded data and add the detailed claim fields that were parsed from the claim document (=email attachment) by the ProcessClaim GenAI Connect rule.

= = =

Please feel free to leave any question or comment.

5 Likes

Very detailed information. Thank you for sharing. I had a client ask about this configuration yesterday. Will share this post with them.

1 Like

Thankyou for sharing detailed steps for processing claim information out from email using GenAI, its a great use case and am sure we can enhance models to process other communication channels like fax or contact us web portals too.

1 Like

Great article, @Will_Cho — thank you for sharing.

The Agentic Email Bot’s ability to read attachments and populate data on the Work object during case creation, as it avoids the need for the GenAI rule to reprocess the same information. As long as the attachment is included in the email and appropriate agent instructions are provided, the agent can successfully read the attachment and populate the required information while creating the work object.

I was also able to validate this behaviour for EmbeddedData in both Page and PageList, and it worked as expected.

1 Like

@RameshSangili thanks for sharing the information. Initially, I thought GenAI Connect was able to process the email attachment with a proper instruction but I wasn’t able to make it work (maybe i missed something). Thus, I had to manually link the email attachment to the .ClaimFile attachment field in the case using DT below. The .ClaimFile field is referenced in the GenAI Connect rule.

Set .ClaimFile.pxAttachmentKey = D_AttachmentFieldInfoWC[LinkRefFrom: .pzInsKey].pxResults(1).pyAttachmentLink

Perhaps, GenAI Agent rule can do it better.

2 Likes

Thanks a lot for sharing this extensive article, very useful!

1 Like

Excellent and well documented. A great use of GenAI to replace the ruta/regex statements in the text analyser rule that were quite a specialism.

1 Like