Skip to content

Structured output does not work with Grounding #665

Description

@samshipengs

I'm trying to use structured output (python pydantic model schema) with grounding = true, and I got the following error:

ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Unable to submit request because controlled generation is not supported with google_search tool. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini', 'status': 'INVALID_ARGUMENT'}}

Based on the error, my guess is ground=true cannot be used with structured output?

my simple code in python:
google-genai==1.10.0

google_search_tool = (
                [Tool(google_search=GoogleSearch())] if grounding else None
            )

            response = self.gemini_client.models.generate_content(
                model=self.model_name,
                contents=user_prompt,
                config=GenerateContentConfig(
                    tools=google_search_tool,
                    system_instruction=prompt,
                    temperature=0.2,
                    # top_k=100,
                    # top_p=0.2,
                    response_mime_type="application/json",
                    response_schema=schema,
                    seed=42,
                ),
            )

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions