Skip to content

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

fix: Platform service err orhandling change to print traceback during errors (#805)

Chandrasekharan M37d33cd06c6e
diff --git a/backend/prompt_studio/prompt_studio_core_v2/views.py b/backend/prompt_studio/prompt_studio_core_v2/views.py
index f5437a304..9a5d08a36 100644
--- a/backend/prompt_studio/prompt_studio_core_v2/views.py
+++ b/backend/prompt_studio/prompt_studio_core_v2/views.py
@@ -358,6 +358,7 @@ class PromptStudioCoreView(viewsets.ModelViewSet):
)
return Response(serializer.data, status=status.HTTP_201_CREATED)
+ # TODO: Move to prompt_profile_manager app and move validation to serializer
@action(detail=True, methods=["post"])
def create_profile_manager(self, request: HttpRequest, pk: Any = None) -> Response:
context = super().get_serializer_context()
diff --git a/frontend/src/components/custom-tools/add-llm-profile/AddLlmProfile.jsx b/frontend/src/components/custom-tools/add-llm-profile/AddLlmProfile.jsx
index 81871abdb..d1c72e1b0 100644
--- a/frontend/src/components/custom-tools/add-llm-profile/AddLlmProfile.jsx
+++ b/frontend/src/components/custom-tools/add-llm-profile/AddLlmProfile.jsx
@@ -237,7 +237,7 @@ function AddLlmProfile({
setAlertDetails(
handleException(
err,
- "Failed to get the dropdown list for LLM Adaptors"
+ "Failed to get the dropdown list for LLM Adapters"
)
);
});
diff --git a/platform-service/src/unstract/platform_service/controller/platform.py b/platform-service/src/unstract/platform_service/controller/platform.py
index fb00d4b2d..eb0ef3718 100644
--- a/platform-service/src/unstract/platform_service/controller/platform.py
+++ b/platform-service/src/unstract/platform_service/controller/platform.py
@@ -354,9 +354,6 @@ def cache() -> Any:
"""
bearer_token = get_token_from_auth_header(request)
_, account_id = get_organization_from_bearer_token(bearer_token)
- if not Env.REDIS_HOST:
- app.logger.error("Env.REDIS_HOST not set")
- return "Internal Server Error", 500
if request.method == "POST":
payload: Optional[dict[Any, Any]] = request.json
if not payload:
@@ -376,8 +373,7 @@ def cache() -> Any:
r.set(redis_key, value)
r.close()
except Exception as e:
- app.logger.error(f"Error while caching data: {e}")
- return "Internal Server Error", 500
+ raise APIError(message=f"Error while caching data: {e}") from e
elif request.method == "GET":
key = request.args.get("key")
try:
@@ -396,8 +392,7 @@ def cache() -> Any:
else:
return value, 200
except Exception as e:
- app.logger.error(f"Error while getting cached data: {e}")
- return "Internal Server Error", 500
+ raise APIError(message=f"Error while getting cached data: {e}") from e
elif request.method == "DELETE":
key = request.args.get("key")
try:
@@ -413,8 +408,9 @@ def cache() -> Any:
r.close()
return "OK", 200
except Exception as e:
- app.logger.error(f"Error while deleting cached data: {e}")
- return "Internal Server Error", 500
+ raise APIError(message=f"Error while deleting cached data: {e}") from e
+ else:
+ raise APIError(message="Method Not Allowed", code=405)
return "OK", 200
@@ -438,41 +434,39 @@ def adapter_instance() -> Any:
if not organization_id:
return Env.INVALID_ORGANIZATOIN, 403
- if request.method == "GET":
- adapter_instance_id = request.args.get("adapter_instance_id")
+ adapter_instance_id = request.args.get("adapter_instance_id")
- try:
- data_dict = AdapterInstanceRequestHelper.get_adapter_instance_from_db(
- organization_id=organization_id,
- adapter_instance_id=adapter_instance_id,
- organization_uid=organization_uid,
- )
+ try:
+ data_dict = AdapterInstanceRequestHelper.get_adapter_instance_from_db(
+ organization_id=organization_id,
+ adapter_instance_id=adapter_instance_id,
+ organization_uid=organization_uid,
+ )
- f: Fernet = Fernet(Env.ENCRYPTION_KEY.encode("utf-8"))
+ f: Fernet = Fernet(Env.ENCRYPTION_KEY.encode("utf-8"))
- data_dict["adapter_metadata"] = json.loads(
- f.decrypt(bytes(data_dict.pop("adapter_metadata_b")).decode("utf-8"))
- )
+ data_dict["adapter_metadata"] = json.loads(
+ f.decrypt(bytes(data_dict.pop("adapter_metadata_b")).decode("utf-8"))
+ )
- return jsonify(data_dict)
- except InvalidToken:
- msg = (
- "Platform encryption key for storing adapter credentials has "
- "changed! All adapters are inaccessible. Please inform "
- "the platform admin immediately."
- )
- app.logger.error(
- f"Error while getting db adapter settings for: "
- f"{adapter_instance_id}, Error: {msg}"
- )
- raise APIError(message=msg, code=403)
- except Exception as e:
- app.logger.error(
- f"Error while getting db adapter settings for: "
- f"{adapter_instance_id}, Error: {str(e)}"
- )
- return "Internal Server Error", 500
- return "Method Not Allowed", 405
+ return jsonify(data_dict)
+ except InvalidToken:
+ msg = (
+ "Platform encryption key for storing adapter credentials has "
+ "changed! All adapters are inaccessible. Please inform "
+ "the platform admin immediately."
+ )
+ app.logger.error(
+ f"Error while getting db adapter settings for: "
+ f"{adapter_instance_id}, Error: {msg}"
+ )
+ raise APIError(message=msg, code=403)
+ except Exception as e:
+ msg = (
+ f"Error while getting db adapter settings for "
+ f"{adapter_instance_id}: {e}"
+ )
+ raise APIError(message=msg)
@platform_bp.route(
@@ -494,19 +488,17 @@ def custom_tool_instance() -> Any:
if not organization_id:
return Env.INVALID_ORGANIZATOIN, 403
- if request.method == "GET":
- prompt_registry_id = request.args.get("prompt_registry_id")
+ prompt_registry_id = request.args.get("prompt_registry_id")
- try:
- data_dict = PromptStudioRequestHelper.get_prompt_instance_from_db(
- organization_id=organization_id,
- prompt_registry_id=prompt_registry_id,
- )
- return jsonify(data_dict)
- except Exception as e:
- app.logger.error(
- f"Error while getting db adapter settings for: "
- f"{prompt_registry_id} Error: {str(e)}"
- )
- return "Internal Server Error", 500
- return "Method Not Allowed", 405
+ try:
+ data_dict = PromptStudioRequestHelper.get_prompt_instance_from_db(
+ organization_id=organization_id,
+ prompt_registry_id=prompt_registry_id,
+ )
+ return jsonify(data_dict)
+ except Exception as e:
+ msg = (
+ f"Error while getting data for Prompt Studio project "
+ f"{prompt_registry_id}: {e}"
+ )
+ raise APIError(message=msg) from e
diff --git a/platform-service/src/unstract/platform_service/exceptions.py b/platform-service/src/unstract/platform_service/exceptions.py
index 97832719c..a67f0a14e 100644
--- a/platform-service/src/unstract/platform_service/exceptions.py
+++ b/platform-service/src/unstract/platform_service/exceptions.py
@@ -3,7 +3,7 @@ from typing import Any, Optional
from werkzeug.exceptions import HTTPException
-DEFAULT_ERR_MESSAGE = "Something went wrong"
+DEFAULT_ERR_MESSAGE = "Error from platform service"
@dataclass
diff --git a/prompt-service/src/unstract/prompt_service/exceptions.py b/prompt-service/src/unstract/prompt_service/exceptions.py
index e8f2d6c63..b7e898254 100644
--- a/prompt-service/src/unstract/prompt_service/exceptions.py
+++ b/prompt-service/src/unstract/prompt_service/exceptions.py
@@ -3,7 +3,7 @@ from typing import Any, Optional
from werkzeug.exceptions import HTTPException
-DEFAULT_ERR_MESSAGE = "Something went wrong"
+DEFAULT_ERR_MESSAGE = "Error from prompt service"
@dataclass