Python: Fix non-string KernelArguments type preservation in prompt template function parameters #13220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #[issue_number] - This PR resolves an issue where non-string
KernelArgumentswere being incorrectly converted to strings when passed as function parameters in prompt templates, causing type-related errors.Problem
When using function calls in Semantic Kernel Prompt Templates with injected
KernelArguments, all argument values were being converted to strings viaVarBlock.render()before being passed to functions. This caused issues when functions expected non-string types:Solution
Made minimal changes to preserve argument types when passing to functions:
named_arg_block.py: ModifiedNamedArgBlock.render()to return the actual value fromKernelArgumentsinstead of the string representation for variable references. This preserves types for named arguments likearg=$var.code_block.py: Updated_enrich_function_arguments()to handleVarBlockpositional arguments by directly retrieving values fromKernelArguments. This preserves types for positional arguments like$var.The fix ensures that:
$myvar) render as strings when used directly in outputarg=$var) and positional ($var) argument styles work correctlyType Coverage
Now properly supports:
Testing
test_non_string_arguments.py) with 10 test casesBreaking Changes
None - this fix is fully backward compatible. String arguments continue to work as before.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.