If there is one thing we can all agree on is how much we hate doing documentation. No matter how useful it is, it a pain to complete (Its one of the reasons I made my auto document chrome extensions AutoReview.
Recently I have been exploring the Create text with GPT
Power Automate connector, and it gave me an idea, could we use a GPT model to automatically create documentation for our flows.
If you want to know more about the connector check out my blog here, in a nutshell my plan is to get the flow definition, pass it to the GPT connector to get a summary of what it does. Additionally, I want to see a simple graphical representation of what it does.
For this explanation I'm going to use a standard template, the Create a task in Planner from Microsoft Forms and post message in Teams.
Im going to split the process into 4 sections
- Get the definition and prepare the data
- GPT Prompts
- Creating Report
- Additional Features
1. Get the definition and prepare the data
First we need to get the flow definition, we use the Get Flow
action from the Flow Managment connector, one of its outputs is the definition. The definition is the key blueprint to all flows, and has all the key information about the flow, and the primary data we need.
But the connector also provides some additional useful information,
- Actions Array - all the actions (5 in the demo)
- Connection References - all the connections (Forms, Teams & Planner in our example)
Because flows can get long and because we have a token (character limit) on our GPT action I only want the API actions (so no conditions, variables or scope, just the actions like Get items or Send Email).
We do this with a simple filter and select only the type's that are 'OpenApiConnection'.
We then simply use the Create HTML Table
actions to create a table of the filtered actions and a table of the connection references.
2. GPT Prompts
We need to use few GPT prompts (so be aware when this comes out of preview the report will cost a few AI Builder credits). The first prompt is probably the most powerful, we use it to summarise what the flow does.
In our demo we get:
The power automate definition is a workflow definition that triggers an action when a new response is submitted. It then gets the response details, creates a task, and posts a message in a chat or channel. If the task creation fails, the workflow is terminated.
Pretty cool 😎
We could stop there, but I want to add something extra cool, a sequence diagram. To do that we have to use 2 GPT prompts (due to the token limit). First we have to extract all the actions that are 'OpenApiConnection'
You may notice this sounds like what we did to the actions array, but that didn't include action name and it is in the wrong order
[
{
"name": "Get_response_details",
"type": "OpenApiConnection"
},
{
"name": "Create_a_task",
"type": "OpenApiConnection"
},
{
"name": "Post_message_in_a_chat_or_channel",
"type": "OpenApiConnection"
}
]
Next we ask GPT to create our mermaid sequence diagram
You could do different mermaid diagrams, or even different models. Mermaid is a powerful free JavaScript library that creates process diagrams
sequenceDiagram
Get_response_details->>Create_a_task: Request
Create_a_task->>Post_message_in_a_chat_or_channel: Request
Post_message_in_a_chat_or_channel-->>Get_response_details: Response
Create_a_task-->>Get_response_details: Response
Post_message_in_a_chat_or_channel-->>Create_a_task: Response
3. Creating Report
To create the report Im going to follow a standard process:
- Create html template
- Get File Content
- Replace place holders with new data
- Save new file
You can create any template you want, I went with Bootstrap, just remember if you are using mermaid to add the JavaScript import
I use placeholders like {name} and {table}, which I then use a replace expression to replace with the GPT or HTML table outputs.
replace(
replace(
replace(
replace(
replace(
replace(
replace(body('Get_file_content_template'),
'{name}'
,
outputs('Get_Flow')?['body/properties/displayName']
)
,
'{author}'
,
outputs('Get_Flow')?['body/properties/creator/userId']
)
,
'{description}'
,
outputs('Create_text_with_GPT_description')?['body/responsev2/predictionOutput/text']
)
,
'{table}'
,
body('Create_HTML_table_actions')
)
,
'{diagram}'
,
concat('sequenceDiagram',split(outputs('Create_text_with_GPT_diagram')?['body/responsev2/predictionOutput/text'],'sequenceDiagram')[1])
)
,
'{date}'
,
formatDateTime(utcNow(),'dd/MM/yyyy')
)
,
'{tableCon}'
,
body('Create_HTML_table_connections')
)
And the output file will look like this:
Teamplates can be download here
4. Additional Features
As you can see you are only limited by your imagination, but there are a couple of things I considered adding:
Classify
The GPT has a cool classification prompt, so you could create different categories and ask it to categorise the flow.
Inventory Default Environment
The flow is a manual flow, but it could be called by another flow listing all the flows in the default environment, the description and other data could also be stored in a list for easier reviewing.
Compress Definition
As we have a token limit some long flows may hit that limit, so I wrote an office script to strip out unneeded information from the definition first.
Further Reading
Top comments (7)
This opens a lot of new scenarios. What about the automatic creation of Power Automate on demand? I don't know if this is possible with the existing actions, but assuming that it is, why not asking GPT for a Power Automate xml definition to create a specific flow? And then, after some days, why not to remove it because it is not needed anymore?
That's a cool idea, you could in theory do edits too. Crazy amount of possibilities
Classify would be an interesting element. You have given me a good idea to basically create a template and add a risk profile as an initial assessment for the flow review...
GPT chat is great
I gave this a try and it worked. Thank you for posting 📫
Can anyone help with the Office Script part?I have very long flows that produce Definitions that are over the GPT Prompt limit and really need to get this to work to get the prompts down.
You can use the office script to remove unnecessary characters (like spaces and new lines). You can also split out the flow metadata (so only grab the root actions node). But afraid after that there isn't much, you could try breaking into 2 and including that it's first/second part in the prompt.
I'm not a fan of monolith flows and encourage breaking into child flows (sorry I know thats not much help)