Skip to content

Error when response schema definition has anyOf with null #625

@DDJensMadsen

Description

@DDJensMadsen

Intro

I use v1.9.0 with the Gemini API. When sending a request with a response_schema with anyOf and where of the options is null, the API returns this error:

400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Unable to submit request because one or more response schemas specified other fields alongside any_of. When using any_of, it must be the only field set. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/control-generated-output', 'status': 'INVALID_ARGUMENT'}}

Is it a bug, and am I not using a non-supported schema feature?

To reproduce

In Python using this data model:

Baz = str | int | None

class Foo(BaseModel):
    bar: Baz

I get the error whereas this data model returns no error:

Baz = str | None

class Foo(BaseModel):
    bar: Baz

I configure the Gemini client as:

GenerateContentConfig(
    response_mime_type=(
          "application/json"
          if json_mode or json_mode_model is not None
          else None
          ),
          response_schema=response_schema,
)

and make the request as:

response = await self._client.aio.models.generate_content(
                             config=config,
                             ....)

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions