Fix LangChainToolAdapter pydantic schema error for tools with internal fields#7808
Open
tysoncung wants to merge 1 commit into
Open
Fix LangChainToolAdapter pydantic schema error for tools with internal fields#7808tysoncung wants to merge 1 commit into
tysoncung wants to merge 1 commit into
Conversation
…l fields Cherry-pick from PR microsoft#7241 by TyCoding. Rebuilt pydantic model using filtered fields from the tool's .args property to avoid PydanticSchemaGenerationError on internal fields like run_manager. Fixes microsoft#6385
Author
|
👋 All 7 CI workflows are in status — needs a maintainer to approve the run since this is a fork PR. Could someone with write access approve the CI workflows? Changes pass GitGuardian and CLA already. Thanks! 🙏 |
avinashkamat48
left a comment
There was a problem hiding this comment.
This rebuilds the args model from schema_cls.model_fields, which only exists on Pydantic v2 models. LangChain still supports/tools may expose Pydantic v1 args_schema classes with __fields__, and the previous code accepted the schema object directly. For those tools this will raise AttributeError during adapter construction. Could you handle both v1 and v2 schema field APIs, or add a regression test for a LangChain tool whose args_schema is a pydantic.v1 BaseModel?
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.
Replaces PR #7241 (by TyCoding) — rebased on current main.
Summary
Some LangChain tools (e.g.,
GoogleDriveSearchTool) have anargs_schemathat includes internal fields likerun_manager(CallbackManagerForToolRun) which pydantic cannot serialize. This causes aPydanticSchemaGenerationErrorwhen creating aLangChainToolAdapter.Fix
Rebuild the pydantic model using only the filtered fields from the LangChain tool's
.argsproperty, which already excludes internal fields likerun_managerandcallbacks. This is consistent with how LangChain itself exposes tool arguments.Related Issue
Fixes #6385
CC: @TyCoding (original author) @anandfresh (original reviewer)