diff --git a/src/backend/base/langflow/api/utils.py b/src/backend/base/langflow/api/utils.py index 652b0e27e..a87bd2e81 100644 --- a/src/backend/base/langflow/api/utils.py +++ b/src/backend/base/langflow/api/utils.py @@ -1,6 +1,7 @@ from __future__ import annotations import uuid +from ast import literal_eval from datetime import timedelta from enum import Enum from typing import TYPE_CHECKING, Annotated, Any @@ -280,11 +281,18 @@ def get_suggestion_message(outdated_components: list[str]) -> str: def parse_value(value: Any, input_type: str) -> Any: """Helper function to parse the value based on input type.""" if value == "": - return value + return {} if input_type == "DictInput" else value if input_type == "IntInput": return int(value) if value is not None else None if input_type == "FloatInput": return float(value) if value is not None else None + if input_type == "DictInput": + if isinstance(value, dict): + return value + try: + return literal_eval(value) if value is not None else {} + except (ValueError, SyntaxError): + return {} return value diff --git a/src/backend/base/langflow/inputs/inputs.py b/src/backend/base/langflow/inputs/inputs.py index c10171906..1bc32c18c 100644 --- a/src/backend/base/langflow/inputs/inputs.py +++ b/src/backend/base/langflow/inputs/inputs.py @@ -458,7 +458,9 @@ class DictInput(BaseInputMixin, ListableInputMixin, InputTraceMixin, ToolModeMix """ field_type: SerializableFieldTypes = FieldTypes.DICT - value: dict | None = {} + # Note do not set value to an empty dict, it will break the component in dynamic update build config + # value: dict | None = {} + value: dict = Field(default_factory=dict) class DropdownInput(BaseInputMixin, DropDownMixin, MetadataTraceMixin, ToolModeMixin):