Skip to content

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

UN-2606 [FIX] Error handling in deploy as API from prompt studio (#1444)

jagadeeswaran-zipstack7f7493ce4d5b
diff --git a/backend/api_v2/serializers.py b/backend/api_v2/serializers.py
index 763fb3e65..2fc9b26fa 100644
--- a/backend/api_v2/serializers.py
+++ b/backend/api_v2/serializers.py
@@ -19,6 +19,7 @@ from rest_framework.serializers import (
)
from tags.serializers import TagParamsSerializer
from utils.serializer.integrity_error_mixin import IntegrityErrorMixin
+from workflow_manager.endpoint_v2.models import WorkflowEndpoint
from workflow_manager.workflow_v2.exceptions import ExecutionDoesNotExistError
from workflow_manager.workflow_v2.models.execution import WorkflowExecution
@@ -57,6 +58,70 @@ class APIDeploymentSerializer(IntegrityErrorMixin, AuditSerializer):
api_name_validator(value)
return value
+ def validate_workflow(self, workflow):
+ """Validate that the workflow has properly configured source and destination endpoints."""
+ # Get all endpoints for this workflow with related data
+ endpoints = WorkflowEndpoint.objects.filter(workflow=workflow).select_related(
+ "connector_instance"
+ )
+
+ # Check for source endpoint
+ source_endpoints = endpoints.filter(
+ endpoint_type=WorkflowEndpoint.EndpointType.SOURCE
+ )
+ if not source_endpoints.exists():
+ raise ValidationError(
+ "Workflow must have a source endpoint configured before creating an API deployment."
+ )
+
+ source_endpoint = source_endpoints.first()
+
+ # First check if connection_type is configured
+ if not source_endpoint.connection_type:
+ raise ValidationError(
+ "Source endpoint must have a connection type configured before creating an API deployment."
+ )
+
+ # For non-API connections, check if connector instance is configured
+ if source_endpoint.connection_type == WorkflowEndpoint.ConnectionType.API:
+ # API connections don't need connector instances
+ pass
+ elif not source_endpoint.connector_instance:
+ raise ValidationError(
+ "Source endpoint must have a connector configured for non-API connections before creating an API deployment."
+ )
+
+ # Check for destination endpoint
+ destination_endpoints = endpoints.filter(
+ endpoint_type=WorkflowEndpoint.EndpointType.DESTINATION
+ )
+ if not destination_endpoints.exists():
+ raise ValidationError(
+ "Workflow must have a destination endpoint configured before creating an API deployment."
+ )
+
+ destination_endpoint = destination_endpoints.first()
+
+ # First check if connection_type is configured
+ if not destination_endpoint.connection_type:
+ raise ValidationError(
+ "Destination endpoint must have a connection type configured before creating an API deployment."
+ )
+
+ # For non-API and non-manual review connections, check if connector instance is configured
+ if destination_endpoint.connection_type in [
+ WorkflowEndpoint.ConnectionType.API,
+ WorkflowEndpoint.ConnectionType.MANUALREVIEW,
+ ]:
+ # API and MANUALREVIEW connections don't need connector instances
+ pass
+ elif not destination_endpoint.connector_instance:
+ raise ValidationError(
+ "Destination endpoint must have a connector configured for non-API and non-manual review connections before creating an API deployment."
+ )
+
+ return workflow
+
def validate(self, data):
"""Validate that only one API deployment per workflow is allowed for new deployments."""
workflow = data.get("workflow")
diff --git a/frontend/src/components/deployments/create-api-deployment-from-prompt-studio/CreateApiDeploymentFromPromptStudio.jsx b/frontend/src/components/deployments/create-api-deployment-from-prompt-studio/CreateApiDeploymentFromPromptStudio.jsx
index b65630f64..be51f11ee 100644
--- a/frontend/src/components/deployments/create-api-deployment-from-prompt-studio/CreateApiDeploymentFromPromptStudio.jsx
+++ b/frontend/src/components/deployments/create-api-deployment-from-prompt-studio/CreateApiDeploymentFromPromptStudio.jsx
@@ -139,12 +139,7 @@ const CreateApiDeploymentFromPromptStudio = ({
fetchToolFunctionName();
}, 1000); // Wait 1 second for export to complete
} catch (exportErr) {
- setAlertDetails({
- type: "error",
- content: `Failed to export tool to organization: ${
- exportErr.response?.data?.message || exportErr.message
- }`,
- });
+ setAlertDetails(handleException(exportErr));
setToolSchema(null);
}
} else {
@@ -155,12 +150,7 @@ const CreateApiDeploymentFromPromptStudio = ({
setToolSchema(null);
}
} catch (err) {
- setAlertDetails({
- type: "error",
- content: `Failed to fetch tool list: ${
- err.response?.data?.message || err.message
- }`,
- });
+ setAlertDetails(handleException(err));
setToolSchema(null);
}
};
@@ -185,12 +175,7 @@ const CreateApiDeploymentFromPromptStudio = ({
} catch (err) {
// If tool schema fetch fails, it means the tool doesn't have configurable settings
// This is common for prompt studio tools that may not be in the tool registry
- setAlertDetails({
- type: "error",
- content: `Tool schema not available: ${
- err.response?.data?.message || err.message
- }`,
- });
+ setAlertDetails(handleException(err));
setToolSchema(null);
} finally {
setIsSchemaLoading(false);
@@ -233,7 +218,9 @@ const CreateApiDeploymentFromPromptStudio = ({
// Validate deployment details form
form
.validateFields()
- .then(() => {
+ .then((values) => {
+ // Update deployment details with the latest form values
+ setDeploymentDetails(values);
setCurrentStep(1);
})
.catch(() => {
@@ -390,9 +377,16 @@ const CreateApiDeploymentFromPromptStudio = ({
});
// Step 6: Create API deployment
+ // Get the latest form values to ensure we have the most up-to-date data
+ const currentFormValues = form.getFieldsValue();
+ const finalDeploymentDetails = {
+ ...deploymentDetails,
+ ...currentFormValues,
+ };
+
const apiDeploymentResponse =
await apiDeploymentsApiService.createApiDeployment({
- ...deploymentDetails,
+ ...finalDeploymentDetails,
workflow: workflowId,
});