From 4e13c7352dcf0ce46b9cee4fe28c611f54c595e3 Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Fri, 14 Jun 2024 16:11:23 -0300 Subject: [PATCH] refactor: Improve value validation in TextInput --- src/backend/base/langflow/inputs/inputs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/inputs/inputs.py b/src/backend/base/langflow/inputs/inputs.py index edbf3f55a..79a5e72ac 100644 --- a/src/backend/base/langflow/inputs/inputs.py +++ b/src/backend/base/langflow/inputs/inputs.py @@ -47,13 +47,14 @@ class TextInput(StrInput): @field_validator("value") @classmethod def validate_value(cls, v: Any, _info): + value = None if isinstance(v, str): - return v + value = v elif isinstance(v, Message): - return v.text + value = v.text elif isinstance(v, Data): if v.text_key in v.data: - return v.data[v.text_key] + value = v.data[v.text_key] else: keys = ", ".join(v.data.keys()) input_name = _info.data["name"] @@ -63,6 +64,9 @@ class TextInput(StrInput): ) else: raise ValueError(f"Invalid input type {type(v)}") + if isinstance(value, str): + return value + raise ValueError(f"Invalid value type {type(value)}") class MultilineInput(BaseInputMixin):