Skip to content

Python: docs(python): clarify prompt template trust boundary - #14648

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
mainfrom
sk-template-safety
Oct 23, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
mainfrom
sk-template-safety

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation and Context

Semantic Kernel prompt template source can invoke functions registered in the Kernel during rendering, but this executable-configuration trust boundary was not explicit. This change documents the supported safe pattern for handling untrusted user-, network-, file-, or service-provided text without changing existing template behavior.

Description

  • Document that template source must be trusted because function expressions execute before the model request.
  • Clarify that untrusted text should be passed through template arguments and that content-escaping settings do not disable template function execution.
  • Add a regression test proving template-like syntax supplied as an argument is rendered literally and does not invoke a registered plugin function.
  • Preserve compatibility: no runtime behavior or defaults change.

Validation:

  • uv run --python 3.12 --frozen pytest tests\unit\prompt_template\test_kernel_prompt_template.py --quiet — passed (10 tests).
  • uv run --python 3.12 --frozen ruff check semantic_kernel\agents\agent.py semantic_kernel\prompt_template\kernel_prompt_template.py tests\unit\prompt_template\test_kernel_prompt_template.py — passed.
  • uv run --python 3.12 --frozen pre-commit run -a — not completed; stopped during first-time hook environment installation to avoid delaying PR creation.

Contribution Checklist

Document that template source can invoke registered kernel functions and add a regression test showing template-like argument values remain literal.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 12:53
@semantic-kernel-automation semantic-kernel-automation Bot added python Pull requests for the Python Semantic Kernel documentation labels Oct 23, 2026
@github-actions github-actions Bot changed the title docs(python): clarify prompt template trust boundary Python: docs(python): clarify prompt template trust boundary Oct 23, 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 documentation and focused regression test clarify existing behavior without runtime changes, and no unresolved issues were identified.

No open issues 🎉

What changed in this PR

Clarifies the Python prompt template trust boundary and documents how to pass untrusted text safely, without changing runtime behavior or defaults.

Changes:

  • Documents that trusted template source can invoke registered functions during rendering.
  • Explains that untrusted text belongs in template arguments and that content escaping does not prevent template function execution.
  • Adds a regression test confirming template syntax in argument values remains literal and does not invoke functions.
File Description
python/​tests/​unit/​prompt_template/​test_kernel_prompt_template.py Tests literal rendering of template syntax supplied through arguments.
python/​semantic_kernel/​template_engine/​README.md Adds security guidance and a safe argument-passing example.
python/​semantic_kernel/​prompt_template/​kernel_prompt_template.py Documents the template source trust requirement in the class docstring.
python/​semantic_kernel/​agents/​agent.py Clarifies the trust requirement for agent instruction templates.

Review effort: Balanced

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
agents
   agent.py3424885%123, 130, 143–144, 147–149, 152–154, 163, 205, 210, 215, 220, 225, 229, 233, 237, 279–281, 309–310, 312, 316, 436, 438, 503, 517, 610, 624, 637, 689, 696–697, 700–701, 720, 767, 824, 909–910, 912–913, 967, 1038, 1053
prompt_template
   kernel_prompt_template.py78791%148–149, 151–155
TOTAL29159546481% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4518 22 💤 0 ❌ 0 🔥 2m 16s ⏱️

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch was previously deployed

2 inactive deployments
github-app-auth — ed93d445 Deployed Oct 23, 2026 by eavanvalkenburg via add_label #29426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants