Leverage Prompt Builder and Flow Builder to automate data creation

Leverage Prompt Builder and Flow Builder to Automate Data Creation | Automate This!

By

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, learn how Erick Mahle leverages Prompt Builder and Flow Builder to streamline processes, enhance productivity, and deliver personalized experiences through generative AI at Lendz Financial.


Generative artificial intelligence (AI) has matured past the hype stage, and there are now several ways that companies can leverage this technology. As companies apply generative AI to their processes, one of the (many) learning lessons they encounter is the realization that productivity gains from it require a lot of good data.

Like many organizations, you might’ve experienced the years of workaround solutions (the infamous “tech debt”) that have come around to tell you that before you get serious about generative AI at a large scale, you may need to take two steps back and fix a few things to set you up for scalable success.

With that in mind, there are a few ways to get started with generative AI that don’t involve completely redesigning your data model and cleaning up years of bad data. At Lendz Financial, we decided to try Prompt Builder instead of working with the OpenAI API platform and were pleasantly surprised at how well Prompt Builder simplifies this process.

One of Lendz Financial’s core initiatives is to revolutionize mortgage lending (specifically, our niche) by bringing forward a large digital transformation effort. Part of this includes using large data warehouses to get a true understanding of our customers and our industry. We’ve rolled out Data Cloud, generative AI, Marketing Cloud Account Engagement (MCAE), and more as we look to transform our organization and processes from our business development through operations.

Use case: A simple and profound greeting with gamification

Lendz Financial is a growing leader in wholesale Non-Qualified Mortgage lending (also known as NQM). As a wholesale lender, that means we grow by working directly with brokers instead of the borrowers looking to purchase a house. Brokerages can range from a single loan originator to hundreds, all representing their borrowers to help them get a mortgage on a home.

In a market where interest rates and other components change frequently, one of the ways we keep our partners updated is with a traditional weekly newsletter. All of the brokerage firms that have signed up with Lendz Financial subscribe to it.

And with undeniable excellence in our ethos, one thing we’ve decided to do is leverage generative AI to create a unique greeting personalized to each loan originator on our newsletter list. The idea is to generate a new sign-off every week to our originators that takes a few things into consideration.

  • Congratulate them on any recent business we’ve successfully accomplished together.
  • Pair them up against their peers: If other colleagues within their own firm have done more business recently, challenge them to take the top of the leaderboard by sending a few more opportunities our way. If they’re at the top of the leaderboard, then recognize that over the number of loan originators in their organization.
  • If we haven’t won a deal together yet, we encourage them to get in touch with us to find a few strategies on how they can get their first (of many) deals.

How we do it is fairly simple and only requires a few key fields and some basic automation before asking Prompt Builder to fill in the blanks. So, as long as you’re tracking contacts, opportunities, and some way to connect the two (hopefully, with Opportunity Contact Roles), you can do the same!

The declarative configuration

First, we need four fields primarily on the Contact object.

  1. Opportunities within the last 120 days: This number field should reflect a count of how many opportunities your contact has been a part of within that time frame. A simple reminder that 120 days is an arbitrary range; use the range you think is most realistic in your organization or industry.
  2. Last Won Opportunity date: This date field represents the most recent opportunity won that your contact has participated in.
  3. Last Opportunity date: This date field represents the most recent opportunity that your contact has participated in (Open, Won, or Lost).
  4. Account Engagement Weekly Greeting: This long text area field is where the results from your prompt will be stored. In our case, since we use MCAE, we created a custom field for the prospect record in MCAE that syncs to this long text area field.

Four necessary fields on the Contact page layout.

The next portion contains three flows that make the magic start to come together.

List view of flows needed for the weekly greeting use case, with their relevant descriptions.

  1. A record-triggered before update flow to roll up the opportunity statistics into the Contact record
  2. A template-triggered prompt flow to help augment the prompt you’ll send to your generative AI tool of choice
  3. A schedule-triggered flow that runs weekly to trigger the greeting at each contact to be refreshed with the latest opportunity numbers and ranking

Summarize key data fields with a record-triggered flow

The first key flow is your contact before update record-triggered flow, which I’ve labeled “Automate This - Contact - RT Before Update”. It may look complicated, but it’s fairly straightforward. All it does is summarize three of the key fields that we’ll need for Prompt Builder: the count of opportunities within the last 120 days, and the most recent dates for an opportunity created and won.

“Automate This - Contact - RT Before Update” record-triggered flow.

This flow probably looks a bit more complicated for a simple need. I try to leverage as many Flow Builder best practices as I can, which includes avoiding as many data manipulation (DML) elements as possible while reusing what I already have. Let’s break it down from top to bottom.

1. From the Contact record, we use a Get Records element to find all of the opportunity contact role records associated with that Contact, and then loop around the collection to add the opportunity IDs from each contact role record into a text collection variable.

“Automate This - Contact - RT Before Update” record-triggered flow.

2. Using that text collection variable, we then use our final Get Records element to get the opportunities themselves. You could simplify this flow even further if you decide to store your necessary information from the opportunity at the opportunity contact role level with a few custom fields. It would simplify this flow quite a bit, just add a few extra steps in custom fields. Note: I recommend creating actual number/boolean/date fields over formula field equivalents at the opportunity contact role level if you decide to go that route, especially if your org handles large data volumes.

“Automate This - Contact - RT Before Update” record-triggered flow.

3. Finally, we use a Filter element to get our count of opportunities within our requested time range, and then loop all opportunities to find the most recent submission and the most recently won with a few Decision elements.

“Automate This - Contact - RT Before Update” record-triggered flow.

Get started with Prompt Builder

Once you have all of the information you need, it’s time to head to Prompt Builder. I’ve said it at the start: Salesforce truly made this an accessible tool for all declarative admins. It takes working directly with OpenAI’s API platform to understand some of the complexity, but here are a few key things that you might not realize.

If you’ve played with a large language model (LLM) tool, the first thing you look at is where you type in your prompt. With Prompt Builder, that’s your Workspace. You can select to ground your prompt with data and, similar to building flows, can choose the resources you’d like to leverage, which makes it very easy to familiarize yourself with it.

Example Prompt Template Workspace.

Now, there isn’t anything crazy special about using merge fields within the Workspace, much like you could with merge fields in an Email Template. However, the fact that you can place whole related lists in the prompt (with no need for flows or any automation!) is something to truly shout about. Being in this ecosystem since 2010, I have to say that the ability to call a related list without having to build a flow is really awesome.

Prompt Template Workspace showing the object’s related lists.

There are times, however, when related lists alone are not enough firepower. We need to deliver an extra level of attention. This is where you can call your flows into play, for that more complex data gathering, to help shape your prompt into whatever you need before sending it out. In our use case, to have the gamification we sought, we decided to leverage Flow Builder.

Enrich prompts with data using a template-triggered prompt flow

This next flow is slightly more complex than the first one, simply because it helps structure the key part of our prompt: understanding how the recipient of our greeting ranks within their organization and helps complete our prompt. Naturally, the first step here is to use the new flow type, a template-triggered prompt flow.

There are two key pieces about this flow type: $input record global variable and the Add Prompt Instructions element, which is where you set the output of your template-triggered prompt flow to pass data back to the prompt.

Prompt Instructions resource in the flow canvas.

New Add Prompt Instructions element in the flow canvas.

A quick note for those attempting their first template-triggered prompt flow. As a Flownatic myself, finding the Input variable took me a few tries, as my muscle memory kept searching for the {!$Record} variable. Instead, here you’re searching for {!$Input}, even though they behave in an almost identical fashion.

Let’s break down the key portions of this flow, from top to bottom.

The template-triggered prompt flow for Weekly Greeting.

1. The first part of the flow uses a Get Records element to find all Contacts under the same AccountId and gets a count of records within that collection. We’ll address lessons learned at the end, but one of them is that we needed to train the prompt to only “gamify” if there was more than one loan originator within the Account. Otherwise, the LLM starts claiming they did a great job against themself.

The first portion of a template-triggered prompt flow for Weekly Greeting.

2. We set an initial Loop element to find out our Top Performer within that account by comparing the number of opportunities within the last 120 days. Once that loop is done, we use a Decision element to start building our Prompt by either congratulating them if they did a great job or challenging them to catch up with the Top Performer.

The second portion of a template-triggered prompt flow for Weekly Greeting.

3. The final Decision element sets up prompt guidelines under different scenarios for us. We want to add those details for the LLM to consider to help it craft the best possible greeting. We chose to consider four different potential scenarios for our contact.

  • Has deals within the last 120 days: This means this person is actively engaged.
  • Has won deals but nothing within the last 120 days: This is a critical contact for us. We want to acknowledge their great work and get them re-engaged if we can.
  • Has deals submitted, however, nothing closed: This shows us we’ve tried in the past and we need to get that extra push with them.
  • Has no deals submitted yet: This means we want to try to get them engaged and help them achieve their first win with our organization.

The final portion of a template-triggered prompt flow for Weekly Greeting.

And that’s it! Once you’ve gone through your paths to identify the prompt, you set your final element (Add Prompt Instructions) to establish the prompt instructions and pass it back as a data resource to Prompt Builder.

One quick note for these new types of flows: In my experience, I really appreciated using a combination of Decision elements and Text Template resources to be able to assign the correct statement at each step of the prompt. It’s so much cleaner than typing it all in at each Assignment element.

Using Text Template resources to assign prompt instructions.

The Text Templates we create simply map to the primary text variable that’ll carry our prompt instructions based on the Decision element path that it follows. For example, if someone has submitted an opportunity fairly recently, there will be a decision path that’ll guide them toward a Text Template with a specific message for contacts that find themselves within that category.

Mapping Text Template resources to the text variable that will be within the final Prompt Instruction element.

Once your flow travels through all of the elements, the text variable you’ve created will have everything it needs to pass the prompt instructions back to Prompt Builder to make its request.

Mapping the final text variable to the Prompt Instructions.

Tie everything up

Once you’ve activated your template-triggered prompt flow, head back into the prompt template you built in Prompt Builder. Using the Resource lookup, you’ll be able to select the template-triggered prompt flow.

Selecting the template-triggered prompt flow using the Resource lookup.

Next, let’s talk about two new areas underneath the Workspace: the Resolution and the Response. In this section, you can select a Preview record to test a prompt one time to see how everything looks and to test and debug your work thus far.

Resolution and Response areas in the Workspace.

Once you select Preview, the Resolution section will populate with the final result of the prompt—instructions from the Prompt Builder Workspace and the grounded data; in this case, the record data and data from the referenced flow. Here, you can take a look at what needs to be fine-tuned and validate the resolution for accuracy.

Resolution section in Prompt Builder.

I used this extensively to spot check several records and see if the prompt made sense. There were several rounds of revising flows to make sure everything came out as we had hoped. You’ll learn quickly that you’ll want to debug a lot with these single tests, and avoid the costly test of running it across all of the records within your org.

On the right side, you’ll see the Response. This is what the generative AI provider (LLM) generates with your prompt instructions. You can click Preview a few times to see different variations. But in our quest for an ultra-personalized newsletter email sign-off, here’s what we came up with.

Response section in Prompt Builder.

Once the prompt instructions look good, activate your prompt template.

Schedule updates to get a personalized weekly greeting

The final flow is a scheduled flow that runs weekly on the Contact object to get an updated greeting once a week. We typically like to run this during off-hours (Sunday morning or evening are great options if your business is primarily a 9 to 5).

The scheduled flow for the Weekly Greeting.

This flow is a very simple one. Effectively, we select to run it off the Contact object, and we typically try to put a filter on it so it only updates the contacts we want. For example, if there are thousands of contacts that have never signed up to do business with you, it may not be worth it to dedicate all of the resources and requests from Einstein AI to personalize communication to them.

Always keep in mind that Prompt Request is a pay-as-you-go resource in Salesforce, so it makes good sense to add the right filters to limit how often you use it, especially when testing and starting out.

The Start element of a scheduled flow for the Weekly Greeting.

The rest of the flow is fairly straightforward. With the Action elements, you can invoke the prompt you’ve created for the greeting. The action will have an output element which is the prompt response—all you need to do at this point is map the response to the Account Engagement Weekly Greeting field on your Contact record, and you’re all set.

The prompt Action element of a scheduled flow for the Weekly Greeting.

One final consideration: Since this org has a small number of contacts that get Weekly Greetings generated, the scheduled flow above is more than enough to get the job done. You may want to leverage more complex declarative tools, such as Platform Event flows, if you need to handle tens of thousands of records or more.

Let’s recap

With a couple of flows and other basic declarative configuration, we’ve put together a great prompt that will deliver a unique experience to our partners and customers. No code, no complications. If you’re using a marketing automation tool such as MCAE, it’s simply a matter of mapping this field to your email content, and you’re good to go!

The final Weekly Greeting result on the Contact layout.

The most striking piece of it all is to think how Salesforce manages to do such a good job already in its early iterations of Prompt Builder. Having originally done this without Prompt Builder (with flows and an HTTP callout to OpenAI’s API platform), there were a lot of complications that we needed to unravel and familiarize ourselves with. Ones that you may never experience because Salesforce does a great job of simplifying the Prompt Builder user experience. Remember, at the time of this article, generative AI LLM tools are barely over a year old. And while you may never experience these pain points if you rely on Prompt Builder, I’ll break some of them down below with our lessons learned as we ventured into generative AI.

Lessons learned with generative AI tools

The Einstein Trust Layer: Doing the hard work for you

One of the things that excites me the most is the Einstein Trust Layer. In a world where data security is making news headlines more and more often, it’s critical to secure your data. And passing data in between Salesforce and your generative AI tool of choice puts it at a greater risk of breach since that data resides in more than one system.

Typically, we start getting into very serious compliance and technical conversations to use the right levels of encryption and permission settings to keep our data safe and secure during this exchange between databases. Several countries have their own data compliance requirements, and federal regulators may even impose certain restrictions on what can be done with publicly traded companies.

To make this extremely complex subject simplified for any declarative administrator, Salesforce introduced the Einstein Trust Layer, which effectively masks and secures your data before it’s sent out to avoid passing any compromising information over, running your prompt and demasking the data once it comes back.

The Einstein Trust Layer.

This effectively means that if you pass any personally identifying information (PII) or sensitive personally identifying information (SPII) to your generative AI provider, they will not see any of that information when actually executing the prompt, keeping your data safe and secure.

This is much different than data you include in your ChatGPT prompt. ChatGPT sees all that data and learns from it. We attempted to mask our data when building a direct integration with OpenAI’s API platform, and it took a lot of work to get it right. It’s something that can be easily taken for granted by someone who has not embarked on a similar project. But it’s probably one of the most crucial functionalities that enables Salesforce Admins to successfully and securely get started with generative AI without compromising their organization’s data integrity and security.

Additionally, when it comes to pricing, it took us a long time to properly understand how OpenAI and its token pricing model works. It’s a pay-as-you-go model based on how much computing power you use. That means there’s one calculation for input tokens and one for output tokens, which all depends on how many characters you pass through (and it outputs) as well as the GPT model you use.

Confused? That’s the simple version.

Salesforce again takes on the brunt of the work here by simply charging you per “request”, taking all of the complex calculations out of the way. Simply speaking, every time you submit a prompt over, that’s a request. Easy peasy. If you’d like any information beyond that, I recommend contacting your Account Executive.

Invent. Iterate. Industrialize.

Another key thing we’ve learned is that getting something like this right takes time and a lot of fine-tuning your prompt. Prompt engineering is an art; it takes practice to strike exactly the right message before it’s ready for prime time. In this example, you’ll see that about 50% of our prompt, highlighted in yellow, is just fine-tuning the tone of the message.

Example of a prompt template, with highlights to indicate how much of the prompt is iterative guidance to get the tone of the message correct.

In our case, when we were 90% there, we created a report in Salesforce with Weekly Greetings. We reviewed them across the report to see if anything stood out, looked odd, or seemed incorrect—putting that human in the loop. Then, we re-ran the Weekly Greetings. It took us 3-4 weeks before our team was comfortable with the prompts, as they were to be included in the weekly newsletter content.

Less is more (for your first attempt)

There’s no shortage of realization about the importance of data in 2024—how it’s structured, the quality of it, and so on. At times, this can mean that the first use case you come across that may sound beneficial for your company may not be the ideal one to get started if the data isn’t up to standard to support it.

While we’ve worked on more complex generative AI projects, we picked this example because of its simplicity; all you need is a count of opportunities associated with different contacts within an account. That’s typically data that can be easily relied upon—you won’t run into a lot of scenarios with missing data or complex data structures.

Familiarize yourself with something easy, then use that experience to make a use case for larger projects that may include some cleanup of data or tech debt.

Accelerate data generation with AI

Lendz Financial has an array of exciting projects on the horizon. Through numerous small projects and proof-of-concepts with generative AI, we’re gaining a clearer picture of how this technology can drive productivity gains and provide an undeniably excellent user experience for our employees and partners.

These projects have deepened our understanding of the interplay between AI and Data Cloud and how each will have a significant role in our future as we accelerate data generation and harness its potential. Like many organizations, we’ll continue to revisit and refine our past data models to progress through upcoming milestones. Salesforce's commitment to providing the tools we need ensures that Lendz Financial can scale securely and successfully.

Resources

Want to see more good stuff? Subscribe to our channel!

SUBSCRIBE TODAY
Headshot of Kristi Brown next to text that says, "Automate This! — Power Up Your Einstein Bot with Flow."

Automate This! — Power Up Your Einstein Bot with Flow

Welcome to another Automate This! In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by #AwesomeAdmin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, let’s see how Kristi Brown tackles some everyday […]

READ MORE
Increase productivity and create starter flows fast with Einstein for Flow

Increase Productivity by Creating Starter Flows Fast Using Einstein for Flow | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, learn how Eduardo Guzman enhanced productivity and […]

READ MORE
How I Created a Solution to Test Scheduled Flows Easier During UAT

How I Created a Solution to Test Scheduled Flows Easier During UAT | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, let’s see how Nancy Brown created a […]

READ MORE