Skip to content

Power Automate and creating text with GPT using a prompt

This time, we’ll be going over my new favorite Power Automate action: Create text with GPT using a prompt  It’s definitely the easiest way to leverage GPT in Power Platform solutions.

What can you use custom prompts for in Power Automate? Anything! As long as you keep in mind how these language templates work and what limitations they have. Let’s break this down with a few examples.

Example – Creating a CSV

Let’s start with something that works great with basic Power Automate. But if you’re familiar with prompting (but not with Power Automate), this might be more natural. I wouldn’t do this myself 🙂

Retrieve all accounts from Dataverse and create a CSV-formatted text containing only the account name and the date it was added to Dataverse.

Let’s start by retrieving all accounts (list rows).

After this, we add the GPT prompt action (Create text with GPT using a prompt).

Do not choose a ready-made prompt, but create your own (New custom prompt).

A prompt editor opens for us. At the top, we write the prompt, i.e. instructions for the language model about what we want it to do. At the bottom, we see the result of testing the prompt.

The cool thing is that you can pass content to the prompt as parameters from Power Automate.

Let’s create a new parameter (Accounts) that will have the accounts returned by the List rows action. Let’s copy the body/value returned by the action to the prompt as sample data. This way we can test the functionality of the prompt directly in the editor.

The hardest part is writing a prompt that produces the desired result. After a few tries, I ended up with the following. Parameters are added using the Add button in the top right corner.

The end result is exactly what I hoped for.

And you don’t have to fiddle with multiple Power Automate functions.

In the workflow, we pass the retrieved accounts as a parameter to the prompt.

And that’s where the resulting CSV can be found.

Let’s continue with examples that can’t be done directly with other Power Automate features.

Example – Classification

We have observations extracted from system x. One observation per row. In addition, we have observation categories to classify the observations.

We want to generate a JSON-formatted text that contains observations classified according to a given classification. For this purpose, we create a new prompt that receives the observations and the classification to be used as parameters.

After a few tries, the prompt becomes the following.

Here is list of observations. Each line contain single observation from the user: **Obervations**.

Here are categories you should use to category each of observation: **Categories**. Each observation can be categorized in several categories.

End result should be a JSON content having two fields: Observation (content from the original source. Do not change the content) and Category (0-n matching categories). If there are several matching categories separate them with semicolon.

We ask GPT to provide the final result in JSON format, but we can also change the format in the settings. The Edit button allows you to define the JSON schema. Now the final result is guaranteed to be valid JSON.

Let’s try the prompt. The result looks great, but quite a few observations have been left unclassified.

The function uses the GPT-4o mini language model by default. It is cheaper and faster than the alternative GPT-4o. Let’s change the function to use GPT 4o and compare the results.

In this example, GPT 4o performs better. It finds a reasonable classification for all observations. For some observations, it even identifies multiple applicable classes.

Example – Code mapping

Next, we automatically process the measurement results. Each result contains the measurement (test) and the measurement result (result). The problem is the description of the measurement. They come from different systems in slightly different formats. All of the ones below refer to the same measurement (Vitamin B12 cyanocobalamin (µg/100kJ)). Easy for humans to understand, traditional program code cannot.

[
    {
        "test": "Vitamin B12 cyanocobalamin (µg/100kJ)",
        "result": "0.9"
    },
    {
        "test": "Vitamin B12  µg / 100kJ",
        "result": "0.3"
    },
    {
        "test": "Vitamin cyanocobalamin (B12) (µg/100kJ)",
        "result": "0.93"
    },
    {
        "test": "Vitamin cyanocobalamin - µg/100kJ",
        "result": "0.19"
    }
]

Each test result should be assigned the correct code based on the description below. The results shown above are all coded “code_1”.

[
    {
        "description": "Vitamin B12 cyanocobalamin",
        "unit": "µg/100kJ",
        "code": "code_1"
    },
    {
        "description": "Vitamin B12 cyanocobalamin",
        "unit": "µg/100g",
        "code": "code_2"
    },
    {
        "description": "Vitamin B7 Biotin",
        "unit": "µg/100kJ",
        "code": "code_3"
    },
    {
        "description": "Vitamin B7 Biotin",
        "unit": "µg/100g",
        "code": "code_4"
    },
    {
        "description": "Vitamin B9 folic acid",
        "unit": "µg/100kJ",
        "code": "code_5"
    },
    {
        "description": "Vitamin B9 folic acid",
        "unit": "µg/100g",
        "code": "code_6"
    }
]

However, for GPT this is a straightforward task. The prompt became the following.

GPT does the job quite well.

Example – Reading invoice information from an image

The last example deals with paper invoices that have been scanned along the way. Below you can see one high-quality scanned invoice.

We want to read the basic information of the invoice. Payee, payer, account number, reference number, amount, due date, etc. Fortunately, we can also pass images or documents as parameters to the prompt. This requires the use of the GPT 4o template.

Add an image of the invoice as a parameter to the prompt.

After a few rounds of experimentation, the prompt becomes the following.

The end result looks quite good.

The great thing about this is that I don’t have to teach the AI ​​model how to read invoices. GPT is reasonably good at extracting the correct information from an invoice.

An interesting detail, however, is the name of the person paying the bill (Pertilä). GPT interprets it as Perttilä, even from a good photo, because it is apparently a much more likely name than Pertilä.

Costs

How much does it cost to use the Create text with GPT using a prompt function? It is a so-called premium connector, which means that its use requires a premium license. However, this is not enough. The function also requires AI Builder credits to work. These are consumed according to usage (16 credits per 1000 tokens).

You can see the tokens used by the function after execution.

The examples in this article consumed credits as follows:

  • CSV generation: 36095 tokens -> 580 AI Builder credits
  • Observation classification: 3513 tokens -> 36 AI Builder credits
  • Attaching test results to test codes: 2272 tokens -> 56 AI Builder credits
  • Extracting invoice data from a photo: 2070 tokens -> 33 AI Builder credits

The cost is directly proportional to how long texts are processed. In our example, CSV generation is expensive because we gave GPT the entire long JSON returned by Dataverse.

By stripping out everything unnecessary from this JSON and giving GPT only the columns it needs (account name and creation date), the number of tokens used drops significantly from 36095 -> 1177.

AI Builder credits come as a bonus with some Power Platform licenses.

Purchased separately, the AI ​​Builder Capacity Add-on T1 costs 468e/month and gives you 1 million credits/month.

Summary

As we saw from the examples, using your own prompts in Power Automate is easy and very convenient in many situations. As long as you remember to test the functionality of the prompt with sufficiently comprehensive data.

Despite extensive testing, GPT can cause hallucinations and confusion. Flow warns if the accuracy of the GPT result is not verified with a human after the GPT operation.

If you run a lot of workflows, costs can get high. In that case, you should look towards Azure AI services.

Currently, Power Automate offers a choice between two language models (GPT-4o and GPT-4o mini). In Azure, the choice is something completely different.

However, due to its straightforwardness, this ready-made function is a great way to start utilizing your own prompts in Power Platform solutions.

Cloud FlowGPTPower AutomatePrompt

Leave a Reply

Your email address will not be published. Required fields are marked *

Forward Forever logo
Cookie settings

This website uses cookies so that we can provide you with the best possible user experience. Please select the cookies you want to allow.