Skip to content

Schema.from_json_schema() loses description and title when unwrapping nullable any_of schemas #1992

@wsa-2002

Description

@wsa-2002

Environment details

  • Programming language: python
  • OS: macOS
  • Language runtime version: 3.13.2
  • Package version: 1.53.0

Steps to reproduce

from google.genai.types import JSONSchema, Schema
json_schema = JSONSchema(
    any_of=[
        JSONSchema(type='string'),
        JSONSchema(type='null'),
    ],
    description='xxx',
    title='xxx'
)
schema = Schema.from_json_schema(json_schema=json_schema)
print(schema.description) # Expected: 'xxx' | Actual: None
print(schema.nullable) # True (correct)

Actual Behavior

The description and title are lost. Only nullable=True and the type information are preserved.

Root Cause

In types.py, the unwrap logic at lines 2706-2712 replaces the entire schema with type_part but only carries over the default value:

if nullable_part and type_part:
    default_value = schema.default
    schema = type_part  # <-- Loses description, title, and other fields
    schema.nullable = True
    if default_value is not None:
        schema.default = default_value

Suggest Fix

if nullable_part and type_part:
    default_value = schema.default
    description_value = schema.description
    title_value = schema.title
    schema = type_part
    schema.nullable = True
    if default_value is not None:
        schema.default = default_value
    if description_value is not None:
        schema.description = description_value
    if title_value is not None:
        schema.title = title_value

Thanks!

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions