Prompt Template Specification
A Prompt resource defines a format-string template that maps dataset feature columns into structured training input. Prompts bind a dataset’s column names to positional slots in the training text, controlling how raw data is presented to the model during fine-tuning and evaluation.
Source: ft/prompts.py, ft/utils.py, ft/jobs.py, ft/db/model.py
Template Fields
| Field | Purpose | Example |
|---|---|---|
prompt_template | Full prompt format string used during training | "Instruction: {instruction}\nInput: {input}\nOutput: {output}" |
input_template | Input portion (informational, used in evaluation) | "Instruction: {instruction}\nInput: {input}" |
completion_template | Expected output portion (informational, used in evaluation) | "Output: {output}" |
Placeholders use Python format-string syntax: {feature_name}. Each placeholder must correspond to a column name in the linked dataset’s features JSON array.
ORM Schema
class Prompt(Base, MappedProtobuf, MappedDict):
__tablename__ = "prompts"
id = Column(String, primary_key=True) # UUID
type = Column(String) # PromptType enum value
name = Column(String) # Display name (unique)
description = Column(String)
dataset_id = Column(String, ForeignKey('datasets.id')) # Linked dataset FK
prompt_template = Column(String) # Full template
input_template = Column(String) # Input portion
completion_template = Column(String) # Output portion
Import Validation
_validate_add_prompt_request() enforces:
- Required fields:
id,name,dataset_id,prompt_template,input_template,completion_templatemust all be present on thePromptMetadatamessage. - Non-blank name:
name.strip()must be non-empty. - Unique name: No existing prompt may share the same
name.
The prompt is created via Prompt.from_message(request.prompt), which uses the MappedProtobuf.from_message() method to map protobuf fields directly to ORM columns.
Auto-Generation from Dataset Columns
ft/utils.py::generate_templates(columns) produces default templates from a list of dataset column names:
-
Output column detection: Compares column names against a ranked list of 500 common output column names (e.g.,
answer,response,output,label,target). The column matching the highest-ranked name becomes the output column. If no match, the last column is used. -
Input columns: All columns except the identified output column.
-
Prompt template: Generated as:
You are an LLM responsible for generating a response. Please provide a response given the user input below. <Column1>: {column1} <Column2>: {column2} <Output>: -
Completion template:
{output_column}\n
Returns (prompt_template, completion_template).
Axolotl Auto-Prompt
ft/jobs.py::_add_prompt_for_dataset() generates a prompt automatically when using the Axolotl framework and no prompt is provided:
- Load the Axolotl config from the database by
axolotl_config_id. - Parse the YAML config and extract the dataset type from
config['datasets'][0]['type']. - Query the Config table for a matching
axolotl_dataset_formatsconfig bydescription == dataset_type. - Parse the format config JSON to extract feature column names.
- Build a template:
<Feature>: {feature}\nfor each feature. - Check for an existing prompt with the same
dataset_idandprompt_template. If found, return its ID. - Otherwise, create a new Prompt named
"AXOLOTL_AUTOGENERATED : {dataset_type}_{dataset_name}".
Removal
remove_prompt() deletes the Prompt record by ID. Note that prompts are also cascade-deleted when their parent dataset is removed with remove_prompts=True.
Protobuf Message
PromptMetadata fields: id, type, name, description, dataset_id, prompt_template, input_template, completion_template.