Skip to content

Python: Reject bytes in prompt template argument encoding - #14669

Open
Eduard van Valkenburg (eavanvalkenburg) wants to merge 1 commit into
microsoft:mainfrom
eavanvalkenburg:validate-bytes-template-safety
Open

Eduard van Valkenburg (eavanvalkenburg) wants to merge 1 commit into
microsoft:mainfrom
eavanvalkenburg:validate-bytes-template-safety

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation and Context

Prompt template argument encoding supports text and a set of scalar values. bytes values do not have an implicit text encoding and currently render using their Python representation. This change uses the existing unsupported-value path so callers must decode or otherwise handle byte content explicitly.

Description

  • Remove bytes from the primitive types accepted by automatic prompt argument encoding.
  • Add parameterized regression coverage for Semantic Kernel, Jinja2, and Handlebars templates.
  • Verify strings remain encoded as a single message and integer rendering is unchanged.

Callers that currently pass bytes with default content handling will now receive the existing NotImplementedError. Textual byte content should be decoded with the intended encoding before rendering.

Validation:

  • cd python && uv run --python 3.12 --frozen pre-commit run -a — passed.
  • cd python && uv run --python 3.12 --frozen pytest tests/unit/prompt_template -q — passed.
  • cd python && uv run --python 3.12 --frozen pytest tests/unit --ignore=tests/unit/processes/dapr_runtime -q — passed.
  • cd python && uv run --python 3.12 --frozen pytest tests/unit/processes/dapr_runtime -q — passed after installing the Dapr FastAPI and Flask test extras in the local uv environment.

Contribution Checklist

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

🟢 Approval recommended

The narrow change matches the intended behavior and includes targeted regression coverage with no unresolved issues.

No open issues 🎉

What changed in this PR

This PR makes Python prompt argument encoding reject bytes, requiring callers to decode byte content explicitly before rendering.

Changes:

  • Remove bytes from the primitive types accepted by automatic encoding.
  • Add regression coverage across Semantic Kernel, Jinja2, and Handlebars templates.
  • Verify decoded strings remain a single user message and integer rendering is unchanged.
File Description
python/​tests/​unit/​prompt_template/​test_prompt_template_e2e.py Test byte rejection and preserved string and integer behavior across three engines.
python/​semantic_kernel/​prompt_template/​prompt_template_base.py Route byte arguments through existing unsupported-value handling.

Review effort: Balanced

This branch was successfully deployed

1 active deployment
github-app-auth — 5a3263d6 Deployed Oct 27, 2026 by eavanvalkenburg via add_label #29467
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.

3 participants