Skip to content

Python: input_variables default values are never applied when rendering templates #14458

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonPull requests for the Python Semantic Kerneltriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions