jsonlangchain

RuntimeError: no validator found for <class 'langchain_community.tools.json.tool.JsonSpec'>, see `arbitrary_types_allowed` in Config


I am getting RuntimeError: no validator found for <class 'langchain_community.tools.json.tool.JsonSpec'>, see arbitrary_types_allowed in Config even after to installing

import yaml
from langchain_community.agent_toolkits import JsonToolkit, create_json_agent
from langchain_community.tools.json.tool import JsonSpec
from langchain_openai import OpenAI

Solution

  • The error you're encountering due to incorrect Pydantic configuration. LangChain uses Pydantic models for validation, and this error can occur when Pydantic does know to handle certain types, such as the JsonSpec. Pydantic's Config class has an option called arbitrary_types_allowed that needs to be set to True in such cases.

    SOLUTIONS

    1. always work in a virtual environment. (recommended)

    2. check install pydantic and other modules related to langchain like langchain-community or langchain-openai. (recommended)

    3. use the following code to set arbitrary_types_allowed to True

        from pydantic import BaseModel
      
        class Maintain(BaseModel):
              class Config:
                    arbitrary_types_allowed = True