LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
[FEAT] Tool Export Validation (#299)
harini-venkataramane28fd0331723
diff --git a/backend/prompt_studio/prompt_studio_registry/exceptions.py b/backend/prompt_studio/prompt_studio_registry/exceptions.pyindex 038878cb2..12a182991 100644--- a/backend/prompt_studio/prompt_studio_registry/exceptions.py+++ b/backend/prompt_studio/prompt_studio_registry/exceptions.py@@ -14,3 +14,19 @@ class ToolDoesNotExist(APIException):class ToolSaveError(APIException):status_code = 500default_detail = "Error while saving the tool."+++class EmptyToolExportError(APIException):+ status_code = 500+ default_detail = (+ "Empty Prompt Studio project without prompts cannot be exported. "+ "Try adding a prompt and executing it."+ )+++class InValidCustomToolError(APIException):+ status_code = 500+ default_detail = (+ "This prompt studio project cannot be exported. It probably "+ "has some empty or unexecuted prompts."+ )diff --git a/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.py b/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.pyindex 00d4addb9..4b8ecfc2e 100644--- a/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.py+++ b/backend/prompt_studio/prompt_studio_registry/prompt_studio_registry_helper.py@@ -8,10 +8,16 @@ from prompt_studio.prompt_profile_manager.models import ProfileManagerfrom prompt_studio.prompt_studio.models import ToolStudioPromptfrom prompt_studio.prompt_studio_core.models import CustomToolfrom prompt_studio.prompt_studio_core.prompt_studio_helper import PromptStudioHelper+from prompt_studio.prompt_studio_output_manager.models import PromptStudioOutputManagerfrom unstract.tool_registry.dto import Properties, Spec, Toolfrom .constants import JsonSchemaKey-from .exceptions import InternalError, ToolSaveError+from .exceptions import (+ EmptyToolExportError,+ InternalError,+ InValidCustomToolError,+ ToolSaveError,+)from .models import PromptStudioRegistryfrom .serializers import PromptStudioRegistrySerializer@@ -173,6 +179,12 @@ class PromptStudioRegistryHelper:grammer_dict = {}outputs: list[dict[str, Any]] = []output: dict[str, Any] = {}+ invalidated_prompts: list[str] = []+ invalidated_outputs: list[str] = []++ if not prompts:+ raise EmptyToolExportError()+if prompt_grammer:for word, synonyms in prompt_grammer.items():synonyms = prompt_grammer[word]@@ -194,6 +206,21 @@ class PromptStudioRegistryHelper:default_llm_profile = ProfileManager.get_default_llm_profile(tool)for prompt in prompts:++ if not prompt.prompt:+ invalidated_prompts.append(prompt.prompt_key)+ continue++ prompt_output = PromptStudioOutputManager.objects.filter(+ tool_id=tool.tool_id,+ prompt_id=prompt.prompt_id,+ profile_manager=prompt.profile_manager,+ ).all()++ if not prompt_output:+ invalidated_outputs.append(prompt.prompt_key)+ continue+if prompt.prompt_type == JsonSchemaKey.NOTES:continueif not prompt.profile_manager:@@ -241,6 +268,17 @@ class PromptStudioRegistryHelper:llm = ""embedding_model = ""+ if invalidated_prompts:+ raise InValidCustomToolError(+ f"Cannot export tool. Prompt(s) : {invalidated_prompts} "+ "are not valid. Please enter a valid prompt."+ )+ if invalidated_outputs:+ raise InValidCustomToolError(+ f"Cannot export tool. Prompt(s) : {invalidated_outputs} "+ "were not run. Please run them before exporting."+ )+export_metadata[JsonSchemaKey.OUTPUTS] = outputsreturn export_metadata