diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 0b6f0a732..06a4f4d7c 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -2,6 +2,7 @@ from typing import Any, Callable, List, Optional from fastapi import HTTPException from langflow.interface.custom.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES from langflow.interface.custom.component import Component +from langflow.interface.custom.directory_reader import DirectoryReader from langflow.utils import validate @@ -38,12 +39,18 @@ class CustomComponent(Component, extra=Extra.allow): }, ) - # TODO: Create the logic to validate what the Custom Component - # should have as a prerequisite to be able to execute - return True + reader = DirectoryReader("", False) + if reader.is_type_hint_used_but_not_imported("Optional", code): + raise HTTPException( + status_code=400, + detail={ + "error": "Type hint Error", + "traceback": "Name type hint 'Optional' is not defined", + }, + ) def is_check_valid(self) -> bool: - return self._class_template_validation(self.code) if self.code else False + return self._class_template_validation(self.code) def get_code_tree(self, code: str): return super().get_code_tree(code) diff --git a/src/backend/langflow/interface/custom/directory_reader.py b/src/backend/langflow/interface/custom/directory_reader.py index d24dbd1ab..2f448e319 100644 --- a/src/backend/langflow/interface/custom/directory_reader.py +++ b/src/backend/langflow/interface/custom/directory_reader.py @@ -196,7 +196,7 @@ class DirectoryReader: elif not self.validate_build(file_content): return False, "Missing build function" elif self.is_type_hint_used_but_not_imported("Optional", file_content): - return False, "Name hint type 'Optional' is not defined" + return False, "Name type hint 'Optional' is not defined" else: if self.compress_code_field: file_content = str(StringCompressor(file_content).compress_string())