Warning: Please note that the information included in this article only refers to LLM Profiles (RAG). If your translation provider is set up using an MT Profile, this information does not apply.
When an LLM is used as your translation provider, Smartling supports the use of conditional syntax and placeholders in the translation prompt:
- Placeholders can be used to modify your default translation instructions.
- Jinja2 conditions can be included in your prompt to dynamically adapt it to specific circumstances based on predefined rules.
Info: For more information about Jinja templating, visit Jinja’s documentation here. Please note that Smartling only supports a limited set of features as described in this article (predefined variables used as placeholders, and conditional syntax).
LLM prompts with conditional syntax
Conditional syntax can help streamline prompt creation. Conditions enable you to use a general prompt and dynamically adapt it to specific circumstances based on predefined rules.
For example, the use of conditions allows you to apply locale-specific rules without having to create a separate prompt for each target locale.
Conditions allow you to apply the correct formality rules for each locale (e.g. If the target locale is fr-FR, use the pronoun "vous" for the formal register; if the target locale is de-DE, use the pronoun "du" for an informal tone, etc.).
By using conditional syntax, you can use the same prompt across languages, but render different rules per locale.
How to use conditions in your prompt
Conditions need to be included in the editable System Role or User Role field of Smartling's prompting interface, together with your translation prompt.
How to use the “Condition” field
A separate “Condition” field allows you to specify if the conditions included in your System Role or User Role message should be applied in the rendered prompt:
- Leave the “Condition” field blank or enter the value “true” if the condition should be applied.
- Enter the value “false” if the condition should not be applied in the rendered prompt.
Example: In this example, the condition entered in the system role field will not be applied in the rendered prompt, as the Condition field is set to "false".
Using placeholders in the "Condition" field
The placeholders defined in your System Role or User Role message can also be used in the "Condition" field, in order to define the scenarios in which the message content will be sent to the LLM.
If the condition below the System Role or User Role message is true, the full message will always be sent. If the condition is not met, the message in the System Role or User Role field will not be sent to the LLM.
Example placeholder: source_locale_id
In this example, the User Role message will be sent to the LLM only if "en" is the source language.
Supported condition syntax
Smartling supports Jinja2 syntax with the following tags: if/elif/else/endif.
Example:
Prompt template (as entered in the System Role field)
Rendered prompt if {{target_locale_id}} is "es-ES"
Translate text
and use this prompt for es-ESHow to use placeholders in your prompt
Smartling supports the use of placeholders in your translation prompt. This is optional and the use of placeholders in your LLM Profile is not required.
In order to resolve placeholders correctly and efficiently, you will need to use the correct placeholder format for each component of your translation prompt.
Placeholders in your System Role prompt
If you would like to include placeholders in your System Role prompt, use curly brackets {} as placeholder markers.
Example placeholders:
{source_locale_id}, {target_locale_id}
Example System Role prompt with placeholders:
Note: This plain text placeholder format is only supported for System Role prompts. Do not use this placeholder format in your User Role prompt.
Placeholders in conditions
Smartling supports the use of conditions following Jinja2 syntax in your System Role prompt or User Role prompt. To use placeholders as part of a condition, apply the Jinja2 placeholder format, which is typically delimited by double curly brackets.
Example placeholders:
{{source_locale_id}}, {{target_locale_id}}
Tip: Inside an {% if %} or {% elif %} statement, reference the placeholder without any brackets (write source_locale_id, not {{source_locale_id}}). Outside of a condition, in the body of your User Role prompt, keep the double curly braces.
Example condition with a placeholder:
Warning: We strongly advise against using a Jinja2 placeholder format with double curly brackets as part of a regular System Role prompt outside of a condition, as this will increase your token usage. If used as part of your regular System Role prompt, the Jinja placeholder will then get resolved twice: once as part of your System Role prompt and once as part of your User Role prompt.
Placeholders in your User Role prompt
If you would like to include placeholders in your User Role prompt, apply the Jinja2 placeholder format delimited by double curly brackets. This placeholder format is also used in Smartling’s default User Role message.
Example placeholders:
{{source_locale_id}}, {{target_locale_id}}
Tip: Placeholders in the User Role message are automatically highlighted to allow for easy visual identification.
Supported placeholders
The placeholders listed below can be included in your translation prompt.
Tip: Please note that the placeholders listed below are listed in a Jinja2 placeholder format for illustration purposes. Please refer to the information on How to use placeholders to ensure you are using the correct placeholder format for each component of your prompt.
Locale and content placeholders
The following placeholders can be added as part of your prompt to modify the default translation behavior. For example, these placeholders can be used to create locale-specific translation rules.
-
{{source_locale_id}}: refers to the source locale as specified in your Smartling project (e.g. en-US). -
{{target_locale_id}}: refers to all target locale(s) as specified in your Smartling project (e.g. es-ES). -
{{translation_requests}}: represents the source content to translate, along with any per-string context Smartling has for it. This replaces both the older{{source_texts}}placeholder and the older{{translation_examples}}placeholder: translation memory examples and String Instructions (see note below) are now included automatically as part of{{translation_requests}}for each string, rather than being available as separate variables.
Placeholders for Assets References
The following placeholders allow you to modify the standard behavior of Smartling's prompt tooling feature.
For example, if Prompt Tooling with RAG is enabled, using your glossary terms as assets references, Smartling will send all available glossary terms to the LLM as part of the rendered prompt. By using the placeholder {{glossary}}, you can adjust this default behavior. For example, your prompt could include the following instruction, in order to avoid using glossary terms with incorrect capitalization as assets references: "Do not insert {{glossary}} terms if they are in different casing in the {{target_locale_id}}."
Each placeholder below only populates with a value if its corresponding checkbox is selected under "Assets References" in your LLM Profile:
-
{{glossary}}: represents glossary terms from the linguistic package associated with your Smartling project. The glossary terms are sent to the LLM as examples of your preferred terminology. -
{{style_rules}}: represents the Automated Style Guides, which are automatically generated and provide a list of locale-specific style rules. -
{{string_role}}: represents the semantic content type of the string being translated (e.g. HTML title, meta description, plain text, subtitle). Only available for strings translated in a workflow. See Prompt Tooling with RAG for details. -
{{file_type}}: represents the source file format of the content being translated (e.g. JSON, XLIFF, HTML, DOCX, SRT, Markdown). Only available for strings translated in a workflow. See Prompt Tooling with RAG for details. -
{{project_label}}: represents the label assigned to the Smartling project being translated, if one exists. Only available when translating in a workflow. See Prompt Tooling with RAG for details.
Example Assets References selection with all sources enabled:
Note: String Instructions do not have their own placeholder. When the String Instructions checkbox is selected under "Assets References," any enabled instructions for a string are included automatically as part of {{translation_requests}} for that string. You cannot reference String Instructions as a separate variable in your prompt or in a condition.
Tip: For more information about Smartling's prompting interface, please visit Creating and Managing LLM Profiles. For more information about Assets References, please visit our documentation on Prompt Tooling with RAG.
Legacy variables
The table below shows the older placeholder variables and their current equivalents. Older variables are still supported for backward compatibility, with one exception noted below, but new and edited prompts should use the current variable names listed earlier in this article.
Renaming a variable doesn't change which bracket format it uses. A variable that used single curly braces in your System Role prompt still uses single curly braces under its new name (e.g. {sourceLanguage} becomes {source_locale_id}, not {{source_locale_id}}). A variable that used double curly braces, in a Condition field or in your User Role prompt, still uses double curly braces under its new name (e.g. {{source_language}} becomes {{source_locale_id}}). See How to use placeholders above for when each format applies, including the one exception: a System Role prompt can use double curly braces, but only inside a Condition field, not in the main prompt text.
| Legacy variable | Current variable |
|---|---|
{sourceLanguage} / {{source_language}}
|
{source_locale_id} / {{source_locale_id}}
|
{targetLanguage} / {{target_language}}
|
{target_locale_id} / {{target_locale_id}}
|
{{source_texts}} |
{{translation_requests}} |
{{glossary_terms}} |
{{glossary}} |
{{translation_examples}} |
No direct replacement Translation examples are now included automatically as part of {{translation_requests}} for each string. They can no longer be referenced as a separate variable. |