Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Unsafe input handling #6003

Merged
merged 22 commits into from
May 16, 2024

Conversation

eavanvalkenburg
Copy link
Member

@eavanvalkenburg eavanvalkenburg commented Apr 25, 2024

Motivation and Context

Implements dealing with unsafe content, by doing HTML parsing on variables and function results.

Closes: #5889

Description

Adds parameter allow_dangerously_set_content to:

  • InputVariable
  • PromptTemplateConfig
  • PromptTemplateBase

The behavior is that if the flag is set to True on the template itself (KernelPromptTemplate, Jinja2PromptTemplate or HandlebarsPromptTemplate) the behavior is the same, no encoding is done on inputs.

Otherwise:

  • variables are encoded by default, this can be switched off using the InputVariables class for that variable.
  • function output is encoded by default, this can be switched off using the flag in the PromptTemplateConfig, this is not yet possible to do on a per function basis.

Contribution Checklist

@eavanvalkenburg eavanvalkenburg requested a review from a team as a code owner April 25, 2024 12:47
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Apr 25, 2024
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Apr 25, 2024

Py3.10 Test Coverage

Python 3.10 Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel
   kernel.py3145782%123, 125, 183–186, 188–192, 194–197, 204, 211–220, 257–260, 270–275, 280, 284–287, 380–416, 535–536, 763, 784–786, 822, 824, 834
semantic_kernel/contents
   streaming_chat_message_content.py84298%193–194
   text_content.py22291%40, 47
semantic_kernel/functions
   kernel_function.py73297%142, 161
   kernel_function_from_prompt.py163597%171, 197, 294, 310, 364
semantic_kernel/planners/sequential_planner
   sequential_planner.py65691%69, 73, 104, 120, 129–130
semantic_kernel/prompt_template
   jinja2_prompt_template.py44393%62–64
   kernel_prompt_template.py85396%119–121
   prompt_template_config.py51688%39, 47, 68, 73–74, 82
semantic_kernel/prompt_template/utils
   handlebars_system_helpers.py93397%16, 43–44
   jinja2_system_helpers.py48394%15, 45, 50
semantic_kernel/template_engine/blocks
   code_block.py70199%130
TOTAL6089106183% 

Python 3.10 Unit Test Overview

Tests Skipped Failures Errors Time
1278 1 💤 0 ❌ 0 🔥 14.816s ⏱️

@eavanvalkenburg eavanvalkenburg marked this pull request as draft April 25, 2024 14:04
@eavanvalkenburg eavanvalkenburg marked this pull request as ready for review May 13, 2024 11:18
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 16, 2024
Merged via the queue into microsoft:main with commit 08bcc80 May 16, 2024
25 checks passed
@eavanvalkenburg eavanvalkenburg deleted the unsafe_input branch May 16, 2024 13:12
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.

Python: Support XML tags in Chat Prompts
3 participants