fix(google): tool_choice none with empty tools, response metadata, structured output format#10438
Open
pawel-twardziak wants to merge 4 commits intolangchain-ai:mainfrom
Conversation
…ructured output format
🦋 Changeset detectedLatest commit: cc9f39d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
1.
tool_choice: "none"with empty tools (converters/tools.ts)convertToolChoiceToGeminiConfighad a guardif (!hasTools || toolChoice === undefined) return undefinedthat discardedtool_choice: "none"whenever tools were absent. This meantbindTools([], { tool_choice: 'none' })silently sent notoolConfigto the API, allowing models likegemini-3-flash-previewto hallucinate function calls.The fix splits the guard so
"none"bypasses the!hasToolscheck - it is the only mode that is semantically meaningful without tool declarations. All other modes ("auto","any", etc.) still returnundefinedwhen no tools are present.2.
response_metadata.modelmissing (chat_models/base.ts)Neither the invoke path nor the streaming path included the model name in
response_metadata. Other providers (OpenAI, Anthropic, and now@langchain/google-genai) exposeresponse_metadata.model. The fix addsmodel: data.modelVersion(invoke) andmodel: chunk.modelVersion(stream) from the API response.3.
ls_structured_output_formatmissing (chat_models/base.ts)withStructuredOutputdid not set thels_structured_output_formatconfig key, so LangSmith could not track which structured output strategy or schema was used. The fix addsls_structured_output_format: { kwargs: { method }, schema: toJsonSchema(schema) }to both the"jsonSchema"and"functionCalling"paths, matching what@langchain/google-genaialready does.Tests
convertToolChoiceToGeminiConfig("none", false)- verifies NONE config is returned even without tools.hasTools=falsewith non-none choices.Fixes #10432