googleapis / googleapis/java-genai

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

Open
#1,169 1 comment 0 reactions 1 assignee Claimed by @hemasekhar-p View on GitHub
priority: p3 type: feature request
Dominant language
Java
Stars
397
Forks
125
Avg merge
2d 8h
Merged PRs (30d)
41

Description

Hi, when using gen AI with schema-constrained output, I've noticed in [`google/genai/_transformers.py`](https://github.com/googleapis/python-genai/blob/ccbc6c58bf872885cfc0a453325060340e415f34/google/genai/_transformers.py#L817), 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:
```py
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:
```java
/**
* Setter for propertyOrdering.
*
*

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.