Skip to content

Conversation

@Nitinref
Copy link
Contributor

@Nitinref Nitinref commented Dec 1, 2025

Fix: Gemini JSON Schema Error (propertyNames removed)

This PR fixes the issue where Gemini throws:

INVALID_ARGUMENT: Unexpected property: propertyNames

What was the bug?

Zod → Gemini schema conversion was passing fields that Gemini does not support:

  • propertyNames
  • additionalProperties
  • strict object metadata

Gemini rejects these and breaks tool calling + structured output.

What we added

A new utility cleanGeminiSchema.ts that:

  • Recursively removes unsupported JSON schema fields
  • Ensures Gemini gets a clean schema
  • Prevents the INVALID_ARGUMENT error

Files changed

  • chat_models.ts
  • utils/common.ts
  • cleanGeminiSchema.ts (new file)

Manual Test (passed)

Running a tool with a Zod schema containing dynamic keys now works without errors.

Summary

This PR ensures that all Gemini models accept LangChain-generated schemas safely and correctly.

…rtyNames and patternProperties for Gemini tool-calling
@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

⚠️ No Changeset found

Latest commit: e7edff0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member

@hntrl hntrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some kind of test suite to verify this works?

@Nitinref
Copy link
Contributor Author

Nitinref commented Dec 16, 2025

@hntrl Added a focused unit test for the google-genai package
to verify that unsupported propertyNames and
patternProperties are removed from schemas.
The google-genai test suite passes locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants