Using Custom AI Prompts in Power Apps and Power Automate

March 8th 2024
Back to all blogs

Many new, exciting AI features, including GPT technology, have recently been added to the Power Platform. Prompts are a new feature within AI Builder that allows you to manipulate text using GPT. Prebuilt prompts are readily available, or you can create your own prompts! This blog will show you how to make and use Custom AI Prompts in Power Apps and Power Automate. We will go through two different prompts, one to be used within a Power App and one to be used within a flow:

  • A grammar fixer prompt that will be used within a Power App
  • A client email response prompt that will be used within a Power Automate

Additional Resources

 

Watch Sophie’s Companion Video

Creating a Custom Prompt

The AI Builder page within Power Apps has been renamed the AI hub. Here, you can find everything related to AI in the Power Platform.

 

Prebuilt

Here, there are ready-made AI models, AI learning resources, and Prompts. Like the prebuilt AI models, there are already prebuilt AI prompts for different scenarios, such as responding to a complaint or summarising text. However, you can also create custom AI prompts and share these with others!

 

Custom Prompts

When creating a custom prompt, you must provide the prompt text yourself. The more descriptive your prompt is, the better the result will be. You can add dynamic values to your prompt. These are the inputs that will change each time the prompt is used. For example, if you want your prompts to look over an email, you would have an ‘Email’ dynamic value and write what you would like the prompt to do with that dynamic content using free text.

Once you have written your prompt, you can test it to ensure you are happy with the response. Provide the test dynamic values and then click ‘Test’ prompt.

Custom AI Prompts in Power Apps

The grammar testing prompt will be used inside a simple Power App, which has been created to demonstrate how to use prompts.

The app allows you to input text, which will be the dynamic input for the prompt. When you click ‘Check Text’, the AI prompt will run and produce a result, which is displayed in the bottom box. Both boxes are text inputs; however, the bottom one is disabled, so you can’t type into it; it will only display the text.

 

Select a data source

To use the AI Prompt in the app, you must first add it as a data source. When you click to add data, underneath ‘Tables,’ there is a section called ‘AI models’. This is where you can add all your AI models and prompts to the app.

Now, you can use the prompt within the app. You call the prompt similar to how you call a Power Automate flow:

NameOfPrompt.Predict(dynamicInput1,dynamicInput2...)

To use the result of the prompt, I am saving it in a variable called result. This is saved as a record. To get the text value, it will be:

result.Text

Result

This is the result when putting the text result as the Default value of the bottom box:

As we can see from the photo, the AI prompt has worked! However, all the result text will return with ‘Message: ‘ in front of it. To remove this, we need to trim the string.

Set(result, First( Split( Last( Split( 'Grammar fixer'.Predict(TextInput1.Text).Text, "Message: " ) ).Value, "Message: " ) ).Value)

 

This formula takes the result of the Prompt and trims it after ‘Message: ‘, keeping the actual text result as expected. The result when using the above formula:

Using a Prompt in Power Automate

To use prompts in Power Automate, you add them the same way you would an action, with the connector being AI Builder. The action you need to select is ‘Create text with GPT using a prompt.’ You can then select the prompt you want to use.

 

Approval

When you use a prompt in Power Automate, if you don’t add an approval step afterwards, your flow will save with an error.

It is best practice to check the output before using it further. AI may not always get a response correct, and it needs to be double-checked by a human before potentially being used in the business or emailed out. To combat this, Power Automate has added a new type of approval called ‘Start and wait for an approval of text’ to be used after a prompt action.

You can save and use your flow without this approval step, as it only saves as a warning but this is not recomended!

 

Condition

You can then add a condition to the flow based on the approval outcome. If you are using the new designer, the outcome dynamic content of the approval action is initially hidden. You need to click ‘See More’ to be able to select it:

In the client email response example, the flow runs when an email is added to the ‘Client Emails’ folder within Outlook to label what emails are from clients. The prompt is then run, and the email response is emailed back to the user to approve. Upon approval, an automated email is then sent back to the client. If the email response is rejected, a task is added to the user’s to-do list to respond to the client’s email.

 

newLine variable

We need to initialise the newLine variable because we need to use this to replace ‘\n’ in the accepted response. We must use the variable in the replace expression rather than ‘\n’ because replace doesn’t always work when looking for special characters. If we don’t do this and just put the accepted text dynamic input, the email will have no line breaks:

 

Using HTML

As we use HTML within the email body, if you are utilising the new designer, you must switch back to the classic designer to use the HTML email body editor.

replace(outputs('Start_and_wait_for_an_approval_of_text')?['body/acceptedText'],variables('newLine'),'<br>')

 

Email from the client:

The Email approval:

Email response:

 

Using Custom AI Prompts in Power Apps and Power Automate

We hope this blog will help you create custom AI prompts in Power Apps and Power Automate! If you have any questions, email support@encodian.com; they can help you with your query.

Looking to supercharge Power Automate? Why not take a look at Flowr?

150+ Actions in one Power Automate connector

The Ultimate Power Automate Connector!

  • Standard Connector with 150+ Actions
  • Easy to use, very powerful
  • For scalable and agile project delivery
  • Best-in-class support
Author
Sophie Charlwood

Technical Evangelist

Back to all blogs

You might also be interested in...