ScrapeGraphAI/Scrapegraph-ai · error · ValueError

pydantic.v1 and langchain_core.pydantic_v1 are not supported

Error message

pydantic.v1 and langchain_core.pydantic_v1 are not supported with this LLM model. Please use pydantic v2 instead.

What it means

ValueError from get_pydantic_output_parser: the schema passed for structured output is a pydantic v1 model (pydantic.v1 or langchain_core.pydantic_v1 BaseModel). This library's parsers only support pydantic v2 schemas, so JsonOutputParser cannot be built.

Source

Thrown at scrapegraphai/utils/output_parser.py:80

        return _base_model_v1_output_parser

    if issubclass(schema, BaseModelV2):
        return _base_model_v2_output_parser

    return _dict_output_parser


def get_pydantic_output_parser(
    schema: Union[Dict[str, Any], Type[BaseModelV1 | BaseModelV2], Type],
) -> JsonOutputParser:
    """
    Get the correct output parser for the LLM model.

    Returns:
        JsonOutputParser: The output parser object.
    """
    if issubclass(schema, BaseModelV1):
        raise ValueError(
            """pydantic.v1 and langchain_core.pydantic_v1
                         are not supported with this LLM model. Please use pydantic v2 instead."""
        )

    if issubclass(schema, BaseModelV2):
        return JsonOutputParser(pydantic_object=schema)

    raise ValueError(
        """The schema is not a pydantic subclass.
                     With this LLM model you must use a pydantic schemas."""
    )


def _base_model_v1_output_parser(x: BaseModelV1) -> dict:
    """
    Parse the output of an LLM when the schema is BaseModelv1.

    Args:

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Rewrite the schema to inherit from pydantic.BaseModel (v2)
  2. Replace langchain_core.pydantic_v1 imports with plain pydantic
  3. Check for stray pydantic.v1 compatibility imports in the schema module

Example fix

# before
from pydantic.v1 import BaseModel
class Schema(BaseModel):
    title: str
# after
from pydantic import BaseModel
class Schema(BaseModel):
    title: str
Defensive patterns

Strategy: type-guard

Validate before calling

from pydantic import v2_not_available  # placeholder
import pydantic
assert issubclass(schema, pydantic.BaseModel), "schema must be pydantic v2"

Type guard

import pydantic
from pydantic import v1

def is_pydantic_v2(cls) -> bool:
    return isinstance(cls, type) and issubclass(cls, pydantic.BaseModel) and not issubclass(cls, getattr(pydantic.v1, "BaseModel", ()))

Try / catch

try:
    parser = get_pydantic_output_parser(schema)
except ValueError as e:
    raise TypeError(f"fix schema: {e}") from e

Prevention

When it happens

Trigger: Passing a schema that inherits from pydantic.v1.BaseModel or langchain_core.pydantic_v1.BaseModel as the graph's schema (used by _get_format_instructions / node execute).

Common situations: Copying schemas from old LangChain examples or pre-1.0 tutorials that still use pydantic v1; mixed pydantic versions in the environment.

Related errors


AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28). Data as JSON: /api/errors/7e089b68cc064b8a. Report an issue: GitHub.