Search code examples
pythonopenai-apipydanticlangchain

ValidationError: 1 validation error for StructuredTool


I was getting an error when trying to use a Pydantic schema as an args_schema parameter value on a @tool decorator, following the DeepLearning.AI course.

My code was:

from pydantic import BaseModel, Field

class SearchInput(BaseModel):
    query: str = Field(description="Thing to search for")

@tool(args_schema=SearchInput)
def search(query: str) -> str:
    """Searches for weather online"""
    return "21c"

And was getting this error:

ValidationError: 1 validation error for StructuredTool
args_schema subclass of BaseModel expected (type=type_error.subclass; expected_class=BaseModel)

Solution

  • Downgrading to pydantic 1.10.10 worked for me.

    Add pydantic==1.10.10 to your requirements.txt and install it with pip install -r requirements.txt

    or with the command pip install pydantic==1.10.10