String Template Syntax
String templates enable dynamic configuration by integrating variable values into predefined string patterns. This feature is valuable for building flexible queries or expressions that adapt to input data in real time. It is particularly effective for dynamically adjusting a node's configuration based on incoming input events.
How to Use String Templates
In designated input fields that support string templates, users can define placeholders using the format {{JSONPath}}
.
These placeholders act as references to fields within input events. During execution, Fleak evaluates the Json path
expression, retrieves the corresponding value from the input, and substitutes the placeholder with the actual value.
The string template feature is supported only in specific input fields
Examples
Dynamic URL Construction
Consider an HTTP Data Input node containing input data as follows:
{
"id": "user_identifier"
}
To extract user-specific information via an API call, a string template can be used within the HTTP request URL:
https://www.example.com/company/{{$.id}}/user
For each input event, Fleak will replace {{$.id}}
with the value of the id field. If the input event data is as shown
above, the final URL will be:
https://www.example.com/company/user_identifier/user
This approach ensures that the node configuration remains dynamic and automatically adapts if the id
value changes.
Error Handling with Json Path
Suppose your HTTP Data Input node includes:
[
{
"first_name": "James",
"last_name": "Smith"
}
]
In an LLM node prompt, an incorrect Json Path in the template is mistakenly used:
{{$.forst_name}}
Due to the misspelling, the Json path does not resolve to a valid value, resulting in null
being returned during
processing. This demonstrates the importance of using correct Json path expressions; otherwise, placeholders will be
replaced by null
.
Best Practices
- Ensure that your input data structure aligns with the Json Path expressions used in the placeholders.
- Validate Json path syntax to avoid errors and unexpected Null results.
- Use descriptive and precise Json path references to maintain the readability and reliability of your configurations.
For more on Json path, click here to refer to the Json path Documentation.