Repository navigation
Python: fix(prompt-template): pass positional helper arguments to kernel functions - #14664
Open
Chen Yufeiyang (feiiiiii5) wants to merge 1 commit into
Open
Chen Yufeiyang (feiiiiii5) wants to merge 1 commit into
Chen Yufeiyang (feiiiiii5) wants to merge 1 commit into
Conversation
…tions The helper computed the positional arguments from the template but only merged kwargs into KernelArguments, so positional values were dropped and defaults won. Map them to the function's template-facing parameters, skip kernel-injected parameters, and reject excess arguments.
Chen Yufeiyang (feiiiiii5)
deployed
to
github-app-auth
October 26, 2026 07:04 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The injected-name filter excludes valid prompt-function inputs, causing incorrect argument binding or rejected calls.
1 open issue
What changed in this PR
This PR enables positional arguments in Python template helpers so Jinja2 and Handlebars calls pass supplied values to kernel functions.
Changes:
- Maps positional arguments to declared parameters before applying keyword overrides.
- Skips kernel-injected parameters and rejects excess positional arguments.
- Adds regression tests for synchronous and asynchronous helpers, Handlebars context handling, and injected parameters.
| File | Description |
|---|---|
python/tests/unit/prompt_template/test_template_helper.py |
Adds positional-argument regression coverage. |
python/semantic_kernel/prompt_template/utils/template_function_helpers.py |
Maps and validates positional arguments in template helpers. |
Review effort: Balanced
| parameter_names = [ | ||
| parameter.name | ||
| for parameter in function.parameters | ||
| if parameter.name is not None and parameter.name not in _INJECTED_FUNCTION_PARAMETER_NAMES |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation and Context
The template helper created by
create_template_helper_from_functioncomputes the positional arguments passed by Jinja2 or Handlebars, but only merges keyword arguments intoKernelArguments. A call such as{{ p_greet('Ada', '?') }}therefore invokes the function with its defaults (Hello, world!) or fails with “parameter is required” even though the template supplied the values. ADR 0023 requires Handlebars kernel-function helpers to support positional arguments.Description
Positional arguments are mapped to the function's template-facing parameters in declaration order before invocation. Parameters injected by the kernel (
kernel,service,execution_settings,arguments) are skipped, and too many positional arguments raiseFunctionExecutionExceptioninstead of being silently ignored. Keyword arguments still override positional ones.Tests cover sync Jinja2, sync Handlebars (including the leading context argument), async Jinja2, too many arguments, and a function with a kernel-injected parameter. The five new cases fail on
483ffb4with the default values/no exception and pass on this branch.tests/unit/prompt_template,tests/unit/contents,tests/unit/template_engine, andtests/unit/textexit 0;ruff checkandruff format --checkare clean.Contribution Checklist