Repository navigation
fix: handle callback parameters in LangChainToolAdapter schema generation - #8356
Closed
David-goldenman wants to merge 1 commit into
Closed
David-goldenman wants to merge 1 commit into
David-goldenman wants to merge 1 commit into
Conversation
…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
Author
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
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_managerof typeCallbackManagerForToolRunorAsyncCallbackManagerForToolRun) cannot be serialized by Pydantic, causing schema generation to fail with 'Unable to generate pydantic-core schema'.Changes
arbitrary_types_allowed=True: Added to the created model config for any remaining edge casesToolWithoutSchematest class to verify the fix works for tools withoutargs_schemathat have callbacksTesting