Skip to content

ValidationError when using prefixItems in google.genai.types.Schema #1468

@stri8ed

Description

@stri8ed

Environment details

  • Programming language: Python
  • OS: Mac
  • Language runtime version: 3.12
  • Package version: 1.40.0

Steps to reproduce

  1. Define a JSON schema that uses prefixItems.
  2. Attempt to validate it using google.genai.types.Schema.model_validate().
import google.genai.types as types
import pydantic

JSON_SCHEMA = {
    "type": "array",
    "prefixItems": [
        {
          "type": "object",
          "properties": {
            "id": {"const": 42},
            "original": {"type": "string", "maxLength": 750},
            "thoughts": {"type": "string", "maxLength": 650},
            "translation": {"type": "string", "maxLength": 1000}
          }
        }
    ],
    "items": {
        "type": "object",
        "properties": {
            "id": {"type": "integer"},
            "original": {"type": "string"},
            "thoughts": {"type": "string"},
            "translation": {"type": "string"}
        },
        "required": ["id", "original", "thoughts", "translation"]
    }
}

try:
    schema = types.Schema.model_validate(JSON_SCHEMA)
except pydantic.ValidationError as e:
    print(f"ERROR: {e}")

Outputs:

ERROR: 1 validation error for Schema
prefixItems
  Extra inputs are not permitted [type=extra_forbidden, input_value=[{'type': 'object', 'prop...', 'maxLength': 1000}}}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden

As per this press release from May, prefixItems should be supported.

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or 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