mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context See [ADR](https://github.com/microsoft/semantic-kernel/pull/5866/files?short_path=7baf347#diff-7baf34730c3b1a98278bac7036172bd99f82a8f8484e696c42e0a15042200ecb) Closes #5699 ### Description To revert to the old (less safe) behavior you can create a `KernelPromptTemplateFactory` and set `AllowUnsafeContent = true` and then all prompt templates will trusted all inserted content. This approach is not recommended unless you are sure that inserted content comes from a trusted source. Here is an example: ```csharp private async Task ExampleTrustedTemplateAsync(Kernel kernel) { KernelFunction trustedMessageFunction = KernelFunctionFactory.CreateFromMethod(() => "<message role=\"system\">You are a helpful assistant who knows all about cities in the USA</message>", "TrustedMessageFunction"); KernelFunction trustedContentFunction = KernelFunctionFactory.CreateFromMethod(() => "<text>What is Seattle?</text>", "TrustedContentFunction"); kernel.ImportPluginFromFunctions("TrustedPlugin", [trustedMessageFunction, trustedContentFunction]); var chatPrompt = @" {{TrustedPlugin.TrustedMessageFunction}} <message role=""user"">{{$input}}</message> <message role=""user"">{{TrustedPlugin.TrustedContentFunction}}</message> "; var promptConfig = new PromptTemplateConfig(chatPrompt); var kernelArguments = new KernelArguments() { ["input"] = "<text>What is Washington?</text>", }; var factory = new KernelPromptTemplateFactory() { AllowUnsafeContent = true }; var function = KernelFunctionFactory.CreateFromPrompt(promptConfig, factory); WriteLine(await RenderPromptAsync(promptConfig, kernel, kernelArguments, factory)); WriteLine(await kernel.InvokeAsync(function, kernelArguments)); } ``` ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Daniel Gonzalez <[email protected]>