Automate Document Creation from Natural Language Using Copilot Studio
Create a Copilot Studio agent that fills Word templates with data from conversations, enabling instant generation of invoices, quotes, or reports.
In today’s fast-moving business environment, drafting standardized documents—invoices, quotes, proposals—is a necessary but repetitive task. Copilot Studio offers a smarter path: an agent that listens to natural language, extracts the relevant details, and produces a preformatted Word document in seconds. This guide walks you through building an agent that takes a simple conversation (for example, “Create an invoice for 40 hours of consulting at $200/hour”) and returns a ready-to-download document stored on OneDrive—all within the chat.
The Scenario: Nova Consulting’s Invoice Generator
Nova Consulting provides IT advisory services. Their consultants frequently create invoices for clients. Instead of manually opening Word and filling in a template, they now interact with an agent called InvoiceGen. The agent understands requests like:
“Create an invoice for client BlueOcean Inc., 30 hours at $130/hour for ‘Cloud Migration Support’. Use today’s date and invoice number INV-2025-07.”
The agent extracts the necessary fields, triggers a Power Automate flow, and returns a link to a completed .docx file that can be reviewed and shared.
Prerequisites
- A Copilot Studio license (standalone or included with Power Platform).
- Power Automate license with access to premium connectors (OneDrive for Business, Office 365 Users, and AI Builder if you use the Run a prompt action).
- Microsoft Word (desktop or web) to create the template.
- OneDrive for Business as the destination for generated files.
Step 1: Design the Invoice Template in Word
Open Word and create a document. You can start from a built-in template or build your own. The critical step is adding placeholders for every dynamic value. Use {{FieldName}} for standalone fields and {{TableName.ColumnName}} for fields inside a table.
For our invoice, include:
- Header fields:
InvoiceNumber,InvoiceDate,ClientName,ClientAddress,ProjectName. - Line-items table with columns:
Description,Hours,HourlyRate,LineTotal. Insert at least one row with placeholders such as{{LineItems.Description}}in each cell. - Footer fields:
Subtotal,TaxRate(e.g., 10%),TaxAmount,TotalAmount.
Make sure every placeholder name is unique and contains no spaces.
Save the template locally (you will upload it to the prompt in the next step).
Quickly test your template by filling placeholders with dummy data and checking the layout. This avoids surprises during the AI prompt configuration.
Step 2: Create the Agent in Copilot Studio
-
Open copilotstudio.microsoft.com and create a new agent.
-
Name it InvoiceGen and select the GPT-5 Auto model (or whichever model is available).
-
On the Instructions tab, provide a clear directive:
“You are an invoice generation assistant. When a user asks you to create an invoice, gather all required details (client name, hours, rate, project description, etc.). Then call the Generate Invoice tool to produce the Word document. Return the download link to the user.”
-
Save the agent; you will configure the tool after building the flow.
Step 3: Build the Power Automate Flow
The flow receives the conversation data, generates the document, stores it, and returns a link.
3.1 Create a New Flow
- In Power Automate, choose Instant cloud flow.
- Select the trigger When an agent calls the flow (this appears after you create an agent flow tool in Copilot Studio).
- Add a text input parameter named UserMessage.
3.2 Run a Prompt to Generate the Document
-
Add the Run a prompt action.
-
Create a new custom prompt. Name it, for example, “Invoice Generator Prompt”.
-
In the prompt text box, write:
“Based on the user’s request below, fill in the placeholders in the provided Word template. Return a complete Word document with all fields populated. User request:
[UserMessage]” -
Attach the Word template file you created in Step 1 (you can upload it directly in the prompt configuration).
-
Map the
UserMessagecontent from the trigger to the prompt’s input. -
Test the prompt with a sample message such as:
“Create an invoice for client BlueOcean Inc. at 123 Ocean Drive, Newport, RI 02840. Invoice number INV-2025-07, date 2026-06-03. Project ‘Cloud Migration Support’, 30 hours at $130/hour. Use 10% tax rate.”
-
The prompt should output a Word document (a binary or file content output). Save and close the prompt.
3.3 Prepare a Unique File Name
Add a Compose action to generate a unique file name:
concat('Invoice_', rand(1000, 9999), '.docx')3.4 Save the Document to OneDrive
- Use the OneDrive for Business – Create file action.
- Folder path:
/Documents. - File name: the output from the previous Compose step.
- File content: the file content output from the Run a prompt action.
3.5 Retrieve the Current User’s Principal Name
Add the Office 365 Users – Get my profile (V2) action. The UserPrincipalName will be used to build the full document URL.
3.6 Assemble the Full Document URL
Add another Compose action. Build the URL using the user’s profile, replacing @ and . with underscores to make it URL-safe.
concat(
'https://novaconsulting-my.sharepoint.com/personal/',
replace(
replace(
outputs('Get_my_profile_(V2)')?['body/userPrincipalName'],
'@',
'_'
),
'.',
'_'
),
'/Documents/',
outputs('Compose_File_Name')
)Replace novaconsulting with your own tenant name. You can find it in your OneDrive URL when you browse to it.
3.7 Encode the URL for the Agent
Copilot Studio expects a properly encoded URL. Add a Compose action to encode the full path:
encodeUriComponent(outputs('Compose_Full_Path'))3.8 Respond to the Agent
Add a Respond to the agent action and configure a text output variable. Name it DocumentLink and set its value to the encoded URL output.
Save and name your flow (e.g., “Generate Invoice from Agent”).
Step 4: Connect the Flow to the Agent
-
Go back to your agent in Copilot Studio.
-
Open the Tools pane and add the flow you just created.
-
Configure the Description for the tool:
“Use this action to generate an invoice Word document. Provide the user’s full statement in the
UserMessageinput. The agent must include all necessary details: client name, address, invoice number, project description, hours, rate, and any tax information.” -
The agent will automatically detect the output parameter (
DocumentLink). -
Update the agent’s instructions again to mention this tool explicitly.
Step 5: Test the End-to-End Flow
Publish your agent. Open the test chat in Copilot Studio and try a sample message:
“Create an invoice for BlueOcean Inc., 30 hours at $130/hour for ‘Cloud Migration Support’. Date today, invoice number INV-2025-07.”
The agent should respond with a summary and a link. Click the link to download the Word document. Verify that all placeholders are correctly replaced.
If the document is not generated, check the flow run history. Common issues include:
- The prompt did not produce the expected output structure (ensure the template is correctly attached).
- The file content mapping is missing.
- The user message does not contain all required fields.
Step 6: Grounding with a Data Source (Optional)
To reduce the amount of typing required from the user, you can connect the agent to a product catalog or client list stored in Dataverse, SharePoint, or an Excel file on OneDrive. For example, if the user says only “Invoice for client ID 1001”, the agent can look up the client details and pass them to the flow.
Enable grounding by:
- Using Copilot Studio’s Knowledge sources to add a SharePoint folder or Dataverse table.
- Or having the agent call an intermediate flow that enriches the data before generating the document.
This approach reduces typing and ensures data consistency.
When grounding with real business data, ensure proper security trimming. Copilot Studio respects permissions from Dataverse, SharePoint, and Graph.
Troubleshooting Common Mistakes
| Issue | Solution |
|---|---|
| The Word document does not open or is corrupted. | Verify that the Run a prompt action outputs a file content type; test the prompt in isolation first. |
| Placeholders remain unfilled. | Ensure placeholder names in the template exactly match those expected by the prompt. Provide a few sample messages to teach the prompt the mapping. |
| The agent returns an error. | Check that the flow is published and the tool configuration is correct. The UserMessage variable must be mapped. |
| Size limits on chat responses. | Return a link instead of the file because documents over a few MB can exceed response size limits. |
| Encoding issues in the URL. | Use encodeUriComponent to escape special characters. Test the final URL in a browser. |
Conclusion and Next Steps
You now have a fully functional Copilot Studio agent that generates Word documents on demand. This pattern can be applied to any document type: quotes, contracts, reports, or certificates. By combining natural language with a structured Word template, you eliminate repetitive formatting work and reduce errors.
To take it further:
- Add a review step where the user confirms the details before generating the document.
- Store the generated file in a SharePoint document library for centralized access.
- Integrate signature workflows using Adobe Sign or DocuSign directly from the chat.
With Copilot Studio and Power Automate, the only limit is the templates you design.
References
- Original inspiration: Copilot Studio: Generate Word Document From A Template – Matthew Devaney
- Microsoft Learn: Create and use custom prompts in Power Automate (placeholder)
- Microsoft Learn: Agent flows in Copilot Studio (placeholder)
From multi‑branch condition blocks to a built‑in human review step, learn how to build resilient approval processes that combine AI logic with real‑world oversight.
Discover how the hidden EditTable YAML node lets you dynamically add, remove, or clear table variables directly inside your copilot conversations.
Connect any model from Azure AI Foundry—open source or custom—to Copilot Studio prompt actions.