For the complete documentation index, see llms.txt. This page is also available as Markdown.

Functions

Transform variable values inline with functions — math, text, dates, JSON, lists, and more.

Variables let you store and reuse values across a conversation. Functions let you transform those values inline — round a number, format a date, clean up text, parse JSON, or reshape a list — right where you use them, without extra logic blocks.

You can apply functions in any field that supports variable interpolation: Text, Set Values, Condition, API, and Prompt blocks, among others.

New to variable interpolation and the {{ ... }} syntax? Start with the Variables guide, then come back here to transform those values.

How Functions Work

A function is an operation — a calculation, an edit, or a check — applied to a value. You apply one with the pipe character (|):

{{ variable | function }}

You can chain as many functions as you like. They run left to right, each receiving the output of the previous one:

{{ variable | function1 | function2 | function3 }}

Whitespace inside the braces is ignored, and any invalid function (or a reference to a variable that doesn't exist) is simply skipped.

Each function can take zero, one, or more arguments. A single argument follows a colon:

// name = "Dante"
{{ name | append: "-san" }}   // Dante-san

Multiple arguments are separated by commas:

// name = "Dante"
{{ name | regex_replace: "D", "f" }}   // fante

Good to know

  • The result is always text. Whatever the input type — number, date, list — the value produced by a function is returned as a string.

  • Setting and transforming in the same step. All variables inside a single Set Values block are evaluated at the same time. If you need to set a variable and then apply a function to that new value within the same flow, use two separate Set Values blocks — otherwise the function reads the old value.

  • A malformed function can break an Answer. If a function is written incorrectly, the Answer that contains it may fail to trigger when you test it in the chat preview. Check your syntax if a tested Answer doesn't fire.

🧰 General

default

Sets a fallback value for any variable that has no value assigned. default returns the fallback when the input is nil, false, or empty.

🔢 Number Operations

abs

Returns the absolute value of a number. Also works on a string that contains a number.

at_least

Limits a number to a minimum value.

at_most

Limits a number to a maximum value.

ceil

Rounds a number up to the nearest integer. The input is converted to a number first.

divided_by

Divides a number by another number. The result type matches the divisor: divide by an integer and you get an integer (rounded down); divide by a float and you get a float.

floor

Rounds a number down to the nearest integer. The input is converted to a number first.

minus

Subtracts one number from another.

modulo

Returns the remainder of a division.

plus

Adds one number to another.

round

Rounds a number to the nearest integer, or to the number of decimal places passed as an argument.

times

Multiplies one number by another.

random

Returns a random element. Applied to a string, it returns a random character; with a numeric argument, it returns a random integer in that range.

🔤 Text Operations

append

Adds a string to the end of another string. Also accepts a variable as its argument.

capitalize

Capitalizes the first character of a string and lowercases the rest. Only the first character is affected.

downcase

Lowercases every character of a string.

upcase

Uppercases every character of a string.

lstrip

Removes all whitespace (tabs, spaces, newlines) from the left side of a string. Whitespace between words is preserved.

rstrip

Removes all whitespace from the right side of a string.

strip

Removes all whitespace from both sides of a string.

strip_newlines

Removes newline characters (line breaks) from a string.

prepend

Adds a string to the beginning of another string. Also accepts a variable as its argument.

remove

Removes every occurrence of a substring from a string.

remove_first

Removes only the first occurrence of a substring.

replace

Replaces every occurrence of the first argument with the second.

replace_first

Replaces only the first occurrence of the first argument with the second.

slice

Returns a substring (or a slice of an array) starting at the given index. An optional second argument sets the length. Indices start at 0; a negative index counts from the end.

strip_html

Removes HTML tags from a string.

A common use is cleaning a context variable before injecting it into a Prompt block:

truncate

Shortens a string to the given number of characters. If the string is longer, an ellipsis (...) is appended and counted in the total.

An optional second argument sets a custom trailing sequence. Its length counts toward the character limit — so to truncate to exactly 10 characters with a 3-character ellipsis, pass 13.

truncatewords

Shortens a string to the given number of words, appending an ellipsis when the string is longer.

translate

Translates a text variable into a target language, identified by its language code.

🔎 Regular Expressions

Regular expressions (regex) let you match and extract patterns inside text. Two functions use them: regex (extract) and regex_replace (substitute).

regex

Extracts every match of a regex pattern from a string. The result is a list: for each match, the first element is the full match and any following elements are the groups captured with parentheses.

You can make the match case-insensitive with a second argument:

A regex is a rule describing a pattern in text — for example, dd matches a double d. A rule combines identifiers (which characters to match) with quantifiers (how many).

Common identifiers:

Identifier
Description
Example match

a

A single character. Any key can be matched this way except some reserved characters. Uppercase and lowercase are different.

Ciao

mela

A sequence of characters.

I'd like to eat an apple

\*

The literal *. Reserved characters (* [ ] { } . and \ itself) are matched by prefixing a backslash.

All done*****

[abc]

A class: any one of the characters inside the brackets.

How the trees grow here — c, a, b

[0-9]

A range inside a class. [0-9] is any digit; [A-Z], [a-z], [A-Za-z] work the same way.

The area code is 081

([a-z][0-9])

A group: collects identifiers so a quantifier applies to all of them. Groups are returned as captures in the result.

(?:[a-z][0-9])

A non-capturing group: starting with ?: excludes the group from the result. Useful to structure a rule without returning that part.

Common quantifiers:

Quantifier
Description

*

Any number of the identifier (including zero)

?

At most one

+

At least one (one or more)

{0,3}

A specific range — here, 0 to 3. You can give only the lower or upper bound.

This is a brief introduction to regular expressions, not a complete reference. For a deeper dive, see one of the many resources online, such as the Wikipedia article on regular expressions.

regex_replace

Replaces the parts of a string that match a regex. Chains well to apply several substitutions in sequence.

🔐 Text Encoding

base64_decode

Decodes a Base64 string.

base64_encode

Encodes a string as Base64.

escape

Escapes a string by replacing characters with their escape sequences — for example so the string can be used in a URL. Strings with nothing to escape are unchanged.

escape_once

Escapes a string without re-escaping entities that are already escaped.

newline_to_br

Inserts an HTML line break (<br />) before every newline (\n) in a string.

url_decode

Decodes a URL-encoded string (for example, one produced by url_encode).

url_encode

Converts URL-unsafe characters into percent-encoded characters. Note that a space becomes + rather than a percent-encoded character.

🔀 Splitting & Converting

split

Splits a string into an array using the argument as the separator. Commonly used to turn comma-separated values into an array.

join

Combines the elements of an array into a single string, using the argument as the separator.

format_list

Displays a list in its correct format. By default, printing a list variable concatenates its values with no separators; format_list renders it as a proper list — useful for display or for passing to third-party services.

This is the recommended workaround for the List-printing limitation described in the Variables guide.

to_integer

Converts a value to an integer. A float is rounded; for an array, every element is converted.

to_float

Converts a value to a float. For an array, every element is converted.

📅 Working with Dates

date

Converts a timestamp to another date format. The format syntax matches strftime.

To get the current time, pass the special word "now" (or "today"):

parse_date

Converts a date string in YYYY-MM-DD format into a datetime structure, which makes further date and time operations easier. Accepts an optional timezone.

parse_date_and_time

Like parse_date, but also takes a time string in HH:mm:ss format. An optional third argument sets the timezone.

timestamp_to_datetime

Turns an integer representing seconds since 1970-01-01 (a Unix timestamp) into a datetime structure. Accepts an optional timezone.

shift_datetime_timezone

Shifts a datetime to a different timezone, adjusting the date and time accordingly.

add_time

Adds time to a datetime. The first argument is the amount (a positive or negative integer); the second is the unit:

  • d — days

  • h — hours

  • m — minutes

  • s — seconds (the default if omitted)

format_datetime

Turns a datetime into a string following the given format. Each element is written as %<padding><length><element>:

  • padding (optional): - none, _ pad with spaces, 0 pad with zeros

  • length (optional): an integer for how much space the element should occupy

  • element: a character selecting which piece of the datetime to output

Element
Description
Example

a

Abbreviated day name

Mon

A

Full day name

Monday

b

Abbreviated month name

Jan

B

Full month name

January

d

Day of the month

01, 31

f

Microseconds (no padding/length)

000000, 999999

H

Hour (24-hour clock)

00, 23

I

Hour (12-hour clock)

01, 12

j

Day of the year

001, 366

m

Month

01, 12

M

Minute

00, 59

p

"AM" or "PM"

AM, PM

P

"am" or "pm"

am, pm

q

Quarter

1, 2, 3, 4

s

Seconds since 1970-01-01 00:00:00 UTC

1565888877

S

Seconds

00, 59

u

Day of the week, starting Monday

1, 7

y

Two-digit year

01, 86, 18

Y

Year

0001, 1986

z

UTC offset (+hhmm / -hhmm)

+0300, -0530

Z

Timezone abbreviation

CET, BRST

%

A literal "%"

%

An optional language argument changes the day and month names. Supported languages are en (default) and it.

compare_with_date

Compares a datetime with a date in YYYY-MM-DD format. Returns gt (datetime is later), eq (same date), or lt (datetime is earlier).

compare_with_time

Compares a datetime with a time in HH:mm:ss format. Returns gt, eq, or lt.

🗂️ Working with JSON

get

Retrieves a nested value from an object, or a value at a specific position in an array (starting at 0).

json_decode

Parses a JSON string into a map (a structure you can traverse, like a parsed JSON object).

json_encode

Encodes a value into a JSON string.

json_to_markdown

Converts a list of maps into a Markdown table. The keys of the first map are used as the columns. An optional argument is a comma-separated list of labels, to filter or reorder columns.

json_path

JSONPath is a standard for retrieving and filtering data from a JSON document using a path expressed as a string. The platform supports a subset of JSONPath. Always run json_decode first, since json_path works on maps and lists.

For the examples below, assume the variable var holds this JSON:

Read a top-level field. Every path starts with $ (the root). The . operator accesses a key; chain operators to reach nested keys.

Read an item by index. Use array syntax; numbering starts at 0.

Filter a list. Inside the brackets, ? introduces a condition and @ refers to the current element being tested.

Extract a field from every item. The : operator defines a range X:Y, where X is the start index (from 0) and Y is the first index to exclude. Omit both to mean the whole list.

Match with OR. Combine conditions to extract items matching any of them.

📄 Working with CSV

csv_to_json

Turns a CSV into a list of maps keyed by the CSV headers. The result is a map with an ok key (the rows parsed correctly) and an errors key (the list of errors). An optional argument sets the column separator (default: comma).

csv_to_markdown

Turns a CSV into a Markdown table. Optional arguments: the column separator (default: comma) and a comma-separated list of labels to filter or reorder columns.

📋 Working with Lists

Lists are a special case of JSON, so the JSON functions above also apply to them.

compact

Removes all nil values from an array.

contains

Checks whether a list contains an element. Returns true or false.

first

Returns the first element of an array.

last

Returns the last element of an array.

size

Counts the number of elements in a list, or the number of characters in a string.

push

Adds an element to the end of a list.

pop

Removes the last element of a list.

unshift

Adds an element to the beginning of a list.

shift

Removes the first element of a list.

reverse

Reverses the order of the elements in a list. To reverse a string, split it first, then rejoin.

sort

Sorts the elements of an array in case-sensitive alphabetical order.

sort_natural

Sorts the elements of an array in case-insensitive alphabetical order.

sum

Adds up all the elements of an array.

uniq

Removes duplicate elements from a list.

merge

Merges two lists into one containing the elements of both. The lists can be either list values or JSON in text form.

Looking for concat? It is deprecated — use merge instead, which accepts a list as its argument.

unique_by

Removes duplicates from a list of maps, comparing on the given key. When duplicates are found, the first one encountered is kept.

An optional second argument removes entries whose value is null:

where

Extracts from a list of maps only the elements whose given key has the given value.

Values are compared as strings by default, which can cause false negatives for numbers. Pass a third argument with the data type — text (default), integer, or float — to compare correctly.

🖼️ Working with Images

merge_images

Overlays one image on top of another. Images can be URLs or Base64-encoded data — both valid in HTML. The optional x and y arguments set the anchor point where the second image is placed on the first:

  • Integers align to the pixel. A negative value counts from the end of the image (from the right for x, from the bottom for y).

  • Keywords set standard alignments: left, center, right for x; top, middle, bottom for y.

Next Steps

  • Revisit Variables to see how values get into your flows in the first place.

  • Browse System Variables — many (like $date, $timestamp, $context) pair naturally with the functions on this page.

  • Put functions to work in the Set Values and Condition blocks.

Last updated

Was this helpful?