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] support dictionaries in pydantic basemodels for json (via additionalProperties) #70

Open
Ben-Epstein opened this issue Jan 2, 2025 · 1 comment
Labels
api: gemini-api api: vertex-ai Issues related to the Vertex AI API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@Ben-Epstein
Copy link

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: dict[str, int]

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")
ValidationError: 1 validation error for Schema
properties.foo.additionalProperties
  Extra inputs are not permitted [type=extra_forbidden, input_value={'type': 'INTEGER'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/extra_forbidden

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

@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

happy-qiao commented Jan 2, 2025

Hi Ben.

additionalProperties is not supported by API backend. We're working on adding this feature and hope to have it ready soon.

Thanks

@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 2, 2025
@happy-qiao happy-qiao changed the title [BUG] dictionaries not supported in pydantic basemodels for json (via additionalProperties) [Feature] support dictionaries in pydantic basemodels for json (via additionalProperties) Jan 2, 2025
@sasha-gitg sasha-gitg added priority: p0 Highest priority. Critical issue. P0 implies highest priority. api: vertex-ai Issues related to the Vertex AI API. api: gemini-api priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. priority: p0 Highest priority. Critical issue. P0 implies highest priority. labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: gemini-api api: vertex-ai Issues related to the Vertex AI API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to 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

3 participants