Skip to content

Retain schema field ordering for google gemini and vertex #9828

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

Merged
merged 1 commit into from
Apr 16, 2025

Conversation

adrianlyjak
Copy link
Contributor

Title

Retain schema field ordering for google gemini and vertex by specifying propertyOrdering

Relevant issues

fixes #9783

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on (make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
image

Type

🐛 Bug Fix

Changes

This change adds the propertyOrdering field to vertex/gemini schemas, in order to retain pydantic and dictionary ordering of fields, otherwise the google APIs will alphabetize the fields.

I'd previously discovered this strange behavior in ~December 2024. At that time, the ai studio version of the API didin't support the propertyOrdering field, only vertex. Since then, they seem to have added it: https://ai.google.dev/gemini-api/docs/structured-output?lang=python. I verified with some basic scripts against the actual vertex and ai studio gemini APIs that this works without error.

Copy link

vercel bot commented Apr 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 16, 2025 2:00am

@krrishdholakia
Copy link
Contributor

Hi @adrianlyjak can you resolve the conflict - this looks good to merge

@adrianlyjak
Copy link
Contributor Author

Hi @adrianlyjak can you resolve the conflict - this looks good to merge

@krrishdholakia resolved

@krrishdholakia krrishdholakia merged commit e3729f9 into BerriAI:main Apr 16, 2025
5 checks passed
krrishdholakia added a commit that referenced this pull request Apr 16, 2025
…ltiple tool calls (#10040)

* fix #9783: Retain schema field ordering for google gemini and vertex (#9828)

* test: update test

* refactor(groq.py): initial commit migrating groq to base_llm_http_handler

* fix(streaming_chunk_builder_utils.py): fix how tool content is combined

Fixes #10034

* fix(vertex_ai/common_utils.py): prevent infinite loop in helper function

* fix(groq/chat/transformation.py): handle groq streaming errors correctly

* fix(groq/chat/transformation.py): handle max_retries

---------

Co-authored-by: Adrian Lyjak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Vertex AI does not respect JSON schema key ordering
2 participants