Create the right prompt for the AI Twig generator
Discover best practices for creating the right prompt for the AI-based Twig generator in rule boxes in Productsup.
Best practice
Some rule boxes in the platform, such as Text Template and Text Template with List, let you use Twig. Twig is a template engine based on PHP that lets you add dynamic content in the template.
See Use Twig to dynamically create new information for more details.
If you need a suggestion for a possible Twig, use our AI-based Twig generator available in the rule boxes. To get the necessary Twig, you need to describe your goal, enter some data examples and the desired result. However, some cases need more precise prompts.
To make the AI-generated Twig suggestions more accurate, we recommend using the following prompt examples:
Use currentValue
to refer to the selected attribute value
When you need to refer to the value of the attribute to which you add a rule box or condition, use currentValue
to introduce the needed attribute value in the prompt. You need to enter the value in double quotes ("value") keeping in mind that it is case-sensitive.
Prompt example | Answer |
---|---|
I would like to display "This is not e-coffee" if the currentValue is "N", and "This is e-coffee" if the currentValue is "Y". |
|
Here is how it looks in the Twig generator:
Refer only to the attributes from the previous stage
If you need to insert values from other attributes into the text template created by Twig, you can only refer to the attributes from the previous stage:
If you add a rule box with Twig between the import and intermediate stages, you can only refer to an attribute from the import stage.
If you add a rule box with Twig between the intermediate and export stages, you can only refer to an attribute from the intermediate stage.
When creating a prompt in the Twig generator of a rule box, you must enter the names of the attributes exactly as they are in the previous stage.
Prompt example | Answer |
---|---|
I currently have two variables called "price_import" and "stock_import". They contain prices and stock, respectively. I would like to display "Best seller" if the price is above 16 and the stock is more than 0. |
|
Remove excessive spaces in the strings created with Twig
When the Text Template rule box with Twig inserts strings in the attributes, OpenAI creates additional spaces at the beginning and end of the string.
To remove spaces, apply the rule box Remove Spaces at Beginning and End (Trim) right after the rule boxes Text Template or Text Template with Lists.