Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Support Schema.prefixItems so that tuple type is supported in response_schema #69

Open
Ben-Epstein opened this issue Jan 2, 2025 · 2 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@Ben-Epstein
Copy link

Ben-Epstein commented Jan 2, 2025

Environment details

  • Programming language: python
  • OS: macos/linux
  • Language runtime version: python 3.10
  • Package version: 0.3.0

Steps to reproduce

from google import genai
from google.genai import types
from pydantic import BaseModel

class Answer(BaseModel):
  foo: tuple[int, str]

project_id = ""
client = genai.Client(vertexai=True, project=project_id, location="us-central1")
cfg = types.GenerateContentConfig(
            response_schema=Answer,
            response_mime_type="application/json",
            temperature=0.0,
            seed=42,
        )
res = client.models.generate_content(model="gemini-1.5-flash-002", config=cfg, contents="Pick a value for foo")

response from api

ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Invalid JSON payload received. Unknown name "prefixItems" at \'generation_config.response_schema.properties[0].value\': Cannot find field.', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'generation_config.response_schema.properties[0].value', 'description': 'Invalid JSON payload received. Unknown name "prefixItems" at \'generation_config.response_schema.properties[0].value\': Cannot find field.'}]}]}}

if i pass the class directly I get

ValidationError: 3 validation errors for Schema
properties.foo.minItems
  Input should be a valid string [type=string_type, input_value=2, input_type=int]
    For further information visit https://errors.pydantic.dev/2.10/v/string_type
properties.foo.maxItems
  Input should be a valid string [type=string_type, input_value=2, input_type=int]
    For further information visit https://errors.pydantic.dev/2.10/v/string_type
properties.foo.prefixItems
  Extra inputs are not permitted [type=extra_forbidden, input_value=[{'type': 'INTEGER'}, {'type': 'STRING'}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.10/v/extra_forbidden

see: https://www.learnjsonschema.com/2020-12/applicator/prefixitems/

@Ben-Epstein Ben-Epstein added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 2, 2025
@happy-qiao
Copy link
Collaborator

Hi Ben

prefixItems is not supported by API backend.

properties.foo.minItems and properties.foo.maxItems are SDK bugs. We are working on fixing it.

Thanks

@happy-qiao
Copy link
Collaborator

properties.foo.minItems and properties.foo.maxItems type issues are fix now.

@happy-qiao happy-qiao changed the title [BUG] tuples not supported in pydantic basemodels [Feature Request] Support Schema.prefixItems so that tuple type is supported in response_schema Jan 7, 2025
@happy-qiao happy-qiao added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants