Skip to main content

Generate Documents from Templates

Choose between a Document Template Tool and use_as_template, then set up Word or Google Doc templates so your workflow can fill placeholders and produce finished documents.

Generate Documents from Templates

A document template is a Word document or Google Doc with placeholders such as {{EmployeeName}}. When a workflow runs, the platform fills those placeholders with live data and saves a new finished document.

Templates are the usual way to produce employment letters, purchase-order confirmations, exception notices, and similar formatted outputs. The template owns layout and formatting; the workflow supplies the data.

There are two ways to generate a document from a template. Pick based on whether you know the template ahead of time.

Which approach should I use?

Use this

When

Why

Document Template Tool

You know which template file the step should use (you set the template URL when you build the tool)

More reliable: the tool locks to that template, builds named input fields from its placeholders, and can be shared or reused across thunks

use_as_template

The template must be chosen or discovered while the workflow runs

More dynamic: the agent resolves the template URL and field mapping at runtime

Prefer a Document Template Tool whenever the document is known up front. Use use_as_template when the template itself is part of the runtime decision.

Both paths use the same placeholder syntax in the Word or Google Doc. For the full syntax reference, see Handlebars templates for document generation.


Document Template Tool

A Document Template Tool is a custom tool that always renders one specific template. You configure the template URL once; the AI agent calls the tool by name and passes values for the placeholders.

Set up the tool

  1. Open the thunk's Tools area and choose + Add New Tool → Document Template Tool.

  2. Start in the tool builder chat. Describe the document you need (or paste a URL if you already have a template). The builder can create a Google Doc or Word template with the right {{placeholders}}, point the tool at it, fetch the variables, and test a sample render. Prefer this path over wiring everything by hand.

If you already have a finished template file, tell the builder its URL instead — it will attach that file and infer the inputs from the placeholders.

What the tool page contains

After the builder finishes (or if you configure the tool yourself), open the tool from Custom-built tools in the left nav. Its page has three tabs: Definition, Implementation, and Try It.

Definition tab

  • Tool name — snake_case identifier the AI agent uses to call the tool.

  • Description — plain-language summary of what the tool produces and when to use it. The agent reads this to decide whether to call the tool.

The tab also has Logic/Intent and the Enabled switch, as every custom tool does. See Custom Tools for naming and description guidance.

Implementation tab

The tab is split into sections you can open and close. Only Details starts open.

  • Inputs — built from the template's placeholders (via Fetch template variables). Each input is a field the agent must supply when calling the tool. The set of fields always comes from the template, but you can explain them better: turn on Show raw JSON schema? to add a description to a field, or to narrow a plain text field to a number, a date, or a set of allowed values.

  • Outputs — fixed by the tool type: the link to the finished document and its file type. You cannot change it.

  • Details — the template itself:

    • Template URL — Google Doc or Word (SharePoint / OneDrive) file that contains the {{placeholders}}. The buttons next to it download the template or open it in a new tab.

    • Convert output to PDF — optional; when on, the tool returns a PDF instead of an editable Word or Google Doc.

    • Fetch template variables — re-reads the placeholders from the template into Inputs (use this after template edits too).

  • Tools — turn on the connection the template needs (for example Google Drive or Microsoft 365) so the tool can read the file.

  • Behavior — batch and behavior settings shared by all custom tools; see Custom Tools.

Try It tab

Run the tool with sample values before you rely on it in a workflow. The tab asks you to fetch template variables first until the tool has saved its placeholders as inputs.

Finally, enable the named tool on each workflow step that should generate that document, and mention the tool name in the step guidance.

Typical step guidance might read:

Call generate_employment_letter with EmployeeName, JobTitle, StartDate, and Purpose. Save the returned document URL on the work item.

After you change the template

If someone adds, removes, or renames placeholders in the template file, the tool's saved inputs can fall out of date. On the tool's Implementation tab, open Details and click Fetch template variables again so the tool picks up the current placeholders.

If a run fails because the template variables no longer match, see Troubleshooting errors.

Share and reuse the tool

Because the template URL and inputs are part of the tool definition, you can export the Document Template Tool in a tool library and import it into other thunks. See Modular reuse of tools.


The use_as_template tool

The use_as_template tool generates a populated document from a template URL you supply at runtime. It is available when the DocumentTemplates module is enabled on the thunk and on each step that generates a document.

Use this path when the step must discover which template to open — for example, after looking up a letter type, or when different countries use different files.

Set up use_as_template

  1. Enable the DocumentTemplates module at the thunk level and on the workflow step.

  2. In step guidance, tell the agent which template to open (SharePoint, OneDrive, or Google Drive URL), which fields to fill, and what to name the output file.

Typical instructions might read:

Based on LetterType and Country, open the matching template URL. Generate a new document named "Letter - {{EmployeeName}} - {{Date}}.docx". Populate EmployeeName, JobTitle, StartDate, ContractType, WorkLocation, and Purpose.

The agent resolves placeholder values from workflow properties and calls use_as_template.

Tip: Aligned placeholder names between the document and the thunk properties — or explicit mapping instructions in the step guidance — produce the most consistent results.

When this path is harder

Because the agent must choose the template and map fields every run, this path is more flexible but less predictable than a Document Template Tool with a fixed URL. Prefer the custom tool when the template does not need to change at runtime.


Template syntax (shared)

Placeholders use double curly braces: {{VariableName}}. You can also use conditionals ({{#if …}}), loops, and Word-oriented helpers for tables and lists.

Details and a syntax table live in Handlebars templates for document generation.


Examples in the sample library

  • Process HR Employee Letter Requests uses a Document Template Tool. Every letter comes from one Word template, with an {{#if}} block for each letter type. A code tool reads the employee's record, applies the letter policy and calls the template tool, so the salary appears only in the letters that state it.

  • Process Incoming Purchase Orders uses use_as_template. It generates a fulfillment notification from a stored template once payment terms are confirmed.

If your workflow always uses the same letter or form, build a Document Template Tool for that file, as the HR letters sample does.


Troubleshooting

Symptom

Where to look

Document template tool has no template URL

Set Template URL on the tool — see Troubleshooting errors

Template variables no longer match

Re-fetch template variables on the tool

Error: "use_as_template tool is not found"

Often a Handlebars syntax problem in the template (for example an unclosed {{#if}}) — see Handlebars templates for document generation

Did this answer your question?