Skip to content

Python: Fix Handlebars messages helper ignoring its argument - #14537

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
VANDRANKI:fix/handlebars-messages-helper-arg
Nov 2, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
VANDRANKI:fix/handlebars-messages-helper-arg

Conversation

@VANDRANKI

Copy link
Copy Markdown
Contributor

Motivation and Context

The Handlebars messages helper ignores its argument. {{messages my_history}} always reads chat_history from the context, so it raises KeyError when that variable is missing and renders the wrong history when both exist. The Jinja2 messages(history) helper uses its argument.

Fixes #14535

Description

_messages in handlebars_system_helpers.py now uses the first positional argument. If no argument is given it falls back to the chat_history context variable, so existing {{messages chat_history}} templates behave the same. The unused options parameter was removed. For a non-block helper pybars passes the first argument in that slot, which is why the argument was never visible. A bare {{messages}} used to raise TypeError and now works through the fallback.

Added two tests (argument with a different variable name, and argument preferred over a chat_history variable). Both fail on main. tests/unit/prompt_template, tests/unit/kernel and tests/unit/functions pass. ruff check clean on the touched files, mypy clean on the helper module.

Contribution Checklist

Copilot AI balanced review requested due to automatic review settings October 4, 2026 20:21
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 4, 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.

Copilot review overview

🟡 Changes recommended

The newly introduced no-argument fallback lacks integration coverage.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Fixes the Handlebars messages helper to honor its argument while retaining context fallback behavior.

Changes:

  • Uses the first helper argument when provided.
  • Adds regression tests for argument selection.
File Description
handlebars_system_helpers.py Corrects chat-history resolution.
test_handlebars_prompt_template.py Tests explicit argument handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Merged via the queue into microsoft:main with commit b4c5b83 Nov 2, 2026
57 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — b5adc4a1 Deployed Oct 4, 2026 by VANDRANKI via add_label #29240
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.

Python: Handlebars messages helper ignores its argument and always reads chat_history from the context

3 participants