LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
UN-2566 [FIX] JSON array wrapping fix (#1411)
Deepak K89f6e3dc3edd
diff --git a/prompt-service/src/unstract/prompt_service/services/answer_prompt.py b/prompt-service/src/unstract/prompt_service/services/answer_prompt.pyindex be9b84f9b..1094dc865 100644--- a/prompt-service/src/unstract/prompt_service/services/answer_prompt.py+++ b/prompt-service/src/unstract/prompt_service/services/answer_prompt.py@@ -255,7 +255,10 @@ class AnswerPromptService:# Heuristic: if wrapping only added '[' and ']', len(b) - len(a) == 2 → original was valid, use 'a'# Otherwise, fallback to 'b' which likely fixed multiple items or invalid top-level structure- parsed_data = a if len(json.dumps(b)) - len(json.dumps(a)) == 2 else b+ dump_a = json.dumps(a, ensure_ascii=False)+ dump_b = json.dumps(b, ensure_ascii=False)+ ARRAY_WRAP_DELTA = 2 # '[' and ']'+ parsed_data = a if len(dump_b) - len(dump_a) == ARRAY_WRAP_DELTA else bif isinstance(parsed_data, str):err_msg = "Error parsing response (to json)\n" f"Candidate JSON: {answer}"