{"record":{"id":"b8523c5f4786c326","repo":"langchain-ai/langchain","slug":"with-structured-output-is-not-implemented-for-this","errorCode":null,"errorMessage":"with_structured_output is not implemented for this model.","messagePattern":"with_structured_output is not implemented for this model\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/language_models/chat_models.py","lineNumber":2526,"sourceCode":"            #     'answer': 'They weigh the same',\n            #     'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'\n            # }\n            ```\n\n        !!! warning \"Behavior changed in `langchain-core` 0.2.26\"\n\n            Added support for `TypedDict` class.\n\n        \"\"\"  # noqa: E501\n        _ = kwargs.pop(\"method\", None)\n        _ = kwargs.pop(\"strict\", None)\n        if kwargs:\n            msg = f\"Received unsupported arguments {kwargs}\"\n            raise ValueError(msg)\n\n        if type(self).bind_tools is BaseChatModel.bind_tools:\n            msg = \"with_structured_output is not implemented for this model.\"\n            raise NotImplementedError(msg)\n\n        llm = self.bind_tools(\n            [schema],\n            tool_choice=\"any\",\n            ls_structured_output_format={\n                \"kwargs\": {\"method\": \"function_calling\"},\n                \"schema\": schema,\n            },\n        )\n        output_parser: JsonOutputToolsParser\n        if isinstance(schema, type) and is_basemodel_subclass(schema):\n            output_parser = PydanticToolsParser(tools=[schema], first_tool_only=True)\n        else:\n            key_name = convert_to_openai_tool(schema)[\"function\"][\"name\"]\n            output_parser = JsonOutputKeyToolsParser(\n                key_name=key_name, first_tool_only=True\n            )\n        if include_raw:","sourceCodeStart":2508,"sourceCodeEnd":2544,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/language_models/chat_models.py#L2508-L2544","documentation":"`NotImplementedError` from the default `BaseChatModel.with_structured_output`: the base implementation depends on `bind_tools`, and `type(self).bind_tools is BaseChatModel.bind_tools` means the subclass never overrode `bind_tools`. Without tool binding, the function-calling structured-output path cannot be constructed.","triggerScenarios":"Calling `with_structured_output(schema)` on any chat model that does not override `bind_tools` — minimal custom `BaseChatModel` subclasses, generic/fake models, or wrappers that inherit the base `bind_tools` unchanged.","commonSituations":"Prototyping with `FakeMessagesListChatModel`/generic base models; custom in-house models where only `_generate` was implemented; using wrapper models (e.g. `RunnableLambda`-style) that don't implement tool APIs.","solutions":["Use a model that supports tools (e.g. `init_chat_model(\"openai:gpt-4o\")`, Anthropic, Gemini) for structured output.","If writing a custom model, implement `bind_tools` (and ideally `with_structured_output`) on the subclass.","As a workaround without tools: `model | JsonOutputParser()` with a schema embedded in the prompt.","Verify with `type(model).bind_tools is BaseChatModel.bind_tools` before calling."],"exampleFix":"# before\nmodel = MyCustomChatModel()\nchain = model.with_structured_output(Schema)  # NotImplementedError\n\n# after\nclass MyCustomChatModel(BaseChatModel):\n    def bind_tools(self, tools, **kwargs):\n        return self.bind(tools=convert_to_openai_tool(tools))\n    ...\nchain = model.with_structured_output(Schema)","handlingStrategy":"type-guard","validationCode":"from langchain_core.language_models.chat_models import BaseChatModel\nsupports_tools = type(model).bind_tools is not BaseChatModel.bind_tools\nif not supports_tools:\n    raise NotImplementedError(\"model lacks bind_tools; structured output unavailable\")","typeGuard":"from langchain_core.language_models.chat_models import BaseChatModel\ndef supports_structured_output(model: BaseChatModel) -> bool:\n    return type(model).bind_tools is not BaseChatModel.bind_tools","tryCatchPattern":"try:\n    chain = model.with_structured_output(Schema)\nexcept NotImplementedError:\n    chain = model | JsonOutputParser()  # prompt-based fallback","preventionTips":["Check `bind_tools` support before wiring structured output into pipelines.","Use tool-capable models (`init_chat_model`) when schemas are required.","Implement `bind_tools` on custom models before advertising structured output."],"tags":["structured-output","bind-tools","custom-model","not-implemented"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}