HandlebarsPromptTemplate Class
Create a Handlebars prompt template.
Handlebars are parsed as a whole and therefore do not have variables that can be extracted, also with handlebars there is no distinction in syntax between a variable and a value, a value that is encountered is tried to resolve with the arguments and the functions, if not found, the literal value is returned.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Constructor
HandlebarsPromptTemplate(*, prompt_template_config: PromptTemplateConfig, allow_dangerously_set_content: bool = False)
Parameters
Name | Description |
---|---|
prompt_template_config
Required
|
<xref:semantic_kernel.prompt_template.handlebars_prompt_template.PromptTemplateConfig>
The prompt template configuration This is checked if the template format is 'handlebars' |
allow_dangerously_set_content
Required
|
<xref:<xref:semantic_kernel.prompt_template.handlebars_prompt_template.bool = False>>
Allow content without encoding throughout, this overrides the same settings in the prompt template config and input variables. This reverts the behavior to unencoded input. |
Keyword-Only Parameters
Name | Description |
---|---|
prompt_template_config
Required
|
|
allow_dangerously_set_content
Required
|
|
Methods
model_post_init |
We need to both initialize private attributes and call the user-defined model_post_init method. |
render |
Render the prompt template. Using the prompt template, replace the variables with their values and execute the functions replacing their reference with the function result. |
validate_template_format |
Validate the template format. |
model_post_init
We need to both initialize private attributes and call the user-defined model_post_init method.
model_post_init(context: Any, /) -> None
Positional-Only Parameters
Name | Description |
---|---|
context
Required
|
|
render
Render the prompt template.
Using the prompt template, replace the variables with their values and execute the functions replacing their reference with the function result.
async render(kernel: Kernel, arguments: KernelArguments | None = None) -> str
Parameters
Name | Description |
---|---|
kernel
Required
|
The kernel instance |
arguments
|
The kernel arguments Default value: None
|
Returns
Type | Description |
---|---|
The prompt template ready to be used for an AI request |
validate_template_format
Validate the template format.
validate_template_format(v: PromptTemplateConfig) -> PromptTemplateConfig
Parameters
Name | Description |
---|---|
v
Required
|
|
Attributes
allow_dangerously_set_content
allow_dangerously_set_content: bool
prompt_template_config
prompt_template_config: PromptTemplateConfig