Amazon Bedrock Studio is in preview release and is subject to change.
Define inputs with expressions
When you configure the inputs for a node, you must define it in relation to the whole
input that will enter the node. The whole input can be a string, number, boolean, array, or
object. To define an input in relation to the whole input, you use a subset of supported
expressions based off JsonPath$.data
, which refers to the whole input. Note
the following for using expressions:
-
If the whole input is a string, number, or boolean, the only expression that you can use to define an individual input is
$.data
-
If the whole input is an array or object, you can extract a part of it to define an individual input.
As an example to understand how to use expressions, let's say that the whole input is the following JSON object:
{ "animals": { "mammals": ["cat", "dog"], "reptiles": ["snake", "turtle", "iguana"] }, "organisms": { "mammals": ["rabbit", "horse", "mouse"], "flowers": ["lily", "daisy"] }, "numbers": [1, 2, 3, 5, 8] }
You can use the following expressions to extract a part of the input (the examples refer to what would be returned from the preceding JSON object):
Expression | Meaning | Example | Example result |
---|---|---|---|
$.data | The entire input. | $.data | The entire object |
.name |
The value for a field called name in a JSON object. |
$.data.numbers | [1, 2, 3, 5, 8] |
[int ] |
The member at the index specified by int in an array. |
$.data.animals.reptiles[2] | turtle |
[int1 , int2 , ...] |
The members at the indices specified by each int in an array. |
$.data.numbers[0, 3] | [1, 5] |
[int1 :int2 ] |
An array consisting of the items at the indices between int1 (inclusive) and int2 (exclusive) in an array. Omitting int1 or int2 is equivalent to the marking the beginning or end of the array. |
$.data.organisms.mammals[1:] | ["horse", "mouse"] |
* | A wildcard that can be used in place of a
name or
int . If there are multiple
results, the results are returned in an array. |
$.data.*.mammals | [["cat", "dog"], ["rabbit", "horse", "mouse"]] |
The following procedure shows how to use expressions to identify fields in a JSON object that you send to a prompt node. The prompt generates a playlist of songs. The JSON object you pass to the flow identifies the number of songs that you want in the playlist and the genre of music that you want the songs to represent. For example, enter the following JSON object to request a playlist of 3 songs in the pop genre.
{ "genre": "Pop", "number": 3 }
To use an expression
Create an empty Prompt Flows app by doing Create an initial Prompt Flow app.
In the flow builder, choose the Flow input node.
In the Prompt Flow builder pane choose the Configure tab.
In Outputs section, choose Type and then select Object.
-
In the Prompt Flow builder pane, select Nodes.
-
From the Orchestration section, drag a Prompt node onto the flow builder canvas.
-
Select the node you just added.
-
In the Configurations tab of the Prompt Flow builder pane, do the following:
-
For Node name, enter
playlist_songs_genre_node
. In Prompt details choose Create new prompt to open the Create prompt pane.
For Prompt name, enter
playlist_songs_genre_prompt
.For Model, choose the model that you want the prompt to use.
For Prompt message enter
Create a playlist of {{number}} songs that are in the {{genre}} genre of music.
.(Optional) In Model configs, make changes to the inference parameters.
Choose Save draft and create version to create the prompt. It might take a couple of minutes to finish creating the prompt.
-
In the flow builder, choose the prompt node that you just added.
-
Choose the Configure tab and do the following in the Prompt details section:
-
For Prompt, select the prompt that you just created (playlist_songs_genre_prompt).
-
For Version, select the version (1) of the prompt to use.
-
For the number input in the Inputs section, do the following:
-
Change the value of Type to Number.
-
Change the value of Expression to
$.data.number
.
-
-
For the genre input in the Inputs section, do the following:
-
Make sure the value of Type is String.
-
Change the expression for the input to
$.data.genre
.
-
-
-
Connect the output from Flow input node to the input number of the Prompt node.
-
Connect the output from Flow input node to the input genre of the Prompt node.
-
Connect the output from the prompt node to the input of the Flow output node.
Choose Save to save the flow. The flow should look similar to the following.
Test your prompt by doing the following:
On the right side of the page, choose < to open the Test pane.
-
Enter the following JSON in the Enter prompt text box.
{ "genre": "Pop", "number": 3 }
-
Press Ctrl + Enter on your keyboard or choose the run button to test the prompt. The response should be a playlist of 3 songs in the pop music genre.