LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Added global error handler for prompt-service (#255)
Deepak K5e4c8d067d13
diff --git a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.pyindex 8c9bccb7e..0f137abec 100644--- a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py+++ b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py@@ -782,7 +782,7 @@ class PromptStudioHelper:answer = responder.single_pass_extraction(payload)# TODO: Make use of dataclassesif answer["status"] == "ERROR":- error_message = answer.get("error", "")+ error_message = answer.get("error", None)raise AnswerFetchError(error_message)output_response = json.loads(answer["structure_output"])return output_responsediff --git a/prompt-service/src/unstract/prompt_service/main.py b/prompt-service/src/unstract/prompt_service/main.pyindex 63bd294a9..c345802da 100644--- a/prompt-service/src/unstract/prompt_service/main.py+++ b/prompt-service/src/unstract/prompt_service/main.py@@ -1,10 +1,9 @@-import jsonimport loggingfrom enum import Enumfrom typing import Any, Optionalimport peewee-from flask import Flask, request+from flask import Flask, json, requestfrom llama_index import VectorStoreIndexfrom llama_index.llms import LLMfrom llama_index.vector_stores.types import ExactMatchFilter, MetadataFilters@@ -23,6 +22,7 @@ from unstract.sdk.utils.service_context import (ServiceContext as UNServiceContext,)from unstract.sdk.vector_db import ToolVectorDB+from werkzeug.exceptions import HTTPExceptionfrom unstract.core.pubsub_helper import LogPublisher@@ -770,6 +770,21 @@ def enable_single_pass_extraction() -> None:enable_single_pass_extraction()[email protected](HTTPException)+def handle_exception(e):+ """Return JSON instead of HTML for HTTP errors."""+ response = e.get_response()+ response.data = json.dumps(+ {+ "code": e.code,+ "name": e.name,+ "error": e.description,+ }+ )+ response.content_type = "application/json"+ return response++if __name__ == "__main__":# Start the serverapp.run(host="0.0.0.0", port=5003)