Template
A Template is a structured JSON file that defines the format for creating prompts that are submittable to a specific model. By following the template parameters, you can create prompts that align with the instructions delivered to the model during training.
It contains:
- Token definitions: Maps token values to their template representations
- Instruction structures: Defines how instructions should be formatted as prompts
- Example usage: Shows how to construct valid prompts and expected outputs
Template Structure
A template file contains five main components:
Encrypt Flag
A boolean flag indicating whether the template has been encrypted.
Version
The version of the template file.
Tokens
The tokens section maps token values (the string identifiers used in your protocol) to their template representations. Each token value maps to a combination of the token's key and its template representation.
Unencrypted Template
In an unencrypted template, tokens are represented in their readable format:
{
"tokens": {
"<NON>": "<NON>",
"Continue_": "Continue_",
"Tree_English_Alice_Talk_": "Tree_English_Alice_Talk_",
"Tree_English_Alice_Talk_Emotion_": "Tree_English_Alice_Talk_Emotion_<num_0_10>",
"Tree_English_Cat_Talk_Coordinates_": "Tree_English_Cat_Talk_Coordinates_<num_-1000_1000_3>"
}
}
Template representations include:
- Basic tokens: Just the token key
- NumTokens: Token key followed by
<num_min_max>format - NumListTokens: Token key followed by
<num_min_max_length>format
Encrypted Template
When encrypted, all token values are converted to hexadecimal strings. The template structure remains the same, but the readable token names are replaced with encrypted hexadecimal values throughout the template file.
{
"tokens": {
"Tree_English_Alice_Talk_": "852964847a70ac50a4b6ecfb",
"Tree_English_Alice_Talk_Emotion_": "852964847a70ac50a4b6ecfb2b98d5<num_0_10>",
"Tree_English_Cat_Talk_Coordinates_": "852964847a7050f7ddb6ecfb57f68c<num_-1000_1000_3>"
}
}
Instructions
The instructions section defines how each instruction should be structured as a prompt. Each instruction contains:
- type: Either
"basic"for standard Instructions or"extended"for ExtendedInstructions - structure: A dictionary defining the prompt structure with numbered steps
- input: A string template showing the complete input format
- output: A string template showing the expected output format
Basic Instruction Structure
{
"alice_cat_alice_instruction_continue": {
"type": "basic",
"structure": {
"<BOS>": "<BOS>",
"0": {
"Tree_English_Cat_Talk_": "Tree_English_Cat_Talk_\n<string>"
},
"1": {
"Tree_English_Alice_Talk_": "Tree_English_Alice_Talk_\n<string>"
},
"2": {
"Tree_English_Cat_Talk_": "Tree_English_Cat_Talk_\n"
},
"<RUN>": "<RUN>"
},
"input": "<BOS>\nTree_English_Cat_Talk_\n<string>\nTree_English_Alice_Talk_\n<string>\nTree_English_Cat_Talk_\n<RUN>",
"output": "<string>\n<NON>\n<EOS>"
}
}
Extended Instruction Structure
{
"alice_disappear_cat_alice_instruction_leave": {
"type": "extended",
"structure": {
"<BOS>": "<BOS>",
"0": {
"Tree_English_Alice_Talk_": "Tree_English_Alice_Talk_\n<string>"
},
"1": {
"Tree_English_Vanish_Cat_Talk_": "Tree_English_Vanish_Cat_Talk_\n<string>"
},
"2": {
"Tree_English_Alice_Talk_": "Tree_English_Alice_Talk_<string>\n"
},
"<RUN>": "<RUN>"
},
"input": "<BOS>\nTree_English_Alice_Talk_\n<string>\nTree_English_Vanish_Cat_Talk_\n<string>\nTree_English_Alice_Talk_<string>\n<RUN>",
"output": "<string>\nLeave_\n<EOS>"
}
}
Example Usage
The example_usage section provides examples of how to construct prompts:
{
"example_usage": {
"instruction_input": "<BOS>\nTree_English_Cat_Talk_\n<string>\nTree_English_Alice_Talk_Emotion_<num_0_10>\n<string>\nTree_English_Cat_Talk_Coordinates_<num_-1000_1000_3>\n<string>\n<RUN>\n<string>\nContinue_\n<EOS>",
"extended_instruction_input": "<BOS>\nTree_English_Alice_Talk_\n<string>\nTree_English_Vanish_Cat_Talk_\n<string>\nTree_English_Alice_Talk_<string>\n<RUN>\n",
"valid_model_output": "<string>\nContinue_\n<EOS>"
}
}
Template Components Explained
Special Tokens
Templates use special tokens to mark different parts of the prompt:
<BOS>: Beginning of sequence token, marks the start of a prompt<RUN>: Run token, marks where the model should begin generating<EOS>: End of sequence token, marks the end of expected output<string>: Placeholder for text content that will be filled in<num_min_max>: Placeholder for a numerical value within a specified range. Filled in like5<num_min_max_length>: Placeholder for a list of numerical values. Filled in like[5, 6, 7]
Instruction Types
Basic Instructions
Basic instructions follow a structured pattern where:
- Each context TokenSet is followed by a
<string>placeholder - The final TokenSet is followed by
<RUN> - The expected output is
<string>\n<final_token>\n<EOS>
Extended Instructions
Extended instructions allow for an additional context snippet:
- The last TokenSet in the context includes an embedded
<string>in its template representation - This allows for user input to be included directly in the prompt structure
- The expected output format is the same as basic instructions
Using Templates to Create Prompts
To create a prompt that your model will understand, follow these steps:
- Identify the Instruction: Determine which instruction type matches your use case
- Follow the Input Template: Use the
inputfield from the instruction as your template - Replace Placeholders:
- Replace
<string>placeholders with actual text content - Replace
<num_min_max>with numerical values within the specified range - Replace
<num_min_max_length>with lists of numbers matching the length requirement
- Replace
- Submit the Prompt: Send the completed prompt to your model
Example: Creating a Basic Instruction Prompt
Given this instruction template:
<BOS>
Tree_English_Cat_Talk_
<string>
Tree_English_Alice_Talk_
<string>
Tree_English_Cat_Talk_
<RUN>
You would create a prompt like:
<BOS>
Tree_English_Cat_Talk_
"Where should I go?"
Tree_English_Alice_Talk_
"I don't much care where—"
Tree_English_Cat_Talk_
<RUN>
Example: Creating an Extended Instruction Prompt
Given this instruction template:
<BOS>
Tree_English_Alice_Talk_
<string>
Tree_English_Vanish_Cat_Talk_
<string>
Tree_English_Alice_Talk_<string>
<RUN>
You would create a prompt like:
<BOS>
Tree_English_Alice_Talk_
"Can you tell me which way I ought to go?"
Tree_English_Vanish_Cat_Talk_
"The Cat vanished slowly, leaving only its grin behind."
Tree_English_Alice_Talk_"Then it doesn't matter which way you go."
<RUN>
Example: Using NumTokens
For instructions that include NumTokens, replace the <num_min_max> placeholder with an actual number:
<BOS>
Tree_English_Cat_Talk_
<string>
Tree_English_Alice_Talk_Emotion_5
<string>
Tree_English_Cat_Talk_Coordinates_100,-50,200
<RUN>
The number 5 must be between 0 and 10, and the coordinates 100,-50,200 must all be between -1000 and 1000, with exactly 3 values in the list.
Template Generation
Templates are automatically generated when you save your protocol. The template file is created from:
- All tokens defined in your protocol
- All instructions (both basic and extended)
- The instruction context snippets parameter
- The encryption setting
The template ensures that any prompts you create will match the exact structure your model was trained on.
Best Practices
- Follow the Template Exactly: Deviations from the template structure may result in unexpected model behavior
- Validate Placeholder Values: Ensure numerical values fall within the specified ranges
- Maintain Token Order: Keep the order of tokens as specified in the instruction structure
Databiomes