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 the 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 Message 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 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 Smartling's system 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_language
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_language}} 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:
{sourceLanguage}, {targetLanguage}
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_language}}, {{target_language}}
Tip: When used as part of a condition, the double curly brackets should be omitted.
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 prompt and once as part of our user prompt.
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 source text 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_language}}: refers to the source locale as specified in your Smartling project (e.g. en-US).{{target_language}}: refers to all target locale(s) as specified in your Smartling project (e.g. es-ES).{{source_texts}}: represents the source text to translate.
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_terms}}, 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_language}}."
{{translation_examples}}: represents example translations from your Translation Memory (TM), with a maximum of five examples and a similarity score above 0.1. This placeholder populates with a value only if the corresponding checkbox is selected under "Assets References" in your LLM Profile.{{glossary_terms}}: 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. This placeholder populates with a value only if the corresponding checkbox is selected under "Assets References" in your LLM Profile.-
{{styleRules}}:represents the Automated Style Guides, which are automatically generated and provide a list of locale-specific style rules. This placeholder populates with a value only if the corresponding checkbox is selected under "Assets References" in your LLM Profile.
Tip: For more information about Smartling's prompting interface, please visit Managing LLM Profiles and Prompts. For more information about Assets References, please visit our documentation on Prompt Tooling with RAG.