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.

Inheritance
HandlebarsPromptTemplate

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

Positional-Only Parameters

Name Description
context
Required

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

Positional-Only Parameters

Name Description
context
Required

Parameters

Name Description
v
Required

Attributes

model_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'populate_by_name': True, 'validate_assignment': True}

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.fields from Pydantic V1.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'allow_dangerously_set_content': FieldInfo(annotation=bool, required=False, default=False), 'prompt_template_config': FieldInfo(annotation=PromptTemplateConfig, required=True)}

allow_dangerously_set_content

allow_dangerously_set_content: bool

prompt_template_config

prompt_template_config: PromptTemplateConfig