Repository navigation
Commit ce34fdb
authored
Python: Reject bytes in prompt template argument encoding (#14669)
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
1. Why is this change required?
2. What problem does it solve?
3. What scenario does it contribute to?
4. If it fixes an open issue, please link to the issue here.
-->
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
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
- 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
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄1 parent a4db76e commit ce34fdb
2 files changed
Lines changed: 41 additions & 1 deletion
File tree
- python
- semantic_kernel/prompt_template
- tests/unit/prompt_template
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
239 | 241 | | |
240 | 242 | | |
241 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
242 | 282 | | |
243 | 283 | | |
244 | 284 | | |
| |||
0 commit comments