semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Python: Unsafe input handling

Open eavanvalkenburg opened this issue 1 year ago • 1 comments

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 avatar Apr 25 '24 12:04 eavanvalkenburg

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 :zzz: 0 :x: 0 :fire: 14.816s :stopwatch:

markwallace-microsoft avatar Apr 25 '24 12:04 markwallace-microsoft