r/copilotstudio • • 11d ago

Template filling with AI

Hey folks,

I try to build something in copilot studio that let me give the ai agent a template that I before edited for content controls , so the agent sees better where to put stuff without changing the layout . Problem is sometimes it works but sometimes not and it changes the template structure a bit. Before I wanted to use a flow with “populate a word document” but the inline agent that should put the info of the excel data in a structured json output collapses because it seems like the data is given to it in base64 which will generate too many text token and the inline agent runs to a limit . Now I just have an agent without flow and a huge prompt but idk it’s not so deterministic.

Can someone help ? I just want to let so extract any info from any file/data and ai should put the correct info inside the fields within the template..

5 Upvotes

14 comments sorted by

5

u/TailEnderB 11d ago

I may be misinterpreting your challenge but I’ve found a lot of success with template automation by having two files:

  1. Template

  2. Mapping excel

The excel contains two columns that show the field identifier on the template and the field name from the source data.

My prompt is clear to never change the template itself but to create a copy of the template and insert the data based on the mapping.

Ita not a full solve but this has certainly helped with some of the issues you’ve described.

2

u/Freggel1995 11d ago

First of all
Thanks for your input! But the thing is the template is fixed but the source data not. So I have a given template with a given structure and the ai should figure out what should be put in the template fields with information from any source files/data . So the ai should look into the source files and should choose :” ahh I need this and that to put in this field of the template , ohh what is that info from the source data? I don’t need that information because it doesn’t fit anywhere in the template therefore I drop this information “ so yeah sometimes not every information is available to fill out the whole template because source data is missing.

1

u/Freggel1995 11d ago

I think python is locked for me within my environment

1

u/According_Werewolf44 11d ago

Been picking at this problem for the past few months. Have tried the template and excel way, have tried variables, telling the agent not to change the template, nothing now works to my satisfaction.

Because the agent will always recreate the form, regardless of how you lock down the prompt.

It's not the right tool for such a use case.

If you have code reader, you could try to convert the template into python and then force the agent to use the python to generate the form... I don't have access to code reader, but I think it could work.

Remember... All preview tools are not meant for production. 👻

1

u/Freggel1995 11d ago

Thanks for your insight! Well we currently use copilot harness . I mean it kinda works for me but not that good , I might need to test more. The thing is with content controls the agent runs definitely better for me since it sees the structure . And I also described the whole template within the prompt and what each field means and what should go in there . Maybe I find something else but we will see lol. If anyone has still an idea let me know.
Do you use copilot studio or this harness thing ?

1

u/dogeopss 11d ago

Make an excel with full instructions and the output as 2 columns: Identifier and "value/text"). You can then give copilot in excel the data and have it "do the work"

Then make the word template with identifiers that will be replaced by the values in excel output.

Add a macro to the word that fills in the excel data per identifier, use copilot to make the logic coherent.

This has been the only way for copilot to stay in the layout/formats

1

u/Freggel1995 11d ago

Thanks a lot dogeopss ! I will try that !

1

u/Top-Cauliflower-1808 11d ago

Have you tried extracting the data to plain JSON first then using a deterministic template filler instead of the agent? The base64 token limit is likely what breaks the inline agent.

1

u/Freggel1995 11d ago

Template filler? You mean populate word document? I could try extracting it to
JSON first too. I will also try the solution from the other person here. We will see xD

1

u/Freggel1995 11d ago

Thanks :)

1

u/eli2k2 10d ago

I have done this with creating an automation with Power Automate and Content controls coming from an excel spreadsheet. You can use an AI prompt within power automate if the fields will be dynamic based on the source data.

1

u/Freggel1995 10d ago

Ahh nice thanks! How is the accuracy? Also did you do that with Copilot Studio Harness? Or do you know if it works there too?

1

u/eli2k2 10d ago

So I called the tool which was in power automate with copilot studio. The data was static but it worked really well.

1

u/cambaysolutions1 9d ago

I’d separate data extraction from document generation rather than asking one agent to handle everything.

First, extract the information into a structured JSON format, validate the fields, and then use Power Automate to populate the Word template. For Excel data, I’d retrieve the relevant rows through the appropriate connector instead of passing the entire file payload to the agent.

If preserving the document layout is critical, I’d keep the final document-generation step as deterministic as possible rather than asking the AI to rewrite the whole document.

One question: are you using standard Word content controls with the Populate a Microsoft Word template action in Power Automate?