Skip to content

pydantic.errors : __modify_schema__ method is not supported in Pydantic v2 #28

@shanli030

Description

@shanli030

When I run compare_embeddings.py, this error occur:
pydantic.errors.PydanticUserError: The __modify_schema__ method is not supported in Pydantic v2. Use __get_pydantic_json_schema__ instead in class SecretStr.
For further information visit https://errors.pydantic.dev/2.11/u/custom-json-schema

I even comment the code below and the error still occur:

# Load environment variables. Assumes that project contains .env file with API keys
load_dotenv()
#---- Set OpenAI API key 
# Change environment variable name from "OPENAI_API_KEY" to the name given in 
# your .env file.
openai.api_key = os.environ['OPENAI_API_KEY']

Should I use other package or change my code?
My version:
langchain: 0.3.26
langchain-community==0.2.3
unstructured==0.14.4
chromadb>=0.5.0
pydantic: 2.11.7

Also, i usefrom langchain_ollama import OllamaEmbeddingsinstead of from langchain_openai import OpenAIEmbeddings

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions