code-interpreter-ai-builder-prompt-power-automate
AI Builder Power Automate
Manish Solanki  

Automating Complex Workflows with AI Builder Prompts and Code Interpreter in Power Automate

The recent introduction of the Code Interpreter into Microsoft Copilot Studio and AI Builder prompts allows makers to generate and execute Python code directly within prompts. This enables advanced data processing, file manipulation, and visualizations without leaving the Power Platform ecosystem.


In this blog, we’ll explore how to harness the Code Interpreter in AI Builder prompts to automate a real-world audit scenario using Power Automate.

What Is the Code Interpreter?

The Code Interpreter allows prompts to:

  • Execute Python code for data analysis, Excel/Word/PDF processing, and chart generation
  • Handle complex logic and file transformations inside AI Builder prompts
  • Return structured outputs like updated Excel files, PDFs, or JSON summaries

Prerequisites

  • Your tenant admin has enabled the Code Interpreter in Power Platform Admin Center (PPAC). In this tutorial, I will cover the detailed steps to enable Code Interpreter in power platform environment
  • You’re working in an environment where Copilot Studio and AI Builder are available
  • You have access to Power Apps Maker Portal and AI Hub

Scenario

Automating Procurement Audits

An enterprise receives:

  • An Excel file with procurement transactions
  • High-risk vendors flagged in a compliance audit are stored in the PDF file

The goal is to automate the audit process to flag transactions over $10,000 with missing PO numbers or involving high-risk vendors.

Solution

Step 1: Enable Code Interpreter in the environment

Go to Power Platform admin center and navigate to “Copilot -> Settings -> Code generation and execution in Copilot Studio”

Select the power platform environment and press “Add” button:

Tick the checkbox to enable code interpreter and click “Save” to save the changes:

Step 2: Building the Prompt with Code Interpreter

Go to power automate portal. Navigate to “AI Hub -> Prompts -> Build you own prompt”. Give prompt a valid name like “Procurement Audit Prompt”. Click 3 dots ‘…’ and select “Settings” from the sub menu:

Scroll down and enable code interpreter setting:

Close the settings window.

Add the below prompt in the instructions box:

You are given:
- An Excel file [Invoice Transactions] with procurement transactions
- A PDF file [High Risk Vendors] listing high-risk vendors

Your tasks:
- Process invoice transactions in excel file
- Identify transactions over $10,000 with missing PO numbers
- Extract vendor names from the PDF
- Cross-reference and flag risky transactions
- Highlight flagged rows in red and add comments
- Generate a summary report with total flagged transactions, vendor names, and reasons

Return:
- Updated Excel file
- PDF summary report
- Text summary of updates

Note: [] is the place holder for document input parameters as shown below:

Change the output format to “Documents/Images”:

Optional: You may change the Model as per the requirements, here I am using default model:

Upload invoice transactions excel file and high-risk vendors list in pdf and test the prompt.

Enabling code interpreter settings allows us to upload word (.docx), .ppt, excel (.xlsx) format in addition to image and pdf.

Run “Test” to verify the output of prompt.

In the response, the AI model will return the output files:

You can verify the result and change the instructions until you get the correct result.

You can view the python code script by switching to Code:

You may also view the run details of the python script:

Save the prompt once you started getting correct output from the prompt output. Else try changing the instructions or AI model until you get the correct results.

If you get “Need attention” error, just reopen the prompt:

Change the output format to “Text” and save the prompt:

Step 3: Call Prompt from power automate flow

The last step is to call the custom prompt from power automate cloud flow.

For simplicity, I used a manually trigger flow but you may choose the trigger as per the requirements. Add 2 file input parameter to automate the auditing process using AI prompt:

Next, add “Run a prompt” action. Choose “Procurement Auditing Prompt” in the drop down:

After that, pass dynamically the base64content value for both input files:

Add select action to parse array of files returned by “Run a prompt” action. Enter the below expression in the “From” input parameter of select action:

outputs('Run_a_prompt')?['body/responsev2/predictionOutput']?['files']

In the map parameter, enter the below JSON:

{
  "name": @{item()?['file_name']},
  "contentbytes": @{base64ToBinary(item()?['base64_content'])}
}

Finally, add “Send an email” action to send across the files generated by AI prompt as email attachments. Add email recipients, subject and email body as per the requirements. In the attachment input parameter, pass dynamically the output of Select action that contains the list of output file files from the AI prompt:

Save the flow. Ready to test the flow execution.

Output

The input invoice transactions excel file will look like:

The input pdf file that contains the list of high-risk vendors will look this:

I passed both these filles as in the input of manually trigger flow. The output of “Run a prompt” actions contains the array of output files with file name, base64 value, content-type etc:

Let’s check the email and the attachments:

The email had 3 attachments.

Summary text file:

Summary pdf file:

Updated Invoice excel sheet:

The results are really awesome!

Best Practices

  • Use precise, structured instructions in prompts
  • Specify expected output formats (e.g., “Return as PDF”)
  • Refine your prompt wording based on the tests
  • Modularize prompts for reuse across flows

Conclusion

  • The Code Interpreter unlocks a new dimension of intelligence in Power Platform workflow automation.
  • By combining AI Builder prompts with Power Automate, you can build agents that not only understand your data but act on it with precision.
  • Whether you’re auditing transactions, generating reports, or transforming files, this feature empowers you to automate with confidence and clarity

Leave A Comment