Skip to content

fix: handle callback parameters in LangChainToolAdapter schema generation - #8356

Closed
David-goldenman wants to merge 1 commit into
microsoft:mainfrom
David-goldenman:fix/langchain-adapter-callback-filter
Closed

David-goldenman wants to merge 1 commit into
microsoft:mainfrom
David-goldenman:fix/langchain-adapter-callback-filter

Conversation

@David-goldenman

Copy link
Copy Markdown

Description

Fixes #6385

When a LangChain tool doesn't have an args_schema, the adapter tries to infer parameter types from the callable's signature. However, LangChain callback parameters (run_manager of type CallbackManagerForToolRun or AsyncCallbackManagerForToolRun) cannot be serialized by Pydantic, causing schema generation to fail with 'Unable to generate pydantic-core schema'.

Changes

  1. Filter out callback parameters: When inferring args_type from the callable's signature, skip LangChain callback parameters
  2. Handle Optional callbacks: Also detect and skip Optional-wrapped callback types
  3. Add arbitrary_types_allowed=True: Added to the created model config for any remaining edge cases
  4. Add test case: Added ToolWithoutSchema test class to verify the fix works for tools without args_schema that have callbacks

Testing

  • Added test case that verifies schema generation works correctly for tools with callback parameters
  • Existing tests should continue to pass

…tion

When a LangChain tool doesn't have an args_schema, the adapter tries to
infer parameter types from the callable's signature. However, LangChain
callback parameters (run_manager of type CallbackManagerForToolRun or
AsyncCallbackManagerForToolRun) cannot be serialized by Pydantic, causing
schema generation to fail with 'Unable to generate pydantic-core schema'.

This fix:
1. Filters out LangChain callback parameters when building the fields dict
2. Handles Optional versions of callback types
3. Adds arbitrary_types_allowed=True to the created model config for
   any remaining edge cases
4. Adds test case for tools without args_schema that have callbacks

Fixes microsoft#6385
@David-goldenman

Copy link
Copy Markdown
Author

Closing as duplicate of #7994 and #7808 which address the same issue.

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

1 participant