Skip to content

Python: Avoid logging function argument values - #14574

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
eavanvalkenburg:sensitive-function-logging
Oct 12, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
eavanvalkenburg:sensitive-function-logging

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Motivation and Context

Function invocation diagnostics currently include complete argument, result, or exception values at INFO, DEBUG, or ERROR level. This change keeps invocation diagnostics useful while avoiding recording those values in ordinary application logs or non-sensitive function spans.

Description

  • Log automatic function identity at INFO without argument values.
  • Log argument counts, result presence, and error type instead of function values.
  • Keep raw exception details in function spans only when sensitive diagnostics are explicitly enabled.
  • Add focused regression coverage for automatic invocation, direct and streaming function invocation, and synchronous/asynchronous template helpers.

Validation:

  • uv build --out-dir /tmp/semantic-kernel-pr-review-build — passed; built the source distribution and wheel.
  • uv run pre-commit run --files semantic_kernel/kernel.py semantic_kernel/functions/kernel_function.py semantic_kernel/functions/kernel_function_log_messages.py semantic_kernel/prompt_template/utils/template_function_helpers.py semantic_kernel/utils/telemetry/model_diagnostics/function_tracer.py tests/unit/kernel/test_kernel.py tests/unit/functions/test_kernel_function_from_method.py tests/unit/prompt_template/test_template_helper.py — passed all applicable hooks.
  • uv run pytest tests/unit/kernel/test_kernel.py tests/unit/functions/test_kernel_function_from_method.py tests/unit/prompt_template/test_template_helper.py — 132 passed.
  • uv run pytest tests/unit/utils/model_diagnostics/test_trace_chat_completion.py tests/unit/utils/model_diagnostics/test_trace_streaming_chat_completion.py tests/unit/utils/model_diagnostics/test_trace_text_completion.py tests/unit/utils/model_diagnostics/test_trace_streaming_text_completion.py — 28 passed.

The full unit-test suite was not run locally; the targeted files cover each changed logging and tracing path.

Contribution Checklist

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

Sensitive argument values are removed with focused regression coverage; only minor message grammar remains.

1 open finding
What changed in this PR

Removes function argument values from Python logs while preserving useful invocation diagnostics.

Changes:

  • Replaces argument values with names/counts in invocation logs.
  • Adds regression coverage across automatic, direct, and template invocations.
File Description
python/​semantic_kernel/​kernel.py Removes automatic-call arguments from INFO logs.
python/​semantic_kernel/​functions/​kernel_function_log_messages.py Logs argument counts instead of values.
python/​semantic_kernel/​prompt_template/​utils/​template_function_helpers.py Replaces template values with invocation counts.
python/​tests/​unit/​kernel/​test_kernel.py Tests automatic invocation logging.
python/​tests/​unit/​functions/​test_kernel_function_from_method.py Tests direct invocation logging.
python/​tests/​unit/​prompt_template/​test_template_helper.py Tests synchronous/asynchronous template logging.

🧠 Review effort: Balanced


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

Comment thread python/semantic_kernel/prompt_template/utils/template_function_helpers.py Outdated
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
kernel.py2365277%149, 160, 164, 320–321, 323, 412, 418–419, 423–424, 487, 501–510, 512, 514–515, 517–537, 539–544
functions
   kernel_function.py2085275%111, 113, 284–288, 341, 367–372, 433, 435, 437, 439–440, 442–443, 447–455, 459–460, 462–480, 482
   kernel_function_log_messages.py33196%40
prompt_template/utils
   template_function_helpers.py510100% 
utils/telemetry/model_diagnostics
   function_tracer.py180100% 
TOTAL29124546481% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4483 22 💤 0 ❌ 0 🔥 2m 10s ⏱️

@semantic-kernel-automation semantic-kernel-automation Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MAF Automated Review — Iteration 1

Result: No findings
Scope: full PR (1 commit(s)): 3e5773ad4a0f
Model: gpt-5.6-sol

Overview

The PR replaces argument-bearing invocation logs with function identity and argument-count diagnostics across direct, automatic, and template invocation paths. The shared direct-invocation helper also covers streaming calls, sensitive tracing remains explicitly gated, and focused tests verify that sentinel values do not reach the changed loggers. No Critical, High, or Medium defect introduced by the reviewed diff was established.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

@jpalvarezl Jose Alvarez (jpalvarezl) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two privacy paths remain in the shared invocation layer: successful return values can echo arguments into DEBUG logs, and failure messages can expose them through ERROR logs and non-sensitive OpenTelemetry spans.

Comment thread python/semantic_kernel/functions/kernel_function_log_messages.py
Comment thread python/semantic_kernel/kernel.py

@jpalvarezl Jose Alvarez (jpalvarezl) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both privacy findings are resolved. Successful invocation diagnostics no longer serialize result values, including direct, automatic, and template paths. Failure diagnostics now keep raw exception text out of ordinary ERROR logs and non-sensitive spans across streaming and non-streaming invocation, while preserving exception details when sensitive diagnostics are explicitly enabled. The added regression coverage exercises those paths, and the current Python CI matrix is green.

Merged via the queue into microsoft:main with commit 1b1f64b Oct 12, 2026
32 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the sensitive-function-logging branch October 12, 2026 11:16

This branch was previously deployed

1 inactive deployment
github-app-auth — 16cef897 Deployed Oct 12, 2026 by eavanvalkenburg via add_label #29322
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