web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Copilot Studio - Copilot Studio pre-built Agent...
Answered

Error when replacing placeholders in Word document using Custom Prompt in Power Automate

(0) ShareShare
ReportReport
Posted on by 4

Problem Description:

I’m using the Custom Prompt feature in Power Automate to generate content via AI and insert the results into a Word template (.docx) that contains placeholders in the format {{FieldName}}.

Flow steps:

  1. AI action (Custom Prompt) applies a prompt with an attached document and generates content.
  2. The next action attempts to build a Word document by replacing the {{...}} placeholders with the AI-generated content.
  3. The Word template is stored locally and contains placeholders such as {{Verificacao}}, {{Seletividade}}, etc.
 
As soon as I place the template .docx file, and perform the tests, it works!! as shown in the image below, however when I try to save the prompt to use in my flow, the error below occurs.
 
 
 

Error Message:

{error: {code: "0x80048d0f",…}}
code: "0x80048d0f"
message: {"operationStatus":"Error","error":{"type":"Error","code":"DependencyFailure","message":"An error occurred while replacing output document placeholders.","properties":{"BackendErrorCode":"InternalServerError","DependencyHttpStatusCode":"500"}}}

Reproduction Scenario:

  • Word template with placeholders:
    {{InfoMaterial}}, {{Verificacao}}, {{Seletividade}}, {{Linearidade}}, {{Precisao}}, {{Exatidao}}, {{LimiteDeteccao}}, {{LimiteQuantificacao}}, {{Robustez}}, {{NaoConformidades}}, {{Classificacao}}, {{Corretivas}}.
  • When I run the action, it fails with status 500 and the error above.

What I’ve Checked/Tested:

  • Confirmed that placeholders exist in the document and names are case-sensitive.
  • Tested with simple placeholders (no accents, no spaces).
  • Document is clean (no Track Changes, no comments).
  • Placeholders are in a single run (not split by formatting).

Questions:

  • Is this behavior expected?
  • Does the action fail completely if any placeholder is missing from the JSON?
  • Is there an official way to define default values (fallback) for missing placeholders?
  • Is there documentation on limitations for the {{...}} replacement mechanism (e.g., supported characters, optional placeholders, null handling)?

Impact:

This error prevents document generation when the model does not return all fields (e.g., optional fields). I need to know:

  • Do I always need to send all keys (even empty)?
  • Or is there a configuration to ignore unfilled placeholders?

Attachments:

  • Word template (.docx) with placeholders.
  • Example Prompt.

 

  • Recommended tags (e.g., Power Automate, AI Builder, Word Template, Custom Prompt)
I have the same question (1)
  • ME-08091808-0 Profile Picture
    4 on at
    Error when replacing placeholders in Word document using Custom Prompt in Power Automate
    Hello @Jerry-IN
    Thank you for your response.
    I’m not using the "Populate a Microsoft Word template" action or JSON output.
    In my case, I’m using the "Run a Prompt" action, which requires a prompt and a .docx template file.

    If I run a test without saving the flow, it works perfectly!
    However, once I save the flow and try to run it again, it fails and shows a message asking to "try again later."

    Eventually, it throws an error stating that it was unable to replace the output document placeholders.
    I’m currently using a different action in Power Automate.
    I’m leveraging the AI Capabilities > Run a Prompt feature:
     
     
    This Model
     
    This allows me to define a custom prompt and configure how the output should be returned:
     
     
     
    In my case, I’m selecting the "Document" output type, which requires a Word document template. As shown below, I populate the template using placeholders like {{...}}, which are correctly recognized:
     
     
    Within the prompt itself, I specify exactly where each response should be inserted. For example:
    “Answer the questions above, including the question (skipping one line between each), the answer, parameter classification, and corrective actions in a single text block at: {{Verificacao}}”
    Here’s the issue I’m encountering:
    If I create the action from scratch, define the prompt, upload the document template, and run a test without saving the flow, everything works perfectly. The output is generated as expected:
    However, once I save the flow and try to run it again, I receive the following error:
     

    Mensagem de erro:

    {error: {code: "0x80048d0f",…}}
    code: "0x80048d0f"
    message: {"operationStatus":"Error","error":{"type":"Error","code":"DependencyFailure","message":"An error occurred while replacing output document placeholders.","properties":{"BackendErrorCode":"InternalServerError","DependencyHttpStatusCode":"500"}}}
    My question is: What changes after saving the flow that could be causing this error? Is there any specific requirement that my document template might not be fulfilling?
    Any guidance or documentation you can provide would be greatly appreciated.
    Best regards,
    Marcos Eduardo Soares Santana
     
     
  • Verified answer
    Jerry-IN Profile Picture
    116 on at
    Error when replacing placeholders in Word document using Custom Prompt in Power Automate
     
    Greetings!
     
    It looks like you're encountering a common but tricky issue when using a custom AI prompt in Power Automate to populate a Word template. The error occurs because the "Populate a Microsoft Word template" action requires a value for every placeholder field you've defined in the template. If your AI model doesn't return a value for an optional field (like {{NaoConformidades}}), the action fails because it receives a null or missing input for that field.
     
    The key to solving this is to handle the potentially null values before they get to the Word connector. You can do this using the coalesce() expression in Power Automate. This function checks if a value is null and, if it is, provides a default value you specify (like an empty string).
     
    Here’s how you can apply this to your flow:
     
    1. Parse the AI Output: First, ensure you are parsing the JSON output from your "Create text with GPT on Azure OpenAI Service" action using a "Parse JSON" step. This will make it easier to access each field.
    2. Use coalesce() in the Word Action: In your "Populate a Microsoft Word template" action, instead of directly mapping the dynamic content from the AI output, you will use an expression for each field. For a field like Verificacao, you would use :coalesce(outputs('Parse_JSON')?['body']?['Verificacao'], '')
     
    This expression does the following:
    • outputs('Parse_JSON')?['body']?['Verificacao']: Attempts to get the value of the Verificacao field from the parsed AI output.
    • coalesce(..., ''): If the Verificacao field is null or doesn't exist, it will return an empty string ('') instead.
    You will need to apply this coalesce() expression for every placeholder in your Word template action, including {{Seletividade}}, {{Linearidade}}, and all the others. This ensures that even if the AI model omits an optional field, the Word connector receives a valid (empty) string instead of a null value, preventing the error and allowing your flow to complete successfully.
     
    By implementing this, your flow will become robust enough to handle cases where the AI-generated content is missing optional fields.
     
    I hope this solution gets your document generation process running smoothly!
     
    Best regards,
    Jerald Felix

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Copilot Studio

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 420 Super User 2025 Season 2

#2
trice602 Profile Picture

trice602 141 Super User 2025 Season 2

#3
Jerry-IN Profile Picture

Jerry-IN 68

Last 30 days Overall leaderboard