From 9e03864d6482256a48a2b497062ca7bc5139f2dc Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Fri, 7 Jun 2024 12:42:09 -0700 Subject: [PATCH] core: add error message for non-structured llm to StructuredPrompt (#22684) previously was the blank `NotImplementedError` from `BaseLanguageModel.with_structured_output` --- libs/core/langchain_core/prompts/structured.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/core/langchain_core/prompts/structured.py b/libs/core/langchain_core/prompts/structured.py index 2f6a48c301..82388bccc9 100644 --- a/libs/core/langchain_core/prompts/structured.py +++ b/libs/core/langchain_core/prompts/structured.py @@ -118,10 +118,19 @@ class StructuredPrompt(ChatPromptTemplate): if isinstance(other, BaseLanguageModel) or hasattr( other, "with_structured_output" ): - return RunnableSequence(self, other.with_structured_output(self.schema_)) + try: + return RunnableSequence( + self, other.with_structured_output(self.schema_) + ) + except NotImplementedError as e: + raise NotImplementedError( + "Structured prompts must be piped to a language model that " + "implements with_structured_output." + ) from e else: raise NotImplementedError( - "Structured prompts need to be piped to a language model." + "Structured prompts must be piped to a language model that " + "implements with_structured_output." ) def pipe(