Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

[FIX] JSON object structure (#1291)

Deepak K7d92db7b4ae9
diff --git a/prompt-service/src/unstract/prompt_service/services/answer_prompt.py b/prompt-service/src/unstract/prompt_service/services/answer_prompt.py
index a89b6b471..0edef84d4 100644
--- a/prompt-service/src/unstract/prompt_service/services/answer_prompt.py
+++ b/prompt-service/src/unstract/prompt_service/services/answer_prompt.py
@@ -154,7 +154,7 @@ class AnswerPromptService:
completion = llm.complete(
prompt=prompt,
process_text=highlight_data,
- extract_json=prompt_type.lower() != PSKeys.JSON,
+ extract_json=False,
)
answer: str = completion[PSKeys.RESPONSE].text
highlight_data = completion.get(PSKeys.HIGHLIGHT_DATA, [])
@@ -247,6 +247,7 @@ class AnswerPromptService:
structured_output=structured_output,
answer=answer,
).run()
+ answer = AnswerPromptService.slice_from_first_bracket(answer)
if enable_highlight:
AnswerPromptService.handle_highlight(
execution_source=execution_source,
@@ -313,3 +314,13 @@ class AnswerPromptService:
if PSKeys.CONFIDENCE_DATA not in metadata:
metadata[PSKeys.CONFIDENCE_DATA] = {}
metadata[PSKeys.CONFIDENCE_DATA][prompt_key] = confidence_data
+
+ @staticmethod
+ def slice_from_first_bracket(text: str) -> str:
+ idx_brace = text.find("{")
+ idx_bracket = text.find("[")
+ indices = [i for i in [idx_brace, idx_bracket] if i != -1]
+ if not indices:
+ return text
+ start = min(indices)
+ return text[start:]