Skip to content

Conversation

athan37
Copy link

@athan37 athan37 commented Oct 5, 2025

Fixes 400 error when using structured output with Google models by setting function calling mode to "auto" instead of "any" when responseMimeType is "application/json".

"error" : {
   "code" 400,
   "message" : "Forced function calling (mode = ANY) is not supported when 'response_mime_type' is not set to 'text/plain'. Please set 'tool_config.function_calling_config.mode= AUTO' or set 'response_mime_type' to 'text/plain'. For more details, see: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#tool-config",
   status: "INVALID_ARGUMENT"
}

Changes

  • Modified formatToolConfig in gemini.ts to dynamically set function calling mode based on responseMimeType
  • Enhanced withStructuredOutput in chat_models.ts to automatically set responseMimeType: "application/json"
  • Added unit tests covering both default and override scenarios
  • Updated documentation to reflect JSON mode support for ChatVertexAI and ChatGoogleGenerativeAI

Testing

  • Added 2 unit tests

Copy link

changeset-bot bot commented Oct 5, 2025

⚠️ No Changeset found

Latest commit: b88f8bc

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

vercel bot commented Oct 5, 2025

@athan37 is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Oct 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Updated (UTC)
langchainjs-docs Ignored Ignored Oct 9, 2025 1:30am

@christian-bromann
Copy link
Member

Really appreciate you taking the time to open this PR, @athan37 🙏
The team is currently focused on shipping our v1 release, so we’re pausing detailed reviews for a bit. We’ll follow up within the next 2–4 weeks once things settle — thanks so much for your patience!

@athan37 athan37 force-pushed the fix/google-response-mime-type-function-calling-mode branch 2 times, most recently from 4881781 to b3a4298 Compare October 9, 2025 01:30
@athan37 athan37 force-pushed the fix/google-response-mime-type-function-calling-mode branch from b3a4298 to a40a55d Compare October 18, 2025 15:22
@athan37 athan37 force-pushed the fix/google-response-mime-type-function-calling-mode branch from a40a55d to b88f8bc Compare October 18, 2025 15:25
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