Python: fix Google AI/Vertex AI crash on anyOf schema (#12442) by weiguangli-io · Pull Request #13624 · microsoft/semantic-kernel

@moonbox3 moonbox3 added the python

Pull requests for the Python Semantic Kernel

label

Mar 2, 2026

moonbox3

…t#12442)

The Google AI protobuf Schema does not support anyOf/oneOf fields or
type-as-array. When ChatCompletionAgent instances are used as plugins,
their parameter schemas (e.g. str | list[str]) include anyOf which
causes ValueError during protobuf conversion.

Add sanitize_schema_for_google_ai() to shared_utils that recursively
rewrites anyOf/oneOf/type-array into nullable + single-type format.
Apply it in both Google AI and Vertex AI function call format converters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rams, add integration tests

- Add "allOf" to the sanitizer loop alongside anyOf/oneOf so allOf
  schemas are handled instead of passing through unsanitized
- Guard Vertex AI parameters construction when metadata.parameters is
  empty, aligning behavior with the Google AI version
- Add allOf unit tests (with and without null variants)
- Add edge-case tests: all-null type list, all-null anyOf, variant
  with its own description
- Add integration tests for both Google AI and Vertex AI format
  functions to prove end-to-end sanitization
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Capitalize first word of docstrings (D403): anyOf->AnyOf, oneOf->OneOf, allOf->AllOf
- Add missing docstrings to test_sanitize_schema_none and test_sanitize_schema_simple_passthrough (D103)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix type checking error where param.name could be None when used as
dict key. Added None checks before using param.name in both Google AI
and Vertex AI utils to satisfy mypy strict type requirements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@moonbox3

moonbox3

@moonbox3