Skip to content

Python: Convert nested SDK models in hosted tool sanitization - #9789

Open
Dhruv Shaswat (Dhruv-Sh-git) wants to merge 1 commit into
microsoft:mainfrom
Dhruv-Sh-git:fix/issue-9784
Open

Dhruv Shaswat (Dhruv-Sh-git) wants to merge 1 commit into
microsoft:mainfrom
Dhruv-Sh-git:fix/issue-9784

Conversation

@Dhruv-Sh-git

@Dhruv-Sh-git Dhruv Shaswat (Dhruv-Sh-git) commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes #9784.

Summary

Passing tools returned by FoundryChatClient.get_bing_custom_search_tool() or FoundryChatClient.get_code_interpreter_tool() directly to an agent or _prepare_tools_for_openai() could fail during JSON serialization with a TypeError.
The issue was that _sanitize_foundry_response_tool() only made a shallow copy of the tool mapping. Nested Azure SDK models were left unchanged, so they couldn't be serialized as JSON.

Changes

  • Updated _tools.py to recursively convert nested SDK models into plain Python data using their .as_dict() representation, including values inside mappings and sequences.
  • Added regression tests in test_foundry_chat_client.py for both Bing custom search and code interpreter tools, checking that they produce valid JSON payloads through _prepare_tools_for_openai().

Testing

Validated locally with Ruff and pytest: 464 tests passed in packages/foundry.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:32

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 was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch was previously deployed

1 inactive deployment
github-app-auth — f2ebec82 Deployed Oct 28, 2026 by Dhruv-Sh-git via team_check #7860
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: FoundryChatClient: hosted tools from get_bing_custom_search_tool() fail JSON serialization (nested SDK models not converted)

2 participants