top of page

Challenge 030 | Custom Prompts

A year ago I created a challenge called Prompt Engineering for Power Platform. We all know a lot has changed since. I purposely didn't focus too much on the GenAI features in Power Platform in the mean time, as the Copilot train was moving faster than I can type. Now that the dust seems to settle, I think it's a good time to see how we can use it and especially what value it can bring to business scenarios.

Challenge Objectives

🎯 Creating good prompts

🎯 Learn how to use it in business scenarios

🎯 Understand the capabilitites for each Power Platform product

Create a good prompt

In last year challenge I referred to a short course I did called ChatGPT Prompt Engineering for Developers. I still highly recommend dedicating some time to really understand how these Large Language Models operate and how you can use them.

In the meantime, Microsoft released the AI Builder | Prompt Builder A Prompt engineering guide. This is a document that basically boils down the thing you need to know in 10 pages.

To get things even simpler, I copied in what I think is the most important part of what a prompt should be. You can think of it as the anatomy of a prompt.

The screenshot is quite self-explanatory of what it should entail. A good thing to keep in mind is that a prompt can, obviously, handle text pretty well. By that I mean that if you elaborate on what it should do (and NOT do), it will have more detailed context and will in general give a better output to fit your need.

Getting to the best prompt is quite an iterative process. At first it may seem like trial and error, but you will get better at it over time. Again, dedicating some time to actually learn how LLMs operate will make you understand what the possibilities are and will be a great ROI overall.

The good news is that Microsoft really simplified the process of creating prompts for Power Platform. We can easily add input data as context, test the prompt to see the response, tweak the prompt to get towards your required output, and keep doing that until you're satisfied. Let's see how to do this.

Create your first AI Builder prompt

  1. Go to make.powerapps.com

  2. Navigate to AI hub

  3. Select the Prompts tab/button

  4. Select the Custom Prompt option from the gallery

There are also predefined templates available that you can use. I think you should skip these. Exactly the same actions are made available in Dataverse. This means you can write a simple Power Fx function in Canvas Apps, or perform an unbound action in Power Automate. Much easier.

We can now start writing our prompt. Our scenario is that we have a Teams channel called Ask the Expert with Power Platform makers as members. They will ask questions when they are working on their app or flow. We want to create a prompt that will use the maker question as in input, and give an answer as if the AI is a Power Platform consultant.

Act as a Power Platform Consultant. You will be given some questions from makers within this organization. The makers can be relatively new to Power Platform, so make sure to answer in a step-by-step solution approach. The question: makerQuestion

Can You identify the task, context, expectations and output as shown in the anatomy screenshot? I do have to say that I did not made it as clear (could be improved), but it basically does contain the 4 elements.

Pro tip: Use Copilot to help you write good prompts. You can give your current prompt, explain what the problem is with the output, and ask for an adjusted version.

Telling the LLM it will receive a question and at the end of the prompt actually giving the question is something I learned from the course, and works pretty well from my experience. This way you can clearly separate the instruction from the context.

The makerQuestion is an input parameter. At my client this scenario is real, so I just looked at what a recent question was and translated it to English as Sample data.

Hello fellow makers!

Does anyone has some spare time to help me out on a Power Automate flow?

What we want to achieve:
- Project Manager publishes report in Oracle (already working)
- Oracle pushes the report to the Project Site in SharePoint (already working)
- Send a message in Teams channel 'project management internal' that says "A new report is available. View report" where View report will be a link to the document in SharePoint. (not working yet)

How can I make this last step work?

Thanks in advance!.

You can see that the context is relatively easy to add to the prompt. Just like Dynamic content in Power Automate basically. Below you can see the output it gives when testing the prompt.

To achieve the final step of sending a message in Teams with a link to the document in SharePoint when a report is published in Oracle, you can follow these steps:

1. **Create a Power Automate Flow**:
   - Go to Power Automate and create a new flow.
   - Choose the trigger based on the report being published in Oracle.

2. **Get the Document Link**:
   - Add an action to get the link to the document in SharePoint where the report is stored. You can use the "Get file metadata" action in SharePoint connector.

3. **Compose the Message**:
   - Add a "Compose" action to create the message you want to send in Teams. Include the text "A new report is available. View report" and use the dynamic content to insert the link to the document.

4. **Post Message in Teams**:
   - Add an action to post a message in the Teams channel 'project management internal'. You can use the "Post a message (V3)" action in the Teams connector.

5. **Test and Debug**:
   - Test the flow by publishing a report in Oracle and ensure that the message is posted in the Teams channel with the correct link to the document in SharePoint.

By following these steps, you should be able to successfully send a message in Teams with a link to the document in SharePoint when a report is published in Oracle. If you encounter any issues or need further assistance, feel free to ask for help!

That is actually a pretty decent answer, right!

You have probably heard of hallucination when using LLMs. That's why Microsoft's Responsible AI Standard state that there should be human oversight when using LLMs. This is also part of the 10 pager's do's and don'ts. When you have been using Copilot, you have probably noticed it will give you a suggestion that you can easily implement, or adjust. We want to do the same.

For that we will simply use Power Automate and Approvals.

Implement a Prompt in Power Automate

After you have saved your prompt, it's time to create a Power Automate flow. I will show the Power Automate flow first, and then talk you through the things that are of interest.

  • The trigger is quite straight forward. We select the Team and Channel where we expect the questions from.

  • The Predict action is from AI Builder. Your prompt is stored as an AI model. That's where you can find it. You can select the prompt you just created and feed it the message body as the makerQuestion.

  • I initialize a variable. The reason for this is that we want to quickly approve the suggested answer, or use the comment field from Approvals to copy over the suggested answer and adjust it accordingly. As I am typing, an Cards for Power Apps card might even be a more suitable option, but that would drift us away from the prompt topic.

  • The message body is in HTML, as you can make things bold, etc. We don't want to see all the HTML tags, so we can use a fairly new connector to quickly make the HTML in plain text.

  • Then we start an approval. We set it to first to respond and give the following details:

  • With the condition I do some trickery that probably can be done in a neater way. The output of the comments is in an array, and only in the JSON output when an actual comment has been given. To do this, the condition contains the function below. I use first() so I don't get an apply to each, and add a length() function so I can check if something is there with is greather than 0.

length(first(outputs('Start_and_wait_for_an_approval')?['body/responses'])?['comments'])
  • If there is a comment, I want to respond that to the maker. Below you can see the function. I intentionally used [0], which does exactly the same as first, but written differently. You can use this option if you want the second [1] or third [2] etc. I also use a replace function, that replaces enters (%0A) with <br>. This is to make the text HTML friendlier, as we want to respond in Teams, which interprets the text as HTML.

replace(outputs('Start_and_wait_for_an_approval')?['body/responses'][0]?['comments'], decodeUriComponent('%0A'),'<br>')
  • If no comments are given, the prompts response can be used as the answer. You can see the replace() function here too to achieve the same functionality. I haven't put this in the 'if no' section, as it will throw an error when there is no comment given. This won't be in the payload. That's why I do it after the condition and set the run after to has failed.

replace(outputs('Predict')?['body/responsev2/predictionOutput/text'], decodeUriComponent('%0A'),'<br>')
  • The last step is to actually reply to the question with the HTML formatted answer. We have to add the is skipped option to the run after settings, as the run after failed will be skipped when a comment is given (as there will be no error).

You can now give it a try in your own tenant. Below you will see the question with the different outputs.

The first response is without the replace action, so everything is right behind each other.

The second response is exactly what the prompts response is. We could improve the formatting of ** (which is Markdown for bold), but we leave that out of scope of this challenge.

The last response is when a comment is given.

You have created a prompt and have been very responsible by keeping a human in the loop for this process. This way a Center of Excellence member or Adoption Consultant will only need to review and potentially adjust the answer, rather than coming up with the answer from scratch. This will improve answering speed, improve community effectiveness and create a great knowledge base for future makers.

Now, let's see how we can use it on Power Apps.

Your Second Prompt

For the second prompt, we will use a real world scenario again. At my client Schiphol Airport, we have a solution intake process. This is a simple Microsoft Forms form where every employee can submit their idea. The data will go to a SharePoint list where the intakes are managed. Here we will basically decide if we will build it or not. If we will, we will create User Stories and store them in Jira.

Our second prompt will help us creating User Stories based on the business scenario given by our employees.

Act as a Scrum Master. You will receive a business scenario. Create a list of User Stories based on the scenario. Each User Story should have a Title, Description, and Story Points. Make sure the Title will have 6 words as a maximum. Business Scenario: businessScenario

I iterated over the prompt a few times. The titles were too long to my taste, so that's why I included the instruction to make it 6 words max.

The prompt isn't really much different from the previous one, except for one thing. We can specify the output as JSON. Very handy. You can see the Prompt response contains an object called userStories, which is an array of all the different User Stories. Great for a Gallery in Power Apps.

We will quickly move on to Power Apps. We will create a simple app that shows all the solution intakes. We can select one and then generate User Stories based on the business Scenario. We want this is a gallery so we can adjust it before we push it to Jira.

Add Prompt to Power Apps

Just like in Power Automate a Prompt is visible as an AI Model, so is the case in Power Apps. Adding the AI model to your app is done at the data tab.

As you can see, I added the SharePoint list and the AI model. The rest is actually relatively straight-forward. I created potentially the ugliest app ever, but the goal is to bring the potential of prompts across.

It's ugly right? But please let me explain what the app can do. The left vertical gallery is based on the Solution intakes that are stored in SharePoint. The business process section shows the input from the user who submitted the form. The button Generate User Stories will grab that Business Process and use it as context in our earlier created prompt. As the output is in JSON, we can store it on a collection. The Power Fx function is pretty easy.

ClearCollect(colUserStories, 'Power Platform Scrum Master'.Predict(lblBusinessProcess.Text).StructuredOutput.UserStories)

The cool thing about the JSON output is that the IntelliSense already knows that the structured output will hold the array UserStories. After clicking the button the User Stories are generated.

Just like in the previous section, we want a human in the loop. That's why we store it in a collection first and use text input controls so we can quickly adjust the User Stories.

You can obviously make the app better looking, implement actually storing the User Story to Jira, add additional User Stories in the app first, etc.

Additional Information

Microsoft's Power Platform Advocacy team started a Prompt samples library on GitHub where you can find and add prompts that work for you. A cool thing I found out is that the prompts for Power Automate will redirect you to Power Automate and will suggest a flow based on your prompt. The prompt itself is a URL parameter. You could easily use this functionality for your Power Platform makers as well.

Not discussed earlier, but prompts can be put into a solution. You can also add them to Catalog from Managed Environments. This gives the ability to let good Prompt Engineers create awesome prompts and share them within your organization.

Thomas van der Waard gave me the feedback there is a specific Approval action for these Generated text scenarios to improve the approval process. You can implement it now if you want to. New GPT Text Approval Feature In Power Automate (youtube.com)

Key Takeaways

👉🏻 Prompts can give great suggestions (question / answer scenario)

👉🏻 Prompts can actually generate data based on text (User Stories scenarios)

👉🏻 Prompts can be shared across your organization

टिप्पणियां


bottom of page