langchain-ai/langchain · error · NotImplementedError

with_structured_output is not implemented for this model.

Error message

with_structured_output is not implemented for this model.

What it means

`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.

Source

Thrown at libs/core/langchain_core/language_models/chat_models.py:2526

            #     'answer': 'They weigh the same',
            #     '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.'
            # }
            ```

        !!! warning "Behavior changed in `langchain-core` 0.2.26"

            Added support for `TypedDict` class.

        """  # noqa: E501
        _ = kwargs.pop("method", None)
        _ = kwargs.pop("strict", None)
        if kwargs:
            msg = f"Received unsupported arguments {kwargs}"
            raise ValueError(msg)

        if type(self).bind_tools is BaseChatModel.bind_tools:
            msg = "with_structured_output is not implemented for this model."
            raise NotImplementedError(msg)

        llm = self.bind_tools(
            [schema],
            tool_choice="any",
            ls_structured_output_format={
                "kwargs": {"method": "function_calling"},
                "schema": schema,
            },
        )
        output_parser: JsonOutputToolsParser
        if isinstance(schema, type) and is_basemodel_subclass(schema):
            output_parser = PydanticToolsParser(tools=[schema], first_tool_only=True)
        else:
            key_name = convert_to_openai_tool(schema)["function"]["name"]
            output_parser = JsonOutputKeyToolsParser(
                key_name=key_name, first_tool_only=True
            )
        if include_raw:

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Use a model that supports tools (e.g. `init_chat_model("openai:gpt-4o")`, Anthropic, Gemini) for structured output.
  2. If writing a custom model, implement `bind_tools` (and ideally `with_structured_output`) on the subclass.
  3. As a workaround without tools: `model | JsonOutputParser()` with a schema embedded in the prompt.
  4. Verify with `type(model).bind_tools is BaseChatModel.bind_tools` before calling.

Example fix

# before
model = MyCustomChatModel()
chain = model.with_structured_output(Schema)  # NotImplementedError

# after
class MyCustomChatModel(BaseChatModel):
    def bind_tools(self, tools, **kwargs):
        return self.bind(tools=convert_to_openai_tool(tools))
    ...
chain = model.with_structured_output(Schema)
Defensive patterns

Strategy: type-guard

Validate before calling

from langchain_core.language_models.chat_models import BaseChatModel
supports_tools = type(model).bind_tools is not BaseChatModel.bind_tools
if not supports_tools:
    raise NotImplementedError("model lacks bind_tools; structured output unavailable")

Type guard

from langchain_core.language_models.chat_models import BaseChatModel
def supports_structured_output(model: BaseChatModel) -> bool:
    return type(model).bind_tools is not BaseChatModel.bind_tools

Try / catch

try:
    chain = model.with_structured_output(Schema)
except NotImplementedError:
    chain = model | JsonOutputParser()  # prompt-based fallback

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/b8523c5f4786c326. Report an issue: GitHub.