{"record":{"id":"544cf8610fe89aff","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"the-schema-is-not-a-pydantic-subclass-with-this-l","errorCode":null,"errorMessage":"The schema is not a pydantic subclass. With this LLM model you must use a pydantic schemas.","messagePattern":"The schema is not a pydantic subclass\\. With this LLM model you must use a pydantic schemas\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/utils/output_parser.py","lineNumber":88,"sourceCode":"def get_pydantic_output_parser(\n    schema: Union[Dict[str, Any], Type[BaseModelV1 | BaseModelV2], Type],\n) -> JsonOutputParser:\n    \"\"\"\n    Get the correct output parser for the LLM model.\n\n    Returns:\n        JsonOutputParser: The output parser object.\n    \"\"\"\n    if issubclass(schema, BaseModelV1):\n        raise ValueError(\n            \"\"\"pydantic.v1 and langchain_core.pydantic_v1\n                         are not supported with this LLM model. Please use pydantic v2 instead.\"\"\"\n        )\n\n    if issubclass(schema, BaseModelV2):\n        return JsonOutputParser(pydantic_object=schema)\n\n    raise ValueError(\n        \"\"\"The schema is not a pydantic subclass.\n                     With this LLM model you must use a pydantic schemas.\"\"\"\n    )\n\n\ndef _base_model_v1_output_parser(x: BaseModelV1) -> dict:\n    \"\"\"\n    Parse the output of an LLM when the schema is BaseModelv1.\n\n    Args:\n        x (BaseModelV1): The output from the LLM model.\n\n    Returns:\n        dict: The parsed output.\n    \"\"\"\n    work_dict = x.dict()\n\n    def recursive_dict_parser(work_dict: dict) -> dict:","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/utils/output_parser.py#L70-L106","documentation":"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.","triggerScenarios":"Passing schema=dataclass or TypedDict or dict to a graph/node that calls get_pydantic_output_parser via _get_format_instructions or execute.","commonSituations":"Assuming any type-annotated class works as the extraction schema; migrating code that used raw dicts for output shaping.","solutions":["Define the output schema as a pydantic v2 BaseModel class and pass the class (not an instance)","Remove schema= entirely if you just want raw text/JSON output","Check you passed the class, not Schema() or Schema.model_json_schema()"],"exampleFix":"# before\n@dataclass\nclass Schema:\n    title: str\n# after\nfrom pydantic import BaseModel\nclass Schema(BaseModel):\n    title: str","handlingStrategy":"type-guard","validationCode":"import pydantic\nassert isinstance(schema, type) and issubclass(schema, pydantic.BaseModel), \"schema must be a pydantic v2 BaseModel class\"","typeGuard":"import pydantic\n\ndef is_pydantic_model_class(obj) -> bool:\n    return isinstance(obj, type) and issubclass(obj, pydantic.BaseModel)","tryCatchPattern":null,"preventionTips":["Pass the schema class, not an instance or .model_json_schema()","Use dataclasses/TypedDict elsewhere, pydantic BaseModel for graph schemas","Assert schema type in graph constructors"],"tags":["pydantic","schema","structured-output"],"backgroundTag":"schema-validation-failed","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}