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 ToolDocument 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 definition contains

After the builder finishes (or if you configure the tool yourself), these are the parts that matter:

Definition

  • Tool namesnake_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.

See Custom Tools for naming and description guidance.

Inputs

Built from the template’s placeholders (via Fetch template variables). Each input is a field the agent must supply when calling the tool. You can refine descriptions and types so the agent knows what each value means; the set of fields still comes from the template.

Implementation

  • Template URL — Google Doc or Word (SharePoint / OneDrive) file that contains the {{placeholders}}.

  • Tools (subtitle) — enable the drive module the template needs (for example Google Drive or Microsoft 365) so the tool can read the file.

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

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

  • Try it! — run the tool with sample values before you rely on it in a workflow.

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 row.

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. Open the tool builder 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

These samples need to select a template while the workflow runs, so they use use_as_template:

  • Process HR Employee Letter Requests — picks a template from letter type and country, then fills verified employee data (including conditional salary disclosure).

  • Process Incoming Purchase Orders — 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 instead.


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?