Variables
Learn how to properly leverage variables in your AI Workflows
Variables in MindStudio are dynamic placeholders that store data during workflow execution. They allow you to pass information between blocks and workflows seamlessly.
Example:
Variable Name:
userName
Usage:
"Hello {{username}}! Welcome to our app."
Types of Variables
Runtime Variables
Most blocks, such as Generate Text Blocks or User Input Blocks, assign values for the variable while the workflow is running. For Example, after performing a Google Search, the block can store the results in a variable called google_result
.

Launch Variables
These are defined in the Start Block of your workflow. Values for these variables are passed in as arguments when a workflow is run via API or via the Run Workflow block.

Global Variables
These variables values are stored in between Agent Runs. They are assigned in the onboarding flow or can be defined in blocks using global.myVariable
syntax.

Creating Variables
Variables are created automatically in MindStudio whenever:
A User Input collects data.
A block generates an output (e.g., Generate Text Block, Analyze Image Block).
You manually define them in the Start Block.
Using Variables
To use a variable in any block or prompt, reference it by enclosing the variable name in double curly braces: {{variable_name}}
.
Example Using Variables in a Generate Text Block:
Summarize the article titled "{{articleTitle}}".
In the summary, make sure to write about the following topic:
{{topic}}
Tips for Working with Large Variables
Variables are replaced with their values before the text is sent to the AI model. You must make sure your message will be coherent and legible after the variables have been substituted with their values. For longer variables, this means using things like XML tags to offset variable content from instructions.
Incorrect:
Summarize this article {{articleContent}} and find all mentions of {{personName}}.
This pattern does not work because {{articleContent}}
will be replaced with the raw text or HTML of an article. If you execute this prompt and view its logs in the Debugger, you will see that what is sent to the model is a giant sentence like "Summarize this article The history of lorem ipsum has long been thought to contain dolor sit amet [...1000 more words from the article directly pasted in] and find all mentions of Taylor Swift".
While AI models are great at parsing text, using simple formatting can make prompts dramatically more effective, as well as easier for you to maintain.
Correct:
<article_content>
{{articleContent}}
</article_content>
Using the provided article content, create a summary of the article as well as a list of all mentions of {{personName}}.
Offsetting with XML-style tags (it doesn't matter what the actual tags are, you can make up anything you like as long as it makes sense) helps the model understand which aspects of your prompt are instructions and which are context. Anthropic found that placing long variables at the top of the prompt using XML tags improved response quality by up to 30%.
To achieve best results, you should strive to make your prompt as easy to read for a human as possible. A handy test is to imagine that you were to print out your prompt on paper (after all variables have been substituted) and give it to someone. Would they be able to understand what you want them to do? Or would it look like gibberish?
MindStudio leverages the Handlebars templating language to make working with variables intuitive and powerful. Handlebars allows you to include, manipulate, and conditionally render data directly in your prompts, outputs, and logic.
Using Handlebars Templating
MindStudio leverages the Handlebars templating language to make working with variables intuitive and powerful. Handlebars allows you to include, manipulate, and conditionally render data directly in your prompts, outputs, and logic.
Conditional Logic
Handlebars supports if-else
logic for dynamic outputs, as well as other control expressions. For a full list of expressions, visit the Handlebars Documentation site.
{{#if userName}}
Hello, {{userName}}! How can we assist you today?
{{else}}
Hello! Please log in to get started.
{{/if}}
{{#if condition}}
{{#if condition}}
Converts a conditional block that renders content only when the condition is true.
Example:
If isLoggedIn
is true
Usage:
{{#if isLoggedIn}}
Welcome back!
{{/if}}
Output:
Welcome back!
{{#unless condition}}
{{#unless condition}}
Converts a conditional block that renders content only when the condition is false.
Example:
If isLoggedIn
is false
Usage:
{{#unless isLoggedIn}}
Please sign in.
{{/unless}}
Output:
Please sign in.
{{#each array}}
{{#each array}}
Iterates over an array or object and renders the block for every item.
Example:
If items
contains:
["Apple", "Banana", "Cherry"]
Usage:
{{#each items}}
{{this}}
{{/each}}
Output:
opyApple
Banana
Cherry
{{#with object}}
{{#with object}}
Changes the evaluation context to the provided object for the enclosed block.
Example:
If user
contains:
{ "name": "Alice", "age": 25 }
Usage:
{{#with user}}
{{name}} is {{age}} years old.
{{/with}}
Output:
Alice is 25 years old.
Special Handlebars Methods in MindStudio
In addition to standard Handlebars features, MindStudio introduces special methods for advanced functionality:
{{json varName}}
{{json varName}}
Converts a JSON object into a string format.
Example:
If userProfile
contains:
{
"name": "John",
"age": 30
}
Usage:
{{json userProfile}}
Output:
{"name":"John","age":30}
{{sample varName number token}}
{{sample varName number token}}
Extracts a portion of the variable's content based on specified parameters.
Parameters:
varName: The variable to sample.
number: The number of items (e.g., lines, words, or letters). If negative, starts from the end.
token: The type of unit to extract (
line
,word
, orletter
).
Examples:
Extract the first 5 words:
{{sample textVar 5 "word"}}
Extract the last 3 lines:
{{sample textVar -3 "line"}}
Extract the first 10 letters:
{{sample textVar 10 "letter"}}
{{lookup object key}}
{{lookup object key}}
Dynamically looks up a property from an object using a key.
Example:
If user
contains:
{ "name": "Alice", "role": "admin" }
Usage:
{{lookup user "role"}}
Output:
admin
{{get varName "property"}}
{{get varName "property"}}
Retrieves a nested property using a JSONPath expression from a JSON object.
Example:
If userData
contains:
{
"name": "Alice",
"contact": { "email": "[email protected]" }
}
Usage:
{{get userData "$.contact.email"}}
Output:
{{add num increment}}
{{add num increment}}
Adds a numeric increment to a given number.
Example:
If num
is:
5
Usage:
{{add 5 3}}
Output:
8
{{subtract num decrement}}
{{subtract num decrement}}
Subtracts a numeric value from a given number.
Example:
If num
is:
10
Usage:
{{subtract 10 4}}
Output:
6
{{multiply value multiplier}}
{{multiply value multiplier}}
Multiplies two numbers.
Example:
If value
is:
2
Usage:
{{multiply 2 5}}
Output:
10
{{divide dividend divisor}}
{{divide dividend divisor}}
Divides one number by another.
Example:
If dividend
is:
10
Usage:
{{divide 10 2}}
Output:
5
{{eq var1 var2}}
{{eq var1 var2}}
Checks if two values are equal using the double-equals operator.
Example:
If var1
contains:
5
and var2
contains:
"5"
Usage:
{{eq 5 "5"}}
Output:
true
{{gt value1 value2}}
{{gt value1 value2}}
Checks if the first value is greater than the second value.
Example:
If value1
is:
10
and value2
is:
5
Usage:
{{gt 10 5}}
Output:
true
{{gte value1 value2}}
{{gte value1 value2}}
Checks if the first value is greater than or equal to the second value.
Example:
If value1
is:
10
and value2 is:
10
Usage:
{{gte 10 10}}
Output:
true
{{lt value1 value2}}
{{lt value1 value2}}
Checks if the first value is less than the second value.
Example:
If value1
is:
5
and value2
is:
10
Usage:
{{lt 5 10}}
Output:
true
{{lte value1 value2}}
{{lte value1 value2}}
Checks if the first value is less than or equal to the second value.
Example:
If value1
is:
5
and value2
is:
5
Usage:
{{lte 5 5}}
Output:
true
{{isEmpty varName}}
{{isEmpty varName}}
Evaluates whether a variable is empty (null, undefined, an empty string, an empty array, or an empty object).
Example:
If data
contains:
""
Usage:
{{isEmpty data}}
Output:
true
{{length varName}}
{{length varName}}
Returns the length of an array or a string. Returns "NaN" if the variable is not an array or string.
Example:
If list
contains:
["a", "b", "c"]
Usage:
{{length list}}
Output:
3
{{itemAt varName index}}
{{itemAt varName index}}
Return an item from an array.
Example:
If list
contains:
["a", "b", "c"]
Usage:
{{itemAt list 1}}
Output:
b
Note that the first item in an array is always index 0
.
{{firstItem varName}}
{{firstItem varName}}
Return the first item from an array.
Example:
If list
contains:
["a", "b", "c"]
Usage:
{{firstItem list}}
Output:
a
{{lastItem varName}}
{{lastItem varName}}
Return the last item from an array.
Example:
If list
contains:
["a", "b", "c"]
Usage:
{{lastItem list}}
Output:
c
{{markdown varName}}
{{markdown varName}}
Converts a Markdown-formatted string into HTML.
Example:
If markdownText
contains:
# Hello World
This is **bold** text.
Usage:
{{markdown markdownText}}
Output:
<h1>Hello World</h1>
<p>This is <strong>bold</strong> text.</p>
{{formattedNumber number fractionDigits}}
{{formattedNumber number fractionDigits}}
Formats a number using locale‑specific formatting with a fixed number of fractional digits.
Example:
If amount
is:
1234.567
Usage:
{{formattedNumber 1234.567 2}}
Output:
1,234.57
{{abbreviatedNumber number fractionDigits}}
{{abbreviatedNumber number fractionDigits}}
Formats a number into a compact, abbreviated notation (e.g., 1K, 1M) with a specified number of fractional digits.
Example:
If amount
is:
1500
Usage:
{{abbreviatedNumber 1500 1}}
Output:
1.5k
{{date varName format}}
{{date varName format}}
Formats a date string according to the specified format. Supports both custom formats (e.g., "YYYY-MM-DD") and relative keywords like "fromNow" or "toNow". Any Moment.js-compatible date format can be used.
Example:
If dateString
contains:
2020-01-01T00:00:00Z
Usage:
{{date dateString "YYYY-MM-DD"}}
Output:
2020-01-01
You can also format the current date by using currentDate
as the variable:
Usage:
{{date currentDate "dddd, MMMM Do YYYY, h:mm:ss a"}}
Output:
Monday, June 9th 2025, 3:25:50 pm
Last updated