-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StructuredTool raises an error when instantiated #9441
Comments
🤖 Hello, Thank you for providing a detailed description of your issue. From the code you've shared, it seems like you're correctly defining However, without the exact error message, it's difficult to pinpoint the exact cause of the issue. The error could be due to a variety of reasons, such as a problem with the To help us better understand the issue, could you please provide the exact error message that you're seeing when you try to instantiate the In the meantime, you could try to debug the issue by adding some print statements in your code to check the type of print(isinstance(InputArgsSchema, BaseModel)) This will print Looking forward to your response. Best, SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Some updates on the topic: The exact output and error message i get in the Colab environment (as suggested by @dosu-bot):
I can also reproduce this bug locally like so:
I debugged it locally and found that it seems like it is checking that So to address the issue/bug again it should work with the |
🤖 Hello, From the code you've shared, it seems like you're correctly defining The Could you please provide the exact error message you're receiving when trying to instantiate the Also, please ensure that the Looking forward to your response. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
@dosu-bot I did provide the error message in my comment |
Ah i found what caused the problem: Pydantic has released a new version on June 30, 2023: https://docs.pydantic.dev/2.0/blog/pydantic-v2-final/ LangChain should consider updating to the new pydantic version then or otherwise document this issue and the requirement to use the Pydantic v1 # causes bug if pydantic 2.x is installed:
# from pydantic import BaseModel
# this works for now
from pydantic.v1 import BaseModel |
🤖 Thank you for bringing this to our attention. You're correct that LangChain version 0.0.267 has some compatibility issues with Pydantic v2.0. This is due to the differences between Pydantic v1 and v2, and the way LangChain handles these differences. As you've found, a temporary workaround is to import However, it's important to avoid mixing Pydantic v1 and v2 code. If you're using Pydantic v2's from langchain.tools.base import Tool
from pydantic.v1 import BaseModel, Field # <-- Uses v1 namespace
class CalculatorInput(BaseModel):
question: str = Field()
Tool.from_function( # <-- tool uses v1 namespace
func=lambda question: 'hello',
name="Calculator",
description="useful for when you need to answer questions about math",
args_schema=CalculatorInput
) We're aware of this issue and are working on making LangChain compatible with Pydantic v2.0. As of We appreciate your patience and understanding as we work to resolve this issue. Please let us know if you have any other questions or concerns. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Hi, @Markus-sevend! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale. From what I understand, the issue you reported is related to instantiating a Now, we would like to know if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you for your understanding and patience. If you have any further questions or concerns, please don't hesitate to reach out. |
For me, installing pydantic 1.10.10 worked: |
System Info
Environment:
Google COLAB project. When running
!cat /etc/os-release
it prints:Python Environment
!python -V
:!pip show langchain
:Who can help?
@hwchase17
Information
Related Components
Reproduction
Create a blank Google Colab Project (https://colab.research.google.com/#create=true) then add a code block and paste in this code:
Now run the code block.
Expected behavior
The
StructuredTool
instance should be instantiated without an exception and theInputArgsSchema
should be accepted as argument forargs_schema
.The text was updated successfully, but these errors were encountered: