microsoft / microsoft/semantic-kernel
Python: input_variables default values are never applied when rendering templates
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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