ScrapeGraphAI/Scrapegraph-ai · error · ValueError

The schema is not a pydantic subclass. With this LLM model y

Error message

The schema is not a pydantic subclass. With this LLM model you must use a pydantic schemas.

What it means

ValueError from get_pydantic_output_parser: the schema is neither a pydantic v1 nor v2 BaseModel subclass (e.g. a dataclass, TypedDict, dict, or plain class), so no JsonOutputParser can be created for structured extraction.

Source

Thrown at scrapegraphai/utils/output_parser.py:88

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:
        x (BaseModelV1): The output from the LLM model.

    Returns:
        dict: The parsed output.
    """
    work_dict = x.dict()

    def recursive_dict_parser(work_dict: dict) -> dict:

View on GitHub (pinned to 532dfffbf6)

Solutions

  1. Define the output schema as a pydantic v2 BaseModel class and pass the class (not an instance)
  2. Remove schema= entirely if you just want raw text/JSON output
  3. Check you passed the class, not Schema() or Schema.model_json_schema()

Example fix

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

Strategy: type-guard

Validate before calling

import pydantic
assert isinstance(schema, type) and issubclass(schema, pydantic.BaseModel), "schema must be a pydantic v2 BaseModel class"

Type guard

import pydantic

def is_pydantic_model_class(obj) -> bool:
    return isinstance(obj, type) and issubclass(obj, pydantic.BaseModel)

Prevention

When it happens

Trigger: Passing schema=dataclass or TypedDict or dict to a graph/node that calls get_pydantic_output_parser via _get_format_instructions or execute.

Common situations: Assuming any type-annotated class works as the extraction schema; migrating code that used raw dicts for output shaping.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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