Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test lacks empty-list and empty-dictionary cases, leaving the new guards unprotected against regressions that could reintroduce FunctionResultError for empty containers.
1 open issue
What changed in this PR
Fixes Python FunctionResult.__str__ so valid falsy results remain visible when kernel function results are converted to text.
Changes:
- Preserves string representations of
0,False, and0.0. - Keeps empty-string behavior for
None, empty lists, and empty dictionaries. - Adds parameterized regression tests for falsy scalar values.
| File | Description |
|---|---|
python/tests/unit/functions/test_function_result.py |
Adds falsy-value string conversion tests. |
python/semantic_kernel/functions/function_result.py |
Replaces the truthiness guard with explicit handling of None and empty containers. |
Review effort: Balanced
| assert str(result) == "" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize(("value", "expected"), [(0, "0"), (False, "False"), (0.0, "0.0"), ("", "")]) |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Problem
FunctionResult.__str__wraps the whole conversion inif self.value:, so any falsy but validresult is turned into an empty string. A kernel function that legitimately returns
0(a count),
False(a predicate) or0.0therefore stringifies to"":This is silent data loss on the public invoke path: prompt rendering,
semantic_kernel.text.aggregate_chunked_resultsand any host that turns a
FunctionResultinto text all see an empty string instead of the value.The method's own docstring says it calls
str()on the value, and the prompt template engine alreadyrenders
0/Falsecorrectly for plain variables, so a function result was the only place where azero disappeared.
Fix
Special-case only
None(which is legitimately empty). The list and dict branches stay as they were,except that empty containers keep returning
""instead of raisingIndexErroronself.value[0],which the old
if self.value:guard was also covering.Tests
New test
test_function_result_str_keeps_falsy_valuesinpython/tests/unit/functions/test_function_result.py,parametrized over
0,False,0.0and""; the existingtest_function_result_str_empty_valuestill covers the
Nonecase, andtest_function_result_str_with_conversion_errorstill covers theFunctionResultErrorpath.Measured counts (Python 3.13, offline):
pytest tests/unit/functions/test_function_result.py-> 13 passedpytest tests/unit/functions(excludingtest_kernel_plugins.py) -> 197 passedpytest tests/unit/contents-> 438 passedtests/unit/functions/test_kernel_plugins.pyreports 31 passed, 3 failed both before and after thischange; the 3 failures are a pre-existing
ImportError: cannot import name 'Spec' from 'openapi_core'from the locally installed
openapi_coreversion and are unrelated to this patch.