Prompt Engineering for Salesforce Developers
Prompt Engineering for Salesforce Developers
Prompt engineering techniques, if done right, can help you get things right, better, and most importantly, faster.
At Dreamforce 2023, there were several sessions on AI. My favorite was presented by Jakub Stefaniak, VP of Technology Strategy and Innovation at Aquiva Labs. In his presentation, Jakub discussed how to augment developer efficiency with large language models (LLMs) using the concept of prompt engineering.
In this blog post, I’ll summarize his insightful information on leveraging prompt engineering as a Salesforce Developer, along with some specific use cases. These techniques can help you get the best out of an LLM like GPT or ChatGPT, which is fine-tuned from GPT-3.5 and optimized for dialogue.
What is prompt engineering?
A prompt is a text input that you give to a LLM to tell it what to do. Prompt engineering is the art of crafting prompts so that the LLM understands what you want. It’s about making clear prompts that help you talk to the LLM in a way it understands perfectly.
Jakub further explains prompt engineering in the following quote.
Prompt engineering is like software engineering in a new programming language.
Building an app is an iterative process — you start with an idea and then keep improving the code until the app works as expected. Prompt engineering works the same way, with one key difference. Instead of refining lines of code, you refine words and sentences in natural language. So, rather than iterating on programming languages, you iterate on plain English prompts to guide an AI system. The goal is the same: through progressive rounds of tweaking and refinement, you aim to arrive at instructions that yield the desired results.
With software, you craft logic in code. With prompt engineering, you craft logic in language that the LLM understands. It’s an iterative approach to translating what you want into the best prompts in order to make AI models produce your desired outcome.
The general guidelines for writing effective prompts are as follows:
Be clear and specific to begin with
Analyze why the results are not providing the desired outcomes
Refine your ideas and prompts
Repeat the process
Prompting techniques
Let’s take a look at three advanced techniques that Jakub explains can benefit Salesforce development use cases.
Role prompting
With role-based prompting, we ask the LLM to behave as a specific persona. For example, we can start a prompt with “Act as a Salesforce Expert/Salesforce Developer.”
To understand this, let’s take an example prompt like below.
csharp
Copy code
Act as a Salesforce Developer, expert in managing technical debt. Explain the best practices of Apex.
Using delimiters
Using delimiters allows AI to understand my request and the input needed to produce the best results. A delimiter can be used to clearly indicate distinct parts of the input. An example prompt for this is shown below.
css
Copy code
You are Senior Salesforce Developer, Expert in Clean Code Development. Explain the code enclosed within triple backticks and propose how to improve it.
Few-shot prompting
By default, the prompts that we write for the LLM are zero-shot prompts. With zero-shot prompting, the model generates a response without any prior training on specific prompts. A common technique to improve results is by providing enough examples to the prompt. The screenshot of the slide from the session below clearly explains this technique with an example.
Common prompt engineering use cases
Next, let’s take a look at some important use cases highlighted by Jakub. These use cases, when adopted by developers, have shown great benefits in improving efficiency.
Diagram generation
Salesforce Developers often need to produce diagrams, such as data models, class diagrams in the Unified Modeling Language (UML) format, or sequence diagrams, in order to document their work. The LLM can generate all of it by providing appropriate prompts and specifying the output format.
For example, to generate a UML, we can give the LLM a prompt like below.
css
Copy code
Prepare a UML diagram of the below classes. Generate the output in PlantUML code format.
Metadata XML generation
The few-shot prompting approach enables generating metadata XML for Salesforce DX source format. To do this, you’ll need to provide the language model with:
A PlantUML code of your data model
Examples of XML metadata representing objects and fields
Code generation
Salesforce Developers can generate Apex and LWC code using general-purpose large language models like GPT. To provide a model customized for Salesforce platforms, we created Einstein for Developers (in Open Beta), trained specifically on Apex, LWC, and related languages.
Unit testing, code explanations, and code refactoring
Other popular use cases that can immensely benefit Salesforce Developers are unit testing, code explanations, and code refactoring.
Should you consider prompt engineering?
A common question that you may have as a skilled Salesforce Developer is: should you consider using prompt engineering in your day-to-day work?
I particularly liked the importance of the human in the loop here if accuracy is the goal. Another important element I would like to add here is security. When using generative AI tools like ChatGPT for Salesforce-related tasks, it is important not to input any customer-sensitive data to the LLM. This can potentially expose security risks. We have created an Einstein Trust Layer that allows you to safely adopt generative AI on the Salesforce Einstein 1 Platform.
Conclusion
Prompt engineering techniques, if done right, can help you get things right, better, and most importantly, faster. The techniques we have covered in this post are general and apply to any LLM. I want to thank Jakub again for sharing a wealth of knowledge about prompt engineering techniques with Salesforce Developers.
In the next blog post, we will dive into some more special prompting techniques when working with Einstein for Developers, Salesforce’s AI assistance tool that helps you generate code for Salesforce-specific languages like Apex.
Comments
Post a Comment