From 9dade0ad5a71faef0d4b0bce06fa95caaa4fdf17 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 26 Jun 2025 17:18:23 +0800 Subject: [PATCH] refactor: improve parsing logic in structured output parser - Updated the logic for handling lists in the parsing process to ensure only dictionary items are considered, enhancing robustness. - Maintained existing functionality while improving the clarity and reliability of the output parsing. --- api/core/llm_generator/output_parser/structured_output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/core/llm_generator/output_parser/structured_output.py b/api/core/llm_generator/output_parser/structured_output.py index a4d8ff598c..ae829eeb48 100644 --- a/api/core/llm_generator/output_parser/structured_output.py +++ b/api/core/llm_generator/output_parser/structured_output.py @@ -250,7 +250,7 @@ def _parse_structured_output(result_text: str) -> Mapping[str, Any]: if not isinstance(temp_parsed, dict): # handle reasoning model like deepseek-r1 got '\n\n\n' prefix if isinstance(temp_parsed, list): - temp_parsed = next((item for item in parsed if isinstance(item, dict)), {}) + temp_parsed = next((item for item in temp_parsed if isinstance(item, dict)), {}) else: raise OutputParserError(f"Failed to parse structured output: {result_text}") structured_output = cast(dict, temp_parsed)