Skip to content

Conversation

@sbroenne
Copy link

Summary

Fix JSON Schema type handling for nullable types in Google AI and Vertex AI integrations.

Discovery Context

This issue was discovered while running agent-benchmark tests against the Windows MCP Server using Gemini 2.5 Pro via Vertex AI. The MCP SDK generates JSON schemas with nullable types (["string", "null"]) for optional parameters, which caused tool calls to fail.

Problem

When tool parameters use nullable types per JSON Schema spec:

{ "type": ["string", "null"] }

The integrations fail with:

tool [0], property [fieldName]: expected string for type, got []interface {}

JSON Schema Spec Reference

Per JSON Schema specification:

"The type keyword may be either a string or an array... An array of strings allows matching against more than one type."

Solution

Added normalizeSchemaType() function that handles both forms:

  • String: "string""string"
  • Array: ["string", "null"]"string" (extracts first non-null type)

Testing

  • Added comprehensive unit tests for normalizeSchemaType()
  • Added integration tests for nullable types at all nesting levels (single-level, nested objects, array items, deeply nested)
  • All existing tests pass
  • Verified with real Vertex AI API calls using agent-benchmark

Files Changed

  • llms/googleai/googleai.go - Added normalizeSchemaType() function and updated convertSchemaRecursive()
  • llms/googleai/googleai_unit_test.go - Added tests for normalizeSchemaType() and nullable tool parameters
  • llms/googleai/vertex/vertex.go - Added normalizeSchemaType() function and updated convertTools()
  • llms/googleai/vertex/vertex_unit_test.go - Added tests for normalizeSchemaType() and nullable tool parameters

Fix JSON Schema type handling for nullable types in Google AI and Vertex AI
integrations. Per JSON Schema specification, the type keyword may be an
array to allow multiple types (e.g., ['string', 'null'] for nullable fields).

Problem:
When tool parameters use nullable types, the integrations fail with:
  tool [0], property [fieldName]: expected string for type, got []interface {}

Solution:
Added normalizeSchemaType() function that handles both forms:
- String: 'string' -> 'string'
- Array: ['string', 'null'] -> 'string' (extracts first non-null type)

Discovery context:
This issue was discovered while running agent-benchmark tests against the
Windows MCP Server using Gemini 2.5 Pro via Vertex AI. The MCP SDK generates
JSON schemas with nullable types for optional parameters.

JSON Schema Spec Reference:
https://json-schema.org/understanding-json-schema/reference/type

Testing:
- Added comprehensive unit tests for normalizeSchemaType()
- Added integration tests for nullable types at all nesting levels
- Verified with real Vertex AI API calls
@sbroenne sbroenne changed the title llms/googleai: handle nullable JSON Schema types in tool parameters fix: llms/googleai - handle nullable JSON Schema types in tool parameters Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant