#
Context Template
Applies to: Text Completion APIs
For equivalent settings in Chat Completion APIs, use Prompt Manager.
Usually, AI models require you to provide the character data to them in some specific way. SillyTavern includes a list of pre-made conversion rules for different models, but you may customize them however you like.
Edit these settings in the "Advanced Formatting" panel.
#
Story String
This field is a template for the prompt preamble (known internally as a story string). This is the main way to add the information defined in Character Cards for text completion and instruct models.
The template supports Handlebars syntax, custom text injections or formatting, and any other macros. See the language reference here: https://handlebarsjs.com/guide/
We provide the following parameters to the Handlebars evaluator (wrapped in double curly braces):
{{anchorBefore}}: Prompts set to use the "Before Story String" position.{{anchorAfter}}: Prompts set to use the "After Story String" position.{{description}}: The character's Description.{{scenario}}: The character's Scenario.{{personality}}: The character's Personality.{{system}}: The system prompt OR the character's main prompt override (if it exists and "Prefer Char. Prompt" is enabled in User Settings).{{persona}}: The selected persona's description.{{char}}: The character's name.{{user}}: The selected persona's name.{{wiBefore}}or{{loreBefore}}: Combined activated World Info entries with Position set to "Before Char Defs".{{wiAfter}}or{{loreAfter}}: Combined activated World Info entries with Position set to "After Char Defs".{{mesExamples}}: (Optional) The character's Example Dialogues, instruct-formatted with a separator.{{mesExamplesRaw}}: The character's Example Dialogues in raw format, without any formatting.
Important
When using {{mesExamples}} in the Story String, set "Example Messages Behavior" in the User Settings panel to "Never include examples" to avoid duplicating example messages in the prompt.
A special {{trim}} macro is supported to remove any newlines that surround it. Use it if you want a part of the text to not be separated from the previous line by a newline (spaces are not trimmed).
WARNING: If any of the above parameters are missing from the story string template, they will not be sent in the prompt at all.
#
Prompt Anchors
The {{anchorBefore}} and {{anchorAfter}} are generic placeholders for prompts added by various extensions and miscellaneous features in a chosen static position, for example:
#
Story String position
By default, the rendered story string (with all placeholders replaced) is placed at the very beginning of the prompt, followed by example messages and the visible chat history.
Alternatively, you can move it to a dynamic position by choosing the "In-chat @ Depth" option, which places the story string at a specific depth in the chat context.
Attention
If the template contains static prompt elements (model-specific prefixes or suffixes) for wrapping the story string, using the "In-Chat @ Depth" position will cause it to be incorrectly double-wrapped with duplicate sequences, which may lead to unexpected results.
In this case, you can fix the issue in one of the following ways:
- Built-in templates: Reset the templates to their defaults using the steps described in Advanced Formatting.
- Custom templates: Move the static elements from the story string template to Story String Sequences.
#
Story String wrapping
The following section only applies when Instruct Mode is ON.
- Default position: The rendered Story String will be wrapped using the sequences defined in Story String Sequences.
- In-chat @ Depth position: The rendered Story String will be wrapped using the sequences defined in Chat Messages Sequences for a chosen role (default: System).
#
Example Separator
Used as a block header and a separator between the example dialogue blocks. Any instance of <START> tags in the example dialogues will be replaced with the contents of this field.
#
Chat Start
Inserted as a separator after the rendered story string and after the example dialogues blocks, but before the first message in context.
#
Separators as Stop Strings
Adds "Example Separator" and "Chat Start" to the list of stop strings.
Helpful if the model tends to hallucinate or leak whole blocks of example dialogue preceded by the separator.
#
Names as Stop Strings
Adds Character and User Persona names to the list of stop strings.
Recommended to keep it on to prevent model impersonation.
#
Always add character's name to prompt
This setting has no effect when Instruct Mode is ON. The name behavior is instead defined by the selected Include Names option.
Appends the character's name to the prompt to force the model to complete the message as the character:
** OTHER CONTEXT HERE **
Character: