{"record":{"id":"c5d8b82defa7ed8b","repo":"langchain-ai/langchain","slug":"structured-prompts-need-to-be-piped-to-a-language","errorCode":null,"errorMessage":"Structured prompts need to be piped to a language model.","messagePattern":"Structured prompts need to be piped to a language model\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/structured.py","lineNumber":214,"sourceCode":"            A `RunnableSequence` object.\n\n        Raises:\n            NotImplementedError: If the first element of `others` is not a language\n                model.\n        \"\"\"\n        if (others and isinstance(others[0], BaseLanguageModel)) or hasattr(\n            others[0], \"with_structured_output\"\n        ):\n            return RunnableSequence(\n                self,\n                others[0].with_structured_output(\n                    self.schema_, **self.structured_output_kwargs\n                ),\n                *others[1:],\n                name=name,\n            )\n        msg = \"Structured prompts need to be piped to a language model.\"\n        raise NotImplementedError(msg)\n","sourceCodeStart":196,"sourceCodeEnd":215,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/structured.py#L196-L215","documentation":"Raised by `StructuredPrompt.__or__` (the `|` pipe operator) when the object being piped is neither recognized as a `BaseLanguageModel` nor exposes a `with_structured_output` method. StructuredPrompt works by piping into a model and wrapping it with `with_structured_output(self.schema_, ...)`, so anything else cannot honor the schema contract and raises `NotImplementedError`.","triggerScenarios":"`structured_prompt | output_parser` (e.g. `StrOutputParser`), `structured_prompt | some_runnable`, or piping to a mock/test double lacking `with_structured_output`. The condition checks `others[0]` only, so a model anywhere but first position also fails.","commonSituations":"Adding an output parser directly after a structured prompt (a habit from normal LCEL chains where `prompt | llm | parser` is idiomatic — here the parser must come after the model, not instead of it); unit tests piping to fake runnables; custom model wrappers that did not inherit from `BaseLanguageModel` and do not implement `with_structured_output`.","solutions":["Pipe the structured prompt directly into a language model first: `prompt | llm`, and append any parser after the model: `prompt | llm | parser`","For custom model classes, implement `with_structured_output(schema, **kwargs)` or subclass `BaseLanguageModel` so the isinstance check passes","If you do not need structured output, use a plain `ChatPromptTemplate` instead of `StructuredPrompt`"],"exampleFix":"# before\nchain = structured_prompt | StrOutputParser()  # NotImplementedError\n\n# after\nchain = structured_prompt | llm | StrOutputParser()  # model first, then parser","handlingStrategy":"type-guard","validationCode":"from langchain_core.language_models import BaseLanguageModel\n\ndef accepts_structured_prompt(target: object) -> bool:\n    return isinstance(target, BaseLanguageModel) or hasattr(target, \"with_structured_output\")","typeGuard":"from langchain_core.language_models import BaseLanguageModel\n\ndef is_pipeable_model(x: object) -> bool:\n    return isinstance(x, BaseLanguageModel) or callable(getattr(x, \"with_structured_output\", None))","tryCatchPattern":"try:\n    chain = structured_prompt | target\nexcept NotImplementedError as e:\n    if \"language model\" in str(e):\n        raise TypeError(\"pipe StructuredPrompt into a model first: prompt | llm | parser\") from e\n    raise","preventionTips":["Always order LCEL structured chains as prompt | model | parser","Subclass BaseLanguageModel (or implement with_structured_output) for custom models","Use plain ChatPromptTemplate when structured output is not needed"],"tags":["prompts","structured-output","lcel","pipe-operator","notimplementederror"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}