Skip to content

[Platform][VertexAi] Normalize nullable fields in structured output schema - #2398

Merged
chr-hertel merged 1 commit into
symfony:mainfrom
ousamabenyounes:fix/issue-1999
Sep 22, 2026
Merged

chr-hertel merged 1 commit into
symfony:mainfrom
ousamabenyounes:fix/issue-1999

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #1999
License MIT

Problem

Using structured output with the Vertex/Gemini bridge throws as soon as a DTO property is nullable:

Error from Gemini API: "Invalid JSON payload received. Unknown name "type" at
'generation_config.response_schema.properties[0].value.items.properties[5].value':
Proto field is not repeating, cannot start list."

The JSON Schema factory represents a nullable field with an array-style type ("type": ["string", "null"]). VertexAI's OpenAPI-flavored schema parser does not accept an array there — it requires a single type plus "nullable": true.

Contract\ToolNormalizer already performed this conversion for tool parameter schemas, but the structured-output responseSchema in Gemini\ModelClient was assigned straight from the response_format payload without any normalization, so nullable fields broke.

Fix

  • Extract the nullable-array → nullable: true conversion (and the additionalProperties stripping) from ToolNormalizer into a shared SchemaNormalizer.
  • ToolNormalizer now delegates to it (identical behavior, no duplicated logic).
  • Gemini\ModelClient runs the structured-output responseSchema through the same normalizer, so tool and response schemas stay in sync.

Test verification (RED → GREEN)

New test testItNormalizesNullableFieldsInStructuredOutputResponseSchema asserts the wire responseSchema has a single type + nullable: true (top-level and nested items) and no additionalProperties.

On the unmodified branch (RED):

1) ...VertexAi\Tests\Gemini\ModelClientTest::testItNormalizesNullableFieldsInStructuredOutputResponseSchema
Failed asserting that Array &0 [
    0 => 'string',
    1 => 'null',
] is identical to 'string'.
FAILURES! Tests: 1, Assertions: 2, Failures: 1.

With the fix (GREEN), the whole VertexAi bridge suite (including the existing ToolNormalizer nullable tests, proving behavior parity after the extraction):

OK (109 tests, 457 assertions)

PHPStan and PHP-CS-Fixer are clean on the changed files.

@carsonbot carsonbot added Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Needs Review labels Aug 11, 2026
Comment thread src/platform/src/Bridge/VertexAi/SchemaNormalizer.php

@chr-hertel chr-hertel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reproduced issue and confirmed as fix!

Comment thread src/platform/src/Bridge/VertexAi/SchemaNormalizer.php
@chr-hertel

Copy link
Copy Markdown
Member

Thank you @ousamabenyounes.

@chr-hertel
chr-hertel merged commit 8cd24fa into symfony:main Sep 22, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Vertex/Gemini] Nullable fields in structured output throw exception

3 participants