{"record":{"id":"3ba71c5b5d3dd8df","repo":"langchain-ai/langchain","slug":"type-property-is-not-implemented-in-class-self","errorCode":null,"errorMessage":"_type property is not implemented in class {self.__class__.__name__}. This is required for serialization.","messagePattern":"_type property is not implemented in class (.+?)\\. This is required for serialization\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/output_parsers/base.py","lineNumber":345,"sourceCode":"            prompt: Input `PromptValue`.\n\n        Returns:\n            Structured output.\n        \"\"\"\n        return self.parse(completion)\n\n    def get_format_instructions(self) -> str:\n        \"\"\"Instructions on how the LLM output should be formatted.\"\"\"\n        raise NotImplementedError\n\n    @property\n    def _type(self) -> str:\n        \"\"\"Return the output parser type for serialization.\"\"\"\n        msg = (\n            f\"_type property is not implemented in class {self.__class__.__name__}.\"\n            \" This is required for serialization.\"\n        )\n        raise NotImplementedError(msg)\n\n    @deprecated(\"1.4.2\", alternative=\"asdict\", removal=\"2.0.0\")\n    @override\n    def dict(self, **kwargs: Any) -> builtins.dict[str, Any]:\n        \"\"\"DEPRECATED - use `asdict()` instead.\n\n        Return a dictionary representation of the output parser.\n        \"\"\"\n        return self.asdict(**kwargs)\n\n    def asdict(self, **kwargs: Any) -> builtins.dict[str, Any]:\n        \"\"\"Return a dictionary representation of the output parser.\"\"\"\n        output_parser_dict = super().model_dump(**kwargs)\n        with contextlib.suppress(NotImplementedError):\n            output_parser_dict[\"_type\"] = self._type\n        return output_parser_dict\n","sourceCodeStart":327,"sourceCodeEnd":362,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/output_parsers/base.py#L327-L362","documentation":"The base `BaseOutputParser._type` property raises NotImplementedError by design; every serializable parser must override it with a short type identifier (e.g. `\"boolean_output_parser\"`, `\"json\"`). Serialization via `asdict()`/`dict()` embeds `_type` so the parser can be reconstructed on load, so calling those methods on a parser without `_type` fails. This is a subclass-contract error, not a runtime data error.","triggerScenarios":"Calling `parser.asdict()` (or deprecated `parser.dict()`) on a custom parser that does not define `_type`; passing such a parser through runnables that checkpoint/serialize their steps.","commonSituations":"Custom parsers built for a single chain and later pulled into LangGraph checkpointing; migrating persisted runnables that now serialize components they previously ignored.","solutions":["Add `@property def _type(self) -> str: return \"my_parser\"` to your subclass.","Use a unique, stable string if you plan to deserialize later, and register a loader for it.","If serialization is not needed for this parser, avoid `asdict()`/checkpointing paths instead of leaving the contract unimplemented."],"exampleFix":"// before\nclass MyParser(BaseOutputParser[str]):\n    def parse(self, text): return text.strip()\n\n// after\nclass MyParser(BaseOutputParser[str]):\n    @property\n    def _type(self) -> str: return \"my_parser\"\n    def parse(self, text): return text.strip()","handlingStrategy":"validation","validationCode":"def is_serializable_parser(p) -> bool:\n    try:\n        p._type\n        return True\n    except NotImplementedError:\n        return False\n\nif not is_serializable_parser(parser):\n    raise ValueError(f\"{type(parser).__name__} must define _type before checkpointing\")","typeGuard":null,"tryCatchPattern":"try:\n    parser.asdict()\nexcept NotImplementedError as e:\n    if \"_type\" in str(e):\n        # add _type to the subclass, or skip serializing this component\n        ...","preventionTips":["Include _type in your custom-parser template from day one","Test asdict() on every custom parser in CI","Use a unique stable _type string if you plan to load checkpoints later"],"tags":["output-parsers","serialization","subclass-contract"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}