Skip to main content
Agents can populate a custom Word, Excel, or CSV document. Common examples include:
  • A Lease Abstract Template
  • A Financial Model (Speadsheet)
  • A Reporting Template
When an Output Template is added to an Agent, the Agent will replace placeholders in the document with results from its Prompts. All other styles, formatting, formulas, and macros in the document will be preserved.

Setting A Template For An Agent

How Templates Work

Each Agent has three components:
  1. Input: Where the Agent will look for source documents
  2. Prompts: The instructions which the Agent will execute on the source documents
  3. Output: Where Agent will put the results of its Prompts
We can insert the results of an Agent into an Output Template document. Each Prompt has an associated placeholder which we can insert into the Output Template and then save to the Agent. When the Agent completes a Run, placeholders are replaced with the results from that Prompt.

Setting Up A Template

Starting your from Agent’s main page, click “Set Template” in the “Output” box. This will open an modal where you can upload a template file. From this modal, you will see each Prompt defined for the Agent as well as their corresponding placeholder. Open your template document in a seperate window using Word, Excel, or some other document editor. Copy and paste the appropriate placeholders into your template document. If necessary, define new Prompts to populate your template. Each new prompt will have an associated placeholder.
Kolena will preserve the font and format of the placeholders. For example, if your placeholder is {{ company_name }} in bolded, size 24, Times New Roman and your Agent Run has Company Name extracted as Kolena Inc, the placeholder will be replaced with Kolena Inc, also in bolded, size 24, Times New Roman.All elements in the template files that are not in placeholders (e.g. text, images, and borders) will be preserved.

Uploading the Template

Once you have copy-pasted the appropriate placeholders into your document, save it and upload it in the “Set Output Template” modal. When uploading, Kolena will indicate which placeholders are detected in the document. Click “Submit” to save the template to the Agent.

Templating the Output File Name

Placeholders can also be used to populate the output file name by using the same curly-bracket syntax in the file name of the template. For example, if you have a lease abstract template and want each file to be named using the property address (“123 Example St - Lease Abstract.pdf”):
  1. Ensure your Agent has a prompt that returns the property address (suppose its placeholder is property_address)
  2. Name your lease abstract template file {{ property_address }} - Lease Abstract.docx
  3. Upload this template file to your Agent
When an output is downloaded manually or sent to a Destination, the placeholder in the file name will be replaced with the real property address.
Form prompts can also be used in the template file name, via either of these two syntaxes:
  1. {{ property_info["Address"] }} - Lease Abstract.docx
  2. {{ property_info.Address }} - Lease Abstract.docx

Using the Template

Once you’ve uploaded a template to the Agent, you can use it for direct downloads and for automated Integrations to Destinations.

Downloading the Output

You can directly download the Templated Output for a given Agent Run:
  1. Navigate to the desired Agent Run
  2. Click into the “Report” tab
  3. Click on the (Download) icon
  4. Select your desired template and format from the download menu
Word Output Templates may be downloaded as either an editable docx, or a generated pdf.

Configuring a Destination

You can also specify a template for export with a Destination:
  1. From the Agent’s main page, click on “Add Destination” in the “Output” box, or edit an existing Destination
  2. Under the “Export Options” section for the Destination, select your desired Ouput Template as the “Fill Template”.

Advanced

Kolena uses the Jinja templating syntax with the docxtpl engine. This tooling allows support for more advanced rendering, such as with tables and conditionally displaying values.

Tables

You can loop over the values of a Kolena table prompt.
  • Word
  • Excel
Date                          Payee                   Payment Value
{%tr for item in payments %}
{{ item["Payment Date"] }}    {{ item["Paid To"] }}   {{ item["Amount"] }}
{%tr endfor %}
In this case, if my {{ payments }} prompt gave me a table with details on individual payments, the above syntax would allow me to replicate that table (with formatting) into my templated output. Note that the field being retrieved from the item must match the prompt’s table columns but the header columns used in the template are free to differ.

Referencing Specific Table Rows

If you wish to reference a specific row from a table prompt, you can do so using bracket notation. For instance, to reference the first row’s Payment Date from a payments table prompt, you can use:
{{ payments[0]["Payment Date"] }}
Be aware that accessing a row which does not exist will result in an error during template rendering. To avoid this, you can use a conditional to check that the row exists before accessing it. For example:
{{ (payments[0]["Payment Date"] if payments|length > 0 else '') }}

Forms

You can treat the values of a Kolena form prompt as key value pairs. When using form data in templates, you can access individual fields using bracket notation:
{{ person_info["Name"] }} is {{ person_info["Age"] }} years old.
If you have a form prompt with the template placeholder person_info with the fields ["Name", "Age", "Email", "Phone"], the unused fields are ignored.

Conditionally Displaying Sections

You can conditionally display a certain section from the template file based on prompt values using the if syntax:
  • Word
  • Excel
{%p if tax_value > 0 %}
Due to local regulations, a tax amount of ${{ tax_value }} is owed.
{%p endif %}
The above blurb about tax value will only be displayed if the {{ tax_value }} prompt retrieves a number greater than zero, and will otherwise not be displayed in the templated output.

Reserved Placeholders

The following placeholders are automatically provided and can be used in templates:
  • {{ _kolena_date }}: Date of the Agent Run in UTC, formatted as YYYY-MM-DD.
  • {{ _kolena_agent }}: Name of the Agent running the prompt.
The following placeholders are reserved for internal use by Kolena and cannot be used in templates. They will not be rendered in the final output:
  • {{ sheet_name }}
  • {{ tpl_name }}

Excel Number Cells

This feature is experimental
Numbers in the Excel Output Templates may show as text cells which can break formulas. To fix this, instead of {{ prompt_name }} you can use {%xv prompt_name %} in your Excel template file, such as {%xv item["Amount"] %}.