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/workflow issues (#114)
vishnuszipstack83ef370d2d4b
diff --git a/backend/tool_instance/tool_instance_helper.py b/backend/tool_instance/tool_instance_helper.pyindex c0d07fab2..dbd11d52f 100644--- a/backend/tool_instance/tool_instance_helper.py+++ b/backend/tool_instance/tool_instance_helper.py@@ -1,16 +1,19 @@import loggingimport osimport uuid+from json import JSONDecodeErrorfrom typing import Any, Optionalfrom account.models import Userfrom adapter_processor.adapter_processor import AdapterProcessorfrom adapter_processor.models import AdapterInstancefrom connector.connector_instance_helper import ConnectorInstanceHelper+from jsonschema import ValidationErrorfrom tool_instance.constants import JsonSchemaKeyfrom tool_instance.models import ToolInstancefrom tool_instance.tool_processor import ToolProcessorfrom unstract.adapters.enums import AdapterTypes+from unstract.sdk.tool.validator import DefaultsGeneratingValidatorfrom unstract.tool_registry.constants import AdapterPropertyKeyfrom unstract.tool_registry.dto import Spec, Toolfrom unstract.tool_registry.tool_utils import ToolUtils@@ -328,3 +331,20 @@ class ToolInstanceHelper:tool_instance = ToolInstance.objects.get(pk=tool_instance_id)tool_instance.step = step + 1tool_instance.save()++ @staticmethod+ def validate_tool_settings(+ tool_uid: str, tool_meta: dict[str, Any]+ ) -> tuple[bool, str]:+ """Function to validate Tools settings."""++ schema_json: dict[str, Any] = ToolProcessor.get_tool_settings(+ tool_uid=tool_uid+ )+ try:+ DefaultsGeneratingValidator(schema_json).validate(tool_meta)+ return True, ""+ except JSONDecodeError as e:+ return False, str(e)+ except ValidationError as e:+ return False, str(e.schema["description"])diff --git a/backend/tool_instance/tool_processor.py b/backend/tool_instance/tool_processor.pyindex 091922ff0..ab9f04a76 100644--- a/backend/tool_instance/tool_processor.py+++ b/backend/tool_instance/tool_processor.py@@ -61,6 +61,14 @@ class ToolProcessor:schema_json: dict[str, Any] = schema.to_dict()return schema_json+ @staticmethod+ def get_tool_settings(tool_uid: str) -> dict[str, str]:+ """Function to get Tools settings."""+ tool: Tool = ToolProcessor.get_tool_by_uid(tool_uid=tool_uid)+ schema: Spec = ToolUtils.get_json_schema_for_tool(tool)+ schema_json: dict[str, Any] = schema.to_dict()+ return schema_json+@staticmethoddef update_schema_with_adapter_configurations(schema: Spec, user: Userdiff --git a/backend/workflow_manager/workflow/exceptions.py b/backend/workflow_manager/workflow/exceptions.pyindex 0e267f69b..94422b07b 100644--- a/backend/workflow_manager/workflow/exceptions.py+++ b/backend/workflow_manager/workflow/exceptions.py@@ -69,3 +69,8 @@ class WorkflowExecutionBadRequestException(APIException):if code is not None:self.code = codesuper().__init__(detail, code)+++class ToolValidationError(APIException):+ status_code = 400+ default_detail = "Tool validation error"\ No newline at end of filediff --git a/backend/workflow_manager/workflow/workflow_helper.py b/backend/workflow_manager/workflow/workflow_helper.pyindex e0568b8da..7cbc7cdfd 100644--- a/backend/workflow_manager/workflow/workflow_helper.py+++ b/backend/workflow_manager/workflow/workflow_helper.py@@ -38,6 +38,7 @@ from workflow_manager.workflow.enums import (from workflow_manager.workflow.exceptions import (InvalidRequest,TaskDoesNotExistError,+ ToolValidationError,WorkflowDoesNotExistError,WorkflowExecutionNotExist,)@@ -190,6 +191,17 @@ class WorkflowHelper:LogComponent.DESTINATION,)+ @staticmethod+ def validate_tool_instances_meta(+ tool_instances: list[ToolInstance],+ ) -> None:+ for tool in tool_instances:+ valid, message = ToolInstanceHelper.validate_tool_settings(+ tool_uid=tool.tool_id, tool_meta=tool.metadata+ )+ if not valid:+ raise ToolValidationError(message)+@staticmethoddef run_workflow(workflow: Workflow,@@ -206,6 +218,10 @@ class WorkflowHelper:] = ToolInstanceHelper.get_tool_instances_by_workflow(workflow.id, ToolInstanceKey.STEP)++ WorkflowHelper.validate_tool_instances_meta(+ tool_instances=tool_instances+ )execution_mode = execution_mode or WorkflowExecution.Mode.INSTANTexecution_service = WorkflowHelper.build_workflow_execution_service(organization_id=organization_id,diff --git a/frontend/src/components/agency/cards-list/CardsList.jsx b/frontend/src/components/agency/cards-list/CardsList.jsxindex f13478388..3e2ee2fac 100644--- a/frontend/src/components/agency/cards-list/CardsList.jsx+++ b/frontend/src/components/agency/cards-list/CardsList.jsx@@ -127,12 +127,7 @@ const CardsList = ({ step, index, activeTool, moveItem }) => {</Typography.Text></div><div className="wf-step-card-progress display-flex-center">- <Progress- type="circle"- percent={step?.progress === "SUCCESS" ? 100 : 0}- size="small"- format={() => index + 1}- />+ <Progress type="circle" size="small" format={() => index + 1} /></div></div></Col>