Enhancing Case Classification and Routing with Tone and Sentiment Analysis using Salesforce Einstein Generative AI, Apex, and Flow - Part 2

In my previous blog post, I explored the use cases of leveraging Salesforce Generative AI for case classification and routing. Now, let’s dive into the implementation steps using Apex and flow. By following these steps, you can empower your agents to handle incoming cases more efficiently and accurately.

Step 1: Craft the prompt and create a flex prompt template in the prompt builder and activate it , I primarily employ two techniques: instruction prompting for prioritization and zero-shot prompting for classification.

  • By analyzing tone and sentiment, I’ve clearly defined rules to prioritize cases, recognizing that criteria may vary across different organizations and circumstances

  • In my sample app, I utilize GPT-4 Turbo, which can perform tasks in a ‘zero-shot’ manner—without additional examples to guide it. Of course, you can also use instruction or example prompting to experiment accuracy.

  • Provide user persona for context and specify the results and the output in JSON format

Step 2: Write an invocable Apex method that calls the prompt template with grounded data and instructions for LLM, and produces output in JSON format, the invocable Apex method sample code can be found here

Due to the potential for bias and toxicity in Generative AI, it’s advisable to test the Prompt template by printing out the response safety score, here are the instructions

  • Uncommenting line 46 (screenshot below)

  • Run code sample below in anonymous apex window to generate the log,

    List<String> caseIds = new List<String>{'your_test_case_id'};

    CaseTriage.caseTriage(caseIds);

  • You can find the similar info as below, If the safety score is close to 1 and other attributes are near 0, it indicates a safe response.

    ConnectApi.EinsteinLlmGenerationSafetyScoreOutput[buildVersion=60.0, hateScore=0.0, physicalScore=0.0, profanityScore=3.0E-5, safetyScore=0.995304, sexualScore=0.00192, toxicityScore=0.00419, violenceScore=2.0E-5]

Step 3: Combine all components into a record-triggered flow: first, extract AI information and output from the invocable Apex method, then proceed with routing and updates in the flow to complete the entire process.

You can access the sample app source code in this Github repository - case-triage-generative-ai . Feel free to experiment with different prompts and configurations. Generative AI provides exciting opportunities for developers to innovate, but we must also be vigilant about potential biases and ensure responsible use. If you have any questions, don’t hesitate to reach out

Previous
Previous

Comparing Picklist, Multi-Select Picklist, and Text Variable Types in Salesforce Flows

Next
Next

Enhancing Case Classification and Routing with Tone and Sentiment Analysis using Salesforce Einstein Generative AI, Apex, and Flow - Part 1