microsoft / microsoft/semantic-kernel

Python: input_variables default values are never applied when rendering templates

Open
#14,458 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

python triage
Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
14h 13m
Merged PRs (30d)
18

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with KernelPromptTemplate.render and VarBlock.render, then inspect PromptTemplateConfig.input_variables and get_kernel_parameter_metadata. Reproduce the example with a missing name and with an explicit argument; done means the declared default appears only when the caller omits the variable, while the explicit value still wins.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.