Templating Node

Templating Nodes

The Templating Node allows you to perform custom data transformations on a set of defined inputs to create a new output. You can use this to define constants, manipulate data before feeding into a prompt, or massage a response to a format of your liking.

Check out our Common Data Transformation Templates for some common examples.

Templating Node

You may have a templating node that outputs JSON which seems valid, but yields the following error when you click “Test” or run your workflow:

Tips - Using Jinja

Jinja has a tendency to leave hard-to-see whitespace which can cause issues when doing equality checks in places like Metrics or Conditional Nodes.

Templating Node JSON Error
Use double quotes when working with JSON

Jinja has a tendency to leave hard-to-see whitespace which can cause issues when doing equality checks in places like Metrics or Conditional Nodes.

1{# this example will have invisible whitespace #}
2{% if some_condition %}
3 {{ result A }}
4{% else %}
5 {{ result B }}
6{% endif %}
7
8{# this will give the result you expect #}
9{%- if some_condition -%}
10 {{- result A -}}
11{%- else -%}
12 {{- result B -}}
13{%- endif -%}