fix(genai): emit items schema for List[Any] tool parameters#1805
Open
obchain (obchain) wants to merge 1 commit into
Open
fix(genai): emit items schema for List[Any] tool parameters#1805obchain (obchain) wants to merge 1 commit into
obchain (obchain) wants to merge 1 commit into
Conversation
Pydantic v2 emits a valid `"items": {}` for `List[Any]` array fields.
`_get_properties_from_schema` guarded with `v.get("items")`, which is
falsy for `{}`, so the `items` field was dropped from the resulting
FunctionDeclaration. Gemini then rejects the request with
`400 INVALID_ARGUMENT: ...properties[...].items: missing field`.
Switch to `"items" in v` (matching the equivalent check in
`langchain-google-vertexai`) so an empty items schema is still
forwarded to `_get_items_from_schema_any`, which defaults the inner
type to STRING.
Fixes langchain-ai#1768
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.
Description
ChatGoogleGenerativeAIinvocations with tools that takeList[Any]parameters fail at runtime with:Root cause: Pydantic v2 emits a valid
"items": {}for an untyped array. In_get_properties_from_schema(libs/genai/langchain_google_genai/_function_utils.py) the guard wasv.get("items"), which is falsy for{}, so theitemsfield was dropped from the FunctionDeclaration. Gemini rejects array fields withoutitems.langchain-google-vertexaialready uses a key-existence check ("items" in property); this PR alignslangchain-google-genaiwith that. An emptyitemsschema is now forwarded to_get_items_from_schema_any, which defaults the inner type toSTRING— the minimal payload Gemini accepts for an untyped array.Relevant issues
Fixes #1768
Type
🐛 Bug Fix
Changes
libs/genai/langchain_google_genai/_function_utils.py: switchv.get("items")to"items" in vat the array-property check.libs/genai/tests/unit_tests/test_function_utils.py: addtest_tool_with_list_any_param_emits_itemsregression covering theList[Any]→itemsshape.Testing
uv run --group test pytest tests/unit_tests/test_function_utils.py— 28 passed.main(stashing the source change) and passes with the fix.make lint(ruff) andmypyclean for the touched files.