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-2975 [FIX] Normalise agentic prompt studio response (#1766)
harini-venkataraman5f8d9f8f8244
diff --git a/tools/structure/src/constants.py b/tools/structure/src/constants.pyindex b4944e3f8..8da6a5701 100644--- a/tools/structure/src/constants.py+++ b/tools/structure/src/constants.py@@ -81,6 +81,7 @@ class SettingsKeys:IS_DIRECTORY_MODE = "is_directory_mode"LLM_PROFILE_ID = "llm_profile_id"CUSTOM_DATA = "custom_data"+ OUTPUT = "output" # For API deployment response format compatibilityclass IndexingConstants:diff --git a/tools/structure/src/main.py b/tools/structure/src/main.pyindex 2ff293985..f68143a6c 100644--- a/tools/structure/src/main.py+++ b/tools/structure/src/main.py@@ -654,10 +654,8 @@ class StructureTool(BaseTool):self.stream_log("Calling agentic extraction endpoint...")extraction_response = responder.agentic_extraction(payload=payload)- # Step 4: Transform response to match expected structure- # Cloud endpoint returns: {document_id, extracted_data, highlights, highlight_data, ...}- # We need: {data: {...}, metadata: {...}}- extracted_data = extraction_response.get("extracted_data", {})+ # Step 4: Process response from agentic extraction+ extracted_data = extraction_response.get(SettingsKeys.OUTPUT, {})# Remove _source_refs from extracted datatry:@@ -667,11 +665,12 @@ class StructureTool(BaseTool):f"Warning: Failed to remove _source_refs: {e}. ""Proceeding with original data.")- # Continue with original extracted_data if removal fails+ # Build final structured output in prompt studio formatstructured_output = {- "data": extracted_data,+ SettingsKeys.OUTPUT: extracted_data,SettingsKeys.METADATA: {+ **extraction_response.get(SettingsKeys.METADATA, {}),SettingsKeys.FILE_NAME: self.source_file_name,"project_id": project_id,"schema_version": schema_version,@@ -679,16 +678,6 @@ class StructureTool(BaseTool):"document_id": self.file_execution_id,},}-- # Add highlight data if available- if "highlights" in extraction_response:- structured_output["highlights"] = extraction_response["highlights"]- if "highlight_data" in extraction_response:- structured_output["highlight_data"] = extraction_response[- "highlight_data"- ]-- # Update GUI with resultsoutput_log = (f"## Agentic Extraction Complete\n"f"Successfully extracted data from '{self.source_file_name}'\n"