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."
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.
Types of Variables
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.
Runtime Variables
Some 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
.
Calling Variables
To use a variable in any block or prompt, reference it by enclosing the variable name in double curly braces: {{variable_name}}
.
Example Calling Variables in a Generate Text Block:
Extracting a Value from a JSON Structure
MindStudio provides tools for extracting specific values from JSON objects using the JSON Path syntax and the get
helper. This allows workflows to handle and manipulate structured data with precision, making them more dynamic and adaptable.
get
Helper - Query JSON Variables
get
Helper - Query JSON VariablesThe get
helper allows you to query JSON variables for specific values using JSON Path expressions. This feature is especially useful when working with nested or complex JSON structures.
Syntax:
Example 1: Extract a Nested Value:
Given the following JSON assigned to myJsonVariable
:
Use this to extract the email address:
Output: alice@example.com
Example 2: Extract the First Item in an Array:
Given the following JSON:
Use this to extract the name of the first item:
Output: Foo
Example 3: Extract Multiple Values:
JSON Path also allows for querying multiple elements. Given the following JSON:
Output: ["Foo", "Bar"]
Best Practices When Extracting JSON
Use a JSON Path Tester: Tools like JSONPath Online Evaluator can help you refine and test your JSON Path queries.
Validate JSON Structure: Ensure your variable contains valid JSON data before attempting to extract values.
Handle Missing Values: Include fallback logic in your workflow to handle cases where the expected path does not exist in the JSON.
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:
For a full list of expressions, see Handlebars Documentation.
Special Handlebars Methods in MindStudio
In addition to standard Handlebars features, MindStudio introduces two special methods for advanced functionality:
{{json varName}}
{{json varName}}
Converts a JSON object into a string format.
Example:
If userProfile
contains:
Usage:
Output:
{{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:
Extract the last 3 lines:
Extract the first 10 letters:
Last updated