Skip to content

fix(genai): improve tool config, response metadata, and structured output#10434

Open
pawel-twardziak wants to merge 4 commits intolangchain-ai:mainfrom
pawel-twardziak:fix/genai-tool-config-response-metadata-structured-output
Open

fix(genai): improve tool config, response metadata, and structured output#10434
pawel-twardziak wants to merge 4 commits intolangchain-ai:mainfrom
pawel-twardziak:fix/genai-tool-config-response-metadata-structured-output

Conversation

@pawel-twardziak
Copy link
Contributor

@pawel-twardziak pawel-twardziak commented Mar 17, 2026

Improves @langchain/google-genai provider with tool config handling, response metadata, structured output defaults, and modernized tests.

Changes

Core (chat_models.ts, utils/common.ts)

  • tool_choice: "none" fallback: When tool_choice is set to "none" but no tools are provided (e.g. after bindTools([], { tool_choice: "none" })), invocationParams now emits toolConfig: { functionCallingConfig: { mode: FunctionCallingMode.NONE } }. Previously, the "none" choice was silently ignored when options.tools was empty because convertToolsToGenAI was never called.
  • response_metadata.model: Both mapGenerateContentResultToChatResult (invoke) and convertResponseContentToChatGenerationChunk (stream) now include the model name in response_metadata, matching the pattern used by other LangChain providers (OpenAI, Anthropic). model_provider: "google-genai" was already present for streaming and is now also added to the non-streaming path.
  • Default withStructuredOutput method: The method parameter now defaults to "functionCalling" instead of undefined, making the behavior explicit and consistent with other providers.
  • LangSmith ls_structured_output_format metadata: withStructuredOutput now attaches ls_structured_output_format (with kwargs.method and schema) to the config for both "functionCalling" and "jsonSchema" paths, enabling LangSmith to track which structured output strategy was used.

Tests

  • New unit tests for invocationParams with tool_choice: "none" (with and without tools).
  • New integration tests for tool_choice: "none" via bindTools (both invoke and stream).
  • Model upgrades: Updated all test model references from gemini-2.0-flash / gemini-1.5-pro / gemini-1.5-flash to gemini-2.5-flash.
  • Embedding tests: Added explicit model: "gemini-embedding-001" to all embedding integration tests.
  • GoogleSearchRetrievalTool tests: Skipped (describe.skip) - google_search_retrieval is no longer supported by current models; newer models use google_search instead.
  • Context caching tests: Wrapped in describe.skipIf(!videoFileExists) so the suite is skipped gracefully when the large video fixture is not downloaded.
  • Token count assertions: Relaxed toBe to toBeGreaterThanOrEqual for total_tokens checks and increased maxOutputTokens from 10 to 256 to avoid truncation flakiness.
  • ESLint fixes: Replaced as any casts in invocationParams test calls with as Partial<GoogleGenerativeAIChatCallOptions>.
  • Import fix: Changed tool_call_conversion.test.ts from @langchain/google-genai (package self-reference) to relative ../chat_models.js.

Related to #10432
This PR fixes the same problem, but for `@langchain/google-genai


Changes have been verified with the current state of the official docs for Google AI


integration tests

90% of the tests were not valid any longer; all fixed

image

unit tests

image

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: af1aafd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@langchain/google-genai Patch
@langchain/google-common Patch
@langchain/google-gauth Patch
@langchain/google-webauth Patch
@langchain/google-vertexai Patch
@langchain/google-vertexai-web Patch

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

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.

1 participant