PromptTemplateBase
Base Classes · AiDotNet.PromptEngineering.Templates
Base class for prompt template implementations providing common functionality and validation.
Implements: IPromptTemplate
Known derived types: ChainOfThoughtTemplate, ChatPromptTemplate, ConditionalPromptTemplate, FewShotPromptTemplate<T>, InstructionFollowingTemplate, RolePlayingTemplate, SimplePromptTemplate, StructuredOutputTemplate
For Beginners
This is the foundation for all prompt templates.
It handles the common tasks:
- Parsing templates to find variables
- Validating that all required variables are provided
- Substituting variables into the template
- Error checking
When you create a new template type, inherit from this class and you get all this functionality for free!
How It Works
This base class handles template parsing, variable extraction, validation, and formatting. Derived classes can override formatting behavior for specialized template types.
Properties
| Property | Summary |
|---|---|
IReadOnlyList<string> InputVariables { get; set; } |
Gets the list of variable names that this template expects. |
string Template { get; set; } |
Gets the raw template string before variable substitution. |
Methods
| Method | Summary |
|---|---|
bool Validate(Dictionary<string, string> variables) |
Validates that the provided variables match the template’s requirements. |
string Format(Dictionary<string, string> variables) |
Formats the template with the provided variables to create a complete prompt. |