Skip to content

Error when response schema definition has anyOf with null #625

Closed as not planned

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,
                             ....)

Activity

  1. added
    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.
    on Apr 6, 2025
  2. EItanya commented on May 23, 2025

    @EItanya

    I would like to double down on this. How is a user supposed to signify that a parameter is optional? Btw, this is also true for tool calls as well.

  3. DDJensMadsen commented on May 26, 2025

    @DDJensMadsen
    Author

    hi @EItanya I am not sure I understand your comment? Could you elaborate a bit :-)

  4. EItanya commented on May 26, 2025

    @EItanya

    This issue is specifically saying that response_schema incorrectly handles any_of, but I'm updating that the same problem exists for tool calls.

  5. luutuankiet commented on Dec 3, 2025

    @luutuankiet

    Hi @DDJensMadsen @EItanya with the latest release v1.16.1 I am experiencing the opposite where VertexAI client throws validation errors for type Optional[Union[str, List[Dict[str, Any]]]] while gemini API client allows this setup. #1807

    Perhaps something changed on the Gemini API since its support for json schema. Is this something you still encounter on your type str | int | None ?

  6. Venkaiahbabuneelam commented on May 21, 2026

    @Venkaiahbabuneelam

    Hi Team,
    Could you please confirm whether the issue is resolved or still persists?
    Thanks

  7. github-actions commented on May 30, 2026

    @github-actions

    This issue has been marked as stale because it has been open for 7 days with no activity. It will be closed in 2 days if no further activity occurs.

  8. github-actions commented on Jun 1, 2026

    @github-actions

    This issue was closed because it has been inactive for 9 days. Please post a new issue if you need further assistance. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions