LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
fix: Defined enable_challenge in prompt-service for error handling (#1111)
Chandrasekharan Mcc56b29d4a28
diff --git a/prompt-service/src/unstract/prompt_service/main.py b/prompt-service/src/unstract/prompt_service/main.pyindex af34d5f82..4cbcfa247 100644--- a/prompt-service/src/unstract/prompt_service/main.py+++ b/prompt-service/src/unstract/prompt_service/main.py@@ -101,6 +101,7 @@ def prompt_processor() -> Any:if not payload:raise NoPayloadErrortool_settings = payload.get(PSKeys.TOOL_SETTINGS, {})+ enable_challenge = tool_settings.get(PSKeys.ENABLE_CHALLENGE, False)# TODO: Rename "outputs" to "prompts" in payloadprompts = payload.get(PSKeys.OUTPUTS, [])tool_id: str = payload.get(PSKeys.TOOL_ID, "")@@ -277,7 +278,6 @@ def prompt_processor() -> Any:metadata=metadata,execution_source=execution_source,)- # TODO: Handle metrics for line-item extractioncontinueexcept APIError as e:app.logger.error(@@ -494,12 +494,24 @@ def prompt_processor() -> Any:)structured_output[output[PSKeys.NAME]] = json.loads(answer)except JSONDecodeError as e:- app.logger.info(- f"JSON format error : {answer}", LogLevel.ERROR+ err_msg = (+ f"Error parsing response (to json): {e}\n"+ f"Candidate JSON: {answer}")- app.logger.info(- f"Error parsing response (to json): {e}",- LogLevel.ERROR,+ app.logger.info(err_msg, LogLevel.ERROR)+ # TODO: Format log message after unifying these types+ publish_log(+ log_events_id,+ {+ "tool_id": tool_id,+ "prompt_key": prompt_name,+ "doc_name": doc_name,+ },+ LogLevel.INFO,+ RunLevel.RUN,+ "Unable to parse JSON response from LLM, try using our"+ " cloud / enterprise feature of 'line-item', "+ "'record' or 'table' type",)structured_output[output[PSKeys.NAME]] = {}@@ -512,7 +524,6 @@ def prompt_processor() -> Any:output[PSKeys.NAME]].rstrip("\n")- enable_challenge = tool_settings.get(PSKeys.ENABLE_CHALLENGE)# Challenge conditionif enable_challenge:challenge_plugin: dict[str, Any] = plugins.get(PSKeys.CHALLENGE, {})diff --git a/unstract/core/src/unstract/core/utilities.py b/unstract/core/src/unstract/core/utilities.pyindex 34d5c1729..5c1a7c523 100644--- a/unstract/core/src/unstract/core/utilities.py+++ b/unstract/core/src/unstract/core/utilities.py@@ -41,6 +41,7 @@ class UnstractUtils:if len(container_name) > 63:logger.warning(f"Container name exceeds 63 char limit for '{container_name}', "- "truncating to 63 chars. There might be collisions in container names"+ "truncating to 63 chars. There might be collisions in container names."+ f"Truncated container name: {container_name[:63]}")return container_name[:63]