Use AI and Power Automate to parse form questions

It’s time for the festive tech calendar again! As AI is the hype everywhere I wanted to contribute with this too but in a different way.
As a consultant I’m often in a situation where I want to get feedback or information from customers, but parsing all the information gathered can take a lot of time. I always find myself in the dilemma where I want to only use multiple choice questions so I can easily parse the information or use open questions so I can get as much data as possible. With the help of AI I believe we could get the best of both worlds!

For this blogpost I’ve created a small survey you can enter.

In this survey you can enter as much information as you want. Some might say their base of operations is just “The Netherlands”, while others will write a whole story about how sometimes they work from home but because they are traveling a lot they don’t feel that to be their base of operations per se.

I’ve created a system using the Power Platform AI Builder to parse this information. To be in the spirits of Santa Clause I’ve asked the AI to determine if the submitted was naughty or nice. All this data will be stored in a SharePoint list and then transformed into a graph which is shown here. After you submitted your reply you can wait a few moments and refresh the page (you might need to do a hard refresh). And if everything went well you might see your response in the graph.

I’ve created a overview graph per country:

And a graph per job area:

Now of course you want to know how to make this. So let’s go to Power Automate and check it out!

Above you see the first part of the flow which is created. If you never used Power Automate before this might look a bit overwhelming. Power Automate can be used to create low-code/no-code solutions. A flow always starts with a trigger at the top. In this case the flow triggers when the form received a new entry. In the next step the data from the entry is being retrieved.

In the next step I create three parallel branches in the automation. This is because these steps can run in parallel without affecting each other.

Now it’s time to use the AI magic! The AI Builder has the option to do a GPT Prompt, this allows you to create a prompt for an LLM which will then return a reply. Do keep in mind that if you want to use this yourself you have to start the free trail (for 30 days which can be extended). The AI Builder requires special licenses on top of the Power Platform licenses. Below you see an example of the prompt I made.

I’ve created a basic simple prompt for this set up to just test how it would work. But if you want to use this for a production workload you want to look into prompt engineering to create better prompts.

The goal of my prompt is to analyze the data and return a single value. But AI does sometimes has a mind of it’s own as it’s inherently random. So there is a chance I wont get a single response back but instead a get a whole story about how it came to the conclusion. The best way would be to ask the ai to structure it’s response in a way that it has room for the extra information while you will still be able to get the data out of it. But I didn’t want to do that. So instead I build in a safeguard.

I’ve created a condition which checks if the response is only a single word long. If that’s not the case then the response is brought to the next AI which will take the answer and tries to reduce it.

This process is done in every branch. One branch is to get the country, one is to get the job area and one is to determine if the person was nice or not. But how would the AI know if the person was nice or not I hear you ask. Well we have to give it some more directions like here:

In this prompt I use multiple inputs (the two final questions). If you do this in a production environment you do want to keep in mind that the input text for a GPT prompt can only have a certain length so you do need to make sure that you don’t go over this. You could first ask to summarize the different inputs before adding them to the prompt to reduce the amount of tokens needed.

In the next part of this flow I just store the different values I generated in a SharePoint List. So the result will look like this:

This list will grow when more of you submit entries to the survey. In the Power Automate flow I run some loops to count the amount of naughty and nice occurrences for both the countries and the job areas. Until eventually I arrive at the last part of this flow.

I use the free version of the quickchart API. This API allows you to provide information and receive an image in return. I’ve used the chart maker on the website to create the chart I wanted to then convert it to the advanced editor and get a JSON representation of the chart. When building it in the editor I just used some dummy data which looks like my data.

Then I take the JSON created by quickchart and put it in Power Automate. I replace the data with the variables I’ve created in my flow so that it will generate the chart with the correct data. I use the POST endpoints to send the data and receive the image back as a reponse.

This image is then send to an Azure Blob Storage with anonymous read access. Using the Update Blob connector in Power Automate.

So the image will be overwritten with the new version (which is then shown in this blogpost). As you see getting the image information is very simple as it’s just the body from the http request that is done.

I hope this will spark some ideas with you too. I would love to see more production worthy attempts at this as I personally think this could be a very helpful tool when creating assessments. I’ve glossed over most of the SharePoint stuff in this blogpost. If you are interested in reading more about how that is done and how the counting is done in the flow please leave a comment and I will create a follow up post about that.
Don’t forget to check out all the other awesome community contributions in the Festive Tech Calendar and if you can spare it please consider donating something to the charity they’ve chosen this year!