semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Python: input_variables default values are never applied when rendering templates

Open ManoharPaturi opened this issue 2 months ago • 0 comments

Description

PromptTemplateConfig.input_variables supports a default per variable, it is even validated (must be a string) and exposed through get_kernel_parameter_metadata as default_value. But the value is never used when rendering: KernelPromptTemplate.render goes straight to the blocks, and VarBlock.render only reads KernelArguments, returning an empty string for anything missing.

Reproduction

from semantic_kernel import Kernel
from semantic_kernel.prompt_template.kernel_prompt_template import KernelPromptTemplate
from semantic_kernel.prompt_template.prompt_template_config import PromptTemplateConfig
import asyncio

cfg = PromptTemplateConfig(
    name="t",
    template="Hello {{$name}}!",
    template_format="semantic-kernel",
    input_variables=[{"name": "name", "description": "who", "default": "STRANGER"}],
)
tpl = KernelPromptTemplate(prompt_template_config=cfg)
print(repr(asyncio.run(tpl.render(Kernel()))))  # 'Hello !'  -- expected 'Hello STRANGER!'

Expected behavior

A declared default fills in when the caller did not supply the variable; an explicit argument still wins.

Environment

semantic-kernel python 1.44.1, pydantic v2

ManoharPaturi avatar Sep 18 '26 11:09 ManoharPaturi