Skip to content

Gen AI with structured output - propertyOrdering in Python vs. Java implementations #1169

Description

@j-nc

Hi, when using gen AI with schema-constrained output, I've noticed in google/genai/_transformers.py, there's explicit handling of propertyOrdering (aka. property_ordering), while it seems that this is not the case in the Java implementation.

In the Python implementation the logic for including it is fairly simple: if propertyOrdering is missing, add it:

      if (
          len(properties.items()) > 1
          and order_properties  # True by default
          and 'propertyOrdering' not in schema
      ):
        schema['property_ordering'] = list(properties.keys())

I wouldn't bring this up if it didn't actually result in AI returning different, and better responses with it, vs. without it. Specifically, in my Java app, with the exact same prompt and basic schema (without explicitly setting propertyOrdering), AI consistently returns fewer fields than it does when invoked via the Python app.

Now I've noticed this field is labeled as non-standard, at least in v1.51.0, which I have locally:

    /**
     * Setter for propertyOrdering.
     *
     * <p>propertyOrdering: Optional. Order of properties displayed or used where order matters.
     * This is not a standard field in OpenAPI specification, but can be used to control the order
     * of properties.
     */

Despite that, I've now added propertyOrdering to my schema (in Java). (Note, I have Vertex AI set to true in both cases, if that makes a difference.)

Is there any general information on this? In particular, is propertyOrdering expected to have an effect on structured output generation in Vertex AI, and should the Java implementation also be adding it automatically when it isn't explicitly provided?

Thanks.

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions