From f454e9546110e5b5a30be9d2a98f747c9b76a217 Mon Sep 17 00:00:00 2001 From: JanHorcicka <49922794+JanHorcicka@users.noreply.github.com> Date: Fri, 12 Jan 2024 06:26:45 +0100 Subject: [PATCH] langchain: fix OutputParserException (#15914) (#15916) **Description:** Fixes OutputParserException thrown by the output_parser when 'query' is 'Null'. Replace this entire comment with: - **Description:** Current implentation of output_parser throws OutputParserException if the response from the LLM contains `query: null`. This unfortunately happens for my use case. And since there is no way to modify the prompt used in SelfQueryRetriever, then we have to fix it here, so it doesn't crash. - **Issue:** https://github.com/langchain-ai/langchain/issues/15914 Didn't run tests. `make test` is not working. There is no `test` rule in the `Makefile`. Co-authored-by: Jan Horcicka --- libs/langchain/langchain/chains/query_constructor/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain/langchain/chains/query_constructor/base.py b/libs/langchain/langchain/chains/query_constructor/base.py index d6c38d5319d..ecbffe18163 100644 --- a/libs/langchain/langchain/chains/query_constructor/base.py +++ b/libs/langchain/langchain/chains/query_constructor/base.py @@ -48,7 +48,7 @@ class StructuredQueryOutputParser(BaseOutputParser[StructuredQuery]): expected_keys = ["query", "filter"] allowed_keys = ["query", "filter", "limit"] parsed = parse_and_check_json_markdown(text, expected_keys) - if len(parsed["query"]) == 0: + if parsed["query"] is None or len(parsed["query"]) == 0: parsed["query"] = " " if parsed["filter"] == "NO_FILTER" or not parsed["filter"]: parsed["filter"] = None