Skip to content

Fix LangChainToolAdapter pydantic schema error for tools with internal fields#7808

Open
tysoncung wants to merge 1 commit into
microsoft:mainfrom
tysoncung:fix/langchain-pydantic-schema-updated
Open

Fix LangChainToolAdapter pydantic schema error for tools with internal fields#7808
tysoncung wants to merge 1 commit into
microsoft:mainfrom
tysoncung:fix/langchain-pydantic-schema-updated

Conversation

@tysoncung

Copy link
Copy Markdown

Replaces PR #7241 (by TyCoding) — rebased on current main.

Summary

Some LangChain tools (e.g., GoogleDriveSearchTool) have an args_schema that includes internal fields like run_manager (CallbackManagerForToolRun) which pydantic cannot serialize. This causes a PydanticSchemaGenerationError when creating a LangChainToolAdapter.

Fix

Rebuild the pydantic model using only the filtered fields from the LangChain tool's .args property, which already excludes internal fields like run_manager and callbacks. This is consistent with how LangChain itself exposes tool arguments.

Related Issue

Fixes #6385

CC: @TyCoding (original author) @anandfresh (original reviewer)

…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
@tysoncung

Copy link
Copy Markdown
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 avinashkamat48 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in LangChainToolAdapter GoogleDriveSearchTool: Unable to generate pydantic-core schema

2 participants