diff --git a/src/backend/base/langflow/inputs/inputs.py b/src/backend/base/langflow/inputs/inputs.py index 48e0c0649..e72366756 100644 --- a/src/backend/base/langflow/inputs/inputs.py +++ b/src/backend/base/langflow/inputs/inputs.py @@ -37,20 +37,34 @@ class TableInput(BaseInputMixin, MetadataTraceMixin, TableMixin, ListableInputMi @field_validator("value") @classmethod def validate_value(cls, v: Any, _info): - # Check if value is a list of dicts + # Convert single dict or Data instance into a list. + if isinstance(v, dict | Data): + v = [v] + # Automatically convert DataFrame into a list of dictionaries. if isinstance(v, DataFrame): v = v.to_dict(orient="records") + # Verify the value is now a list. if not isinstance(v, list): - msg = f"TableInput value must be a list of dictionaries or Data. Value '{v}' is not a list." - raise ValueError(msg) # noqa: TRY004 - - for item in v: + msg = ( + "The table input must be a list of rows. You provided a " + f"{type(v).__name__}, which cannot be converted to table format. " + "Please provide your data as either:\n" + "- A list of dictionaries (each dict is a row)\n" + "- A pandas DataFrame\n" + "- A single dictionary (will become a one-row table)\n" + "- A Data object (Langflow's internal data structure)\n" + ) + raise ValueError(msg) # noqa: TRY004 Pydantic only catches ValueError or AssertionError + # Ensure each item in the list is either a dict or a Data instance. + for i, item in enumerate(v): if not isinstance(item, dict | Data): msg = ( - "TableInput value must be a list of dictionaries or Data. " - f"Item '{item}' is not a dictionary or Data." + f"Row {i + 1} in your table has an invalid format. Each row must be either:\n" + "- A dictionary containing column name/value pairs\n" + "- A Data object (Langflow's internal data structure for passing data between components)\n" + f"Instead, got a {type(item).__name__}. Please check the format of your input data." ) - raise ValueError(msg) # noqa: TRY004 + raise ValueError(msg) # noqa: TRY004 Pydantic only catches ValueError or AssertionError return v