Skip to content

Python: fix(prompt-template): pass positional helper arguments to kernel functions - #14664

Open
Chen Yufeiyang (feiiiiii5) wants to merge 1 commit into
microsoft:mainfrom
feiiiiii5:semantic-kernel-A-257
Open

Chen Yufeiyang (feiiiiii5) wants to merge 1 commit into
microsoft:mainfrom
feiiiiii5:semantic-kernel-A-257

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Motivation and Context

The template helper created by create_template_helper_from_function computes the positional arguments passed by Jinja2 or Handlebars, but only merges keyword arguments into KernelArguments. 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 raise FunctionExecutionException instead 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 483ffb4 with the default values/no exception and pass on this branch. tests/unit/prompt_template, tests/unit/contents, tests/unit/template_engine, and tests/unit/text exit 0; ruff check and ruff format --check are clean.

Contribution Checklist

  • The code builds clean without errors or warnings in the targeted suites.
  • The PR follows the SK contribution guidelines; ruff check/format pass on the two changed files.
  • All targeted unit tests pass, and regression tests were added.
  • Named and keyword arguments keep their existing precedence; varargs are not specially supported.

…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.
@feiiiiii5
Chen Yufeiyang (feiiiiii5) requested a review from a team as a code owner October 26, 2026 07:04
Copilot AI balanced review requested due to automatic review settings October 26, 2026 07:04
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 26, 2026
@github-actions github-actions Bot changed the title fix(prompt-template): pass positional helper arguments to kernel functions Python: fix(prompt-template): pass positional helper arguments to kernel functions Oct 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

1 active deployment
github-app-auth — e309288e Deployed Oct 26, 2026 by feiiiiii5 via add_label #29443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants