Skip to content

Python: keep a streamed '{}' delta when combining function call arguments - #14513

Open
PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 3 commits into
microsoft:mainfrom
VANDRANKI:fix/function-call-combine-empty-object
Open

PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 3 commits into
microsoft:mainfrom
VANDRANKI:fix/function-call-combine-empty-object

Conversation

@VANDRANKI

Copy link
Copy Markdown
Contributor

Motivation and Context

FunctionCallContent.combine_arguments treated any "{}" string as an empty placeholder and dropped it. When a provider streams the arguments as raw token deltas and one delta is exactly {}, that delta is lost and the accumulated string is invalid JSON. For example {"query":"x","filters": + {} + } became {"query":"x","filters":}, and parse_arguments() then raised FunctionCallInvalidArgumentsException on a call the model produced correctly.

Fixes #14512

Description

"{}" is no longer in EMPTY_VALUES. Only "" and None are always treated as empty. The "{}" placeholder behavior the old code was written for is kept in the two places it makes sense:

  • If the accumulated first side is exactly "{}", it is a finished empty object, so the second side replaces it (same as before).
  • If the second side is "{}" and the first side already parses as a complete JSON object, it is dropped (same as before).

In every other case, including a "{}" delta after a partial JSON string, the deltas are concatenated as plain text.

Tests added in tests/unit/contents/test_function_call_content.py: the three delta splits from the issue (they fail on current main and pass now) and the trailing-placeholder case. The existing test_add_empty cases still pass.

tests/unit/contents and tests/unit/connectors/ai/test_function_choice_behavior.py: 429 passed. ruff format and mypy are clean on the changed file.

Contribution Checklist

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Complete single-quoted objects followed by a placeholder now regress to invalid arguments.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates streamed function-call argument merging so {} deltas are preserved when part of incomplete JSON.

Changes:

  • Refines empty-placeholder handling.
  • Adds streamed-delta and trailing-placeholder tests.
File Description
python/​semantic_kernel/​contents/​function_call_content.py Adds context-aware {} handling.
python/​tests/​unit/​contents/​test_function_call_content.py Covers streamed empty-object deltas.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@VANDRANKI

Copy link
Copy Markdown
Contributor Author

The Copilot finding was right. _is_complete_object only tried plain json.loads, so {'input': 'world'} followed by a trailing {} was treated as incomplete and ended up as {'input': 'world'}{}, which cannot be parsed.

Fixed in 0487868. _is_complete_object now falls back to the same single quote preprocessing that parse_arguments uses, so the trailing {} placeholder is dropped as before. Added test_add_trailing_empty_placeholder_after_single_quoted_object, which fails without the change and passes with it. tests/unit/contents passes, and ruff and mypy are clean on the touched files.

@eavanvalkenburg

Eduard van Valkenburg (eavanvalkenburg) commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

The streaming fix and single-quote compatibility regression pass review. The remaining merge blocker is fresh required validation: the old Merge Gatekeeper, Spell Check, and .NET runs failed before producing checks. Those runs were created on October 1 and are beyond GitHub's rerun limit. Please update/rebase onto current main so fresh workflows can run.

@VANDRANKI

Copy link
Copy Markdown
Contributor Author

I updated this branch with current main (df1cb33). I merged main in instead of force pushing, so the new head 594679a is a normal merge commit. There were no conflicts and the PR diff is unchanged: 2 files, 56 lines added, 1 removed.

On the pushed commit, tests/unit/contents and tests/unit/connectors/ai/test_function_choice_behavior.py give 474 passed. With function_call_content.py taken back to the main version, the 3 streamed {} delta tests in test_function_call_content.py fail.

The new workflow runs for 594679a show action_required, so a maintainer needs to approve them before they start.

This branch was previously deployed

1 inactive deployment
github-app-auth — 594679ab Deployed Nov 6, 2026 by VANDRANKI via add_label #29608
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: FunctionCallContent.combine_arguments drops a streamed "{}" chunk, producing invalid JSON arguments

3 participants