[Copilot Studio] I tried automatically generating a Word report by inserting numbers into a template: Document output

[Copilot Studio] I tried automatically generating a Word report by inserting numbers into a template: Document output

I verified a method for automatically inserting KPI data into Word templates and generating reports using the Document Output feature in Copilot Studio. I will introduce a mechanism that allows agents to handle the creation of fixed-format regular reports and customer materials.
2026.06.23

This page has been translated by machine translation. View original

Introduction

Hello, I'm Keema.

When creating regular internal reports or customer presentation materials, there's often the task of "same format every time, just swap out the numbers inside."
The theme of this article is whether we can delegate this "insert values into a fixed template" work to a Copilot Studio agent.

In this article, I cover Copilot Studio's Document output (preview) and summarize the verification results as of June 2026.
The focus is on the basics of document creation — generating reports by inserting values into Word template placeholders.
I hope this serves as a reference for those considering agents that automate document creation.

This article is the 9th installment in a series on building agents with Copilot Studio.
The series as a whole aims to build an agent that handles "collection → aggregation → charts → insights → documentation" end-to-end, and this article covers the "documentation (Word)" part.

Target audience: Those who want to automatically generate documents (Word) by inserting values into templates using Copilot Studio

Series Article List

# Theme Article
Part 1 First Agent Creating Your First Agent
Part 2 Knowledge Trying Knowledge-Grounded Answers Based on Files
Part 3 Topics, Tools, Flows Building "Behaviors" with Topics, Tools, and Agent Flows
Part 4 Templates, Autonomous Triggers, Multi-agent Expanding the Configuration with Templates, Autonomous Triggers, and Multi-agent
Part 5 Collection (How to Pass Data) Comparing Methods for Giving KPI Data to an Agent for Aggregation
Part 6 Aggregation Performing KPI Aggregation Deterministically Without Relying on LLM
Part 7 Charts Displaying KPIs as Charts Within Chat
Part 8 Insights Generating Insights from Aggregated Numbers
Part 9 Documentation (Word) (This article)

1. What This Article Verifies

The goal is to reach a state where, when you ask the agent to "create a report summarizing the KPIs of 3 companies," a Word document in a fixed format is produced.
In this article, we first verify that values are inserted into the template using a minimal configuration with fixed KPI data. Dynamic insertion where values change based on user input or variables is an advanced extension that combines with the input passing covered in the collection and aggregation articles.

Specifically, we verify the following flow on actual hardware:

  • Prepare placeholders in {{field}} format in a Word template
  • Use a Copilot Studio prompt tool to insert values for each placeholder from the KPI data written in the instructions
  • Call it with natural language from the agent's test chat and confirm that Word can be generated

The verification uses KPI data (fictional) from three fictional SaaS companies (CloudNova / StreamForge / Datapeak).

2. Overview of Output Methods (Word uses Document output, PPT/Excel uses Code interpreter)

There are several ways to generate documents in Copilot Studio.
Here we organize Document output, used in this article, and Code interpreter, another option.

Document output is a preview feature that converts prompt output into a Word document.

The output of the Document (preview) feature lets you generate a Microsoft Word document for your prompt response instead of text. The generated document follows a layout that needs to be provided in the document output settings.

Source: Document output (preview) | Microsoft Learn

This is a method where AI generates and inserts values into template placeholders. Only Word can be output.

Generating only a Word document is supported.

Source: Document output (preview) | Microsoft Learn

To generate PowerPoint or Excel, use Code interpreter.
It can execute Python to process Word / Excel / PowerPoint / PDF.

Execute Python code for data analysis, processing Word, Excel, PowerPoint, and PDF files, and visualizations

Source: Use code interpreter in a prompt to generate and execute Python code | Microsoft Learn

However, Code interpreter is a premium feature that consumes Copilot Credits.

Code generation and execution count as text and generative AI tools (premium) features.

Source: Use code interpreter in a prompt to generate and execute Python code | Microsoft Learn

Method Supported Formats Insertion Method Billing
Document output Word only AI generates values into template {{fields}} Consumes Copilot Credits as prompt execution (separate meter from Code interpreter)
Code interpreter Word / Excel / PowerPoint / PDF Python execution Premium (Copilot Credits)

In the later test screen (Step 5), Copilot Credits (0.3) are displayed for prompt execution.
This is consumption as regular prompt execution, separate from Code interpreter.

In this article, we first verify the template insertion mechanism with Word (Document output).

3. Preparing a Word Template

We create a Word template as the insertion destination.
In Document output, you write the parts you want to replace in {{field name}} format.

The rules are as follows:

  • Fields to replace should be enclosed in double curly brackets {{ }} (e.g., {{FirstName}})
  • Fields to replace in a table should identify the table name and column name, separated by a period (e.g., {{items.quantity}})
  • Field names should not contain spaces
  • Fields to replace should be identified using double curly brackets. Example: {{FirstName}}
  • Fields to replace in a table should identify the table name and the column name, separated with a period. Example: {{items.quantity}}
  • Fields to replace shouldn't contain space in the name.

Source: Document output (preview) | Microsoft Learn

Since we have 3 fixed companies this time, we use a configuration with individual fields in each table cell (such as {{CN_ARR}}).
The template is generated using python-docx.

Template generation script (click to expand)
#!/usr/bin/env python3
"""Generate a Word template for KPI comparison report (for Document output)."""
from docx import Document

OUT = "kpi-report-template.docx"

# Comparison table rows: (fixed company name, ARR field, NRR field, operating profit margin field)
TABLE_ROWS = [
    ("CloudNova", "{{CN_ARR}}", "{{CN_NRR}}", "{{CN_OPM}}"),
    ("StreamForge", "{{SF_ARR}}", "{{SF_NRR}}", "{{SF_OPM}}"),
    ("Datapeak", "{{DP_ARR}}", "{{DP_NRR}}", "{{DP_OPM}}"),
]
HEADERS = ["Company", "ARR (million yen)", "NRR (%)", "Operating Profit Margin (%)"]


def main() -> None:
    doc = Document()
    doc.add_heading("SaaS Company KPI Comparison Report", level=0)
    doc.add_paragraph("Target Period: {{ReportPeriod}}")

    doc.add_heading("Key KPI Comparison", level=1)
    table = doc.add_table(rows=len(TABLE_ROWS) + 1, cols=len(HEADERS))
    table.style = "Light Grid Accent 1"
    for i, h in enumerate(HEADERS):
        table.rows[0].cells[i].text = h
    for r, row in enumerate(TABLE_ROWS, start=1):
        for c, val in enumerate(row):
            table.rows[r].cells[c].text = val

    doc.add_heading("Insights from the Comparison", level=1)
    doc.add_paragraph("{{Insights}}")
    doc.save(OUT)


if __name__ == "__main__":
    main()

Save the above as make_docx_template.py.
Then run the following command:

pip install python-docx
python make_docx_template.py

A template with placeholders is created, containing a cover page, a comparison table for 3 companies, and an insights section.

Word template with placeholders
Word template with replacement locations written as {{field}}

4. Creating a Prompt Tool with Document output

From the agent's "Tools", create a new prompt tool.

Select "Add a tool" → "Prompt".

Once the prompt editor opens, change the output on the right side from "Text" to "Document".
This "Document" is the Document output.

Change output to Document
Change the output format to "Document"

Open "Document settings" and upload the template created in Step 3.
Once uploaded, the placeholders in the template are automatically recognized.

Template uploaded with fields recognized
11 fields recognized as "Identified fields"

Next, write "what to put in each field" in the instructions on the left.
If the field names have meaningful names, AI can fill them correctly with minimal instructions, but for abbreviations like CN, SF, and DP, it's safer to explicitly state the correspondence.

Please fill in each field of the document based on the KPI data of the following 3 SaaS companies.

KPI data (target period: FY2025 Q2, July–September 2025):
- CloudNova: ARR 1,800 million yen, NRR 118%, Operating profit margin 12.5%
- StreamForge: ARR 1,150 million yen, NRR 104%, Operating profit margin -3.0%
- Datapeak: ARR 2,600 million yen, NRR 126%, Operating profit margin 18.4%

Field mapping:
- ReportPeriod: FY2025 Q2 (July–September 2025)
- CN_ARR / CN_NRR / CN_OPM: CloudNova's ARR / NRR / operating profit margin values only
- SF_ARR / SF_NRR / SF_OPM: StreamForge's ARR / NRR / operating profit margin values only
- DP_ARR / DP_NRR / DP_OPM: Datapeak's ARR / NRR / operating profit margin values only
- Insights: 3–4 sentences of insights from comparing the 3 companies (each company's strengths/weaknesses and the top company)

Enter numbers exactly as in the above data; do not fabricate.

5. Verifying Field Insertion with a Test

Once the instructions are entered, the "Test" button becomes active.
Running the test displays the values inserted into each field and a download link for the generated Word document.

Test results with values inserted into each field
All 11 fields have the correct values inserted, and a download link for "output.docx" appeared

In my environment, all ARR, NRR, and operating profit margin values were inserted exactly as in the input data, and Insights was also generated from the input.
The downloaded Word document is a native, editable Word table with the values inserted into the template table.

The actual Word document after insertion
Word document with values inserted into the template. The table is a native Word table and is editable

Once confirmed, save the prompt tool.
You will be asked for a name and description when saving.
The description is used by the agent's orchestrator to decide which tool to select, so make it clear "when this tool should be used."

6. Calling from the Agent with Natural Language

The prompt tool you created is registered as an agent tool.
Let's try making a request from the test chat using natural language.

When I sent "Please summarize the KPIs of 3 companies and output them as a Word report," the agent automatically selected this tool, executed it, and a message appeared saying Word had been generated.
However, no Word download link appeared.

The official documentation also notes that since the generated document's byte array cannot be directly handled as a node output in a topic, the recommended approach is to return a shared link via a flow.

Unlike cloud flows and agent flows, the Document Output Content Bytes output isn't directly available as a node output in a topic. To allow a user to download the generated document in a topic, use a cloud flow as an intermediary to save the document and return a download link.

Source: Document output (preview) | Microsoft Learn

To allow users to receive the actual file, you go through a flow.

The steps in the official documentation are as follows:

  1. Add a "Run a prompt" action and select the prompt created with Document output
  2. Add a "Create file" action from OneDrive or SharePoint
  3. In the "File content" of that action, specify the prompt output "Document Output Content Bytes"
  4. Add a "Create sharing link" action for the created file to generate a shareable download URL
  5. Add a "Return value(s) to Power Virtual Agents" action and return the shared link URL as an output variable
  1. Add a Run a prompt action and select the prompt created in Create a prompt with document output.
  2. Add the action Create file from OneDrive or SharePoint.
  3. From the prompt action in the File content field, select Document Output Content Bytes.
  4. Add a Create sharing link action for the file to generate a shareable download URL.
  5. Add a Return value(s) to Power Virtual Agents action and return the sharing link URL as an output variable.

Source: Document output (preview) | Microsoft Learn

By calling this flow as a tool, you can return a shared link in the chat.
Since this article does not verify distribution via a flow, that will be covered in a separate article.

Tool auto-triggered in test chat and Word generated
The tool was automatically selected and executed from a natural language request, generating a KPI comparison report

7. Summary

For standard Word reports, you can build a minimal configuration that "generates a document by inserting values into a template" using only the standard Document output feature, without any third-party connectors.
In this verification, we were able to confirm the flow from natural language request to tool selection, value insertion, and Word generation using fixed data.

On the other hand, file distribution to users (shared links) and expansion to PowerPoint / Excel are outside the scope of this article.
Distribution requires a flow, and PowerPoint / Excel requires Code interpreter — separate means are needed. These will be covered in later articles.

References

Share this article