{"record":{"id":"7e089b68cc064b8a","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"pydantic-v1-and-langchain-core-pydantic-v1-are-not","errorCode":null,"errorMessage":"pydantic.v1 and langchain_core.pydantic_v1 are not supported with this LLM model. Please use pydantic v2 instead.","messagePattern":"pydantic\\.v1 and langchain_core\\.pydantic_v1 are not supported with this LLM model\\. Please use pydantic v2 instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/utils/output_parser.py","lineNumber":80,"sourceCode":"        return _base_model_v1_output_parser\n\n    if issubclass(schema, BaseModelV2):\n        return _base_model_v2_output_parser\n\n    return _dict_output_parser\n\n\ndef 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:","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/utils/output_parser.py#L62-L98","documentation":"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.","triggerScenarios":"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).","commonSituations":"Copying schemas from old LangChain examples or pre-1.0 tutorials that still use pydantic v1; mixed pydantic versions in the environment.","solutions":["Rewrite the schema to inherit from pydantic.BaseModel (v2)","Replace langchain_core.pydantic_v1 imports with plain pydantic","Check for stray pydantic.v1 compatibility imports in the schema module"],"exampleFix":"# before\nfrom pydantic.v1 import BaseModel\nclass Schema(BaseModel):\n    title: str\n# after\nfrom pydantic import BaseModel\nclass Schema(BaseModel):\n    title: str","handlingStrategy":"type-guard","validationCode":"from pydantic import v2_not_available  # placeholder\nimport pydantic\nassert issubclass(schema, pydantic.BaseModel), \"schema must be pydantic v2\"","typeGuard":"import pydantic\nfrom pydantic import v1\n\ndef is_pydantic_v2(cls) -> bool:\n    return isinstance(cls, type) and issubclass(cls, pydantic.BaseModel) and not issubclass(cls, getattr(pydantic.v1, \"BaseModel\", ()))","tryCatchPattern":"try:\n    parser = get_pydantic_output_parser(schema)\nexcept ValueError as e:\n    raise TypeError(f\"fix schema: {e}\") from e","preventionTips":["Never import BaseModel from pydantic.v1 in new code","Add a CI check forbidding 'pydantic.v1' imports","Migrate copied LangChain example schemas to pydantic v2"],"tags":["pydantic","schema","structured-output"],"backgroundTag":"pydantic-v1-v2-migration","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}