Skip to content

Conversation

@ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Apr 2, 2025

Improve input validation for Data, DataFrame, and Message types while adding unit tests to ensure proper data conversion functionality.

Summary by CodeRabbit

  • New Features

    • Enhanced input fields to accept and seamlessly convert between multiple data types, including tables, structured data, and messages, improving flexibility for data entry and processing.
  • Bug Fixes

    • Improved validation and error handling for various input types to ensure consistent and reliable conversions.
  • Tests

    • Added comprehensive tests to verify correct input conversion, content integrity, and error handling for all supported data types.

@edwinjosechittilappilly edwinjosechittilappilly changed the base branch from main to convert_component May 29, 2025 16:09
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels May 29, 2025
Base automatically changed from convert_component to main June 2, 2025 20:28
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 2, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 2, 2025

Walkthrough

The changes expand the input type compatibility for four input classes, enabling them to interchangeably accept and convert between Data, DataFrame, and Message types. Validation and conversion methods are added or updated to ensure consistent internal representations. Comprehensive unit tests are introduced to verify these behaviors.

Changes

File(s) Change Summary
src/backend/base/langflow/inputs/inputs.py Expanded input type support and added/updated validation and conversion logic for DataInput, DataFrameInput, MessageInput, and MessageTextInput classes.
src/backend/tests/unit/io/test_data_convertion.py Added unit tests for DataInput, DataFrameInput, MessageInput, and MessageTextInput to verify type conversion and validation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InputClass
    participant Data
    participant DataFrame
    participant Message

    User->>InputClass: Provide input (Data, DataFrame, Message, dict, etc.)
    InputClass->>InputClass: Validate and convert input
    alt Input is DataFrame
        InputClass->>Data: Convert DataFrame to Data (if needed)
        InputClass->>Message: Convert DataFrame to markdown text (if needed)
    else Input is Data
        InputClass->>DataFrame: Convert Data to DataFrame (if needed)
        InputClass->>Message: Extract text or convert to string (if needed)
    else Input is Message
        InputClass->>Data: Convert Message to Data (if needed)
        InputClass->>DataFrame: Convert Message to DataFrame (if needed)
    else Input is dict
        InputClass->>Data: Convert dict to Data
        InputClass->>DataFrame: Convert dict to DataFrame
        InputClass->>Message: Convert dict to Message
    end
    InputClass-->>User: Return standardized internal representation
Loading

Possibly related PRs

Suggested labels

size:L, lgtm

Suggested reviewers

  • ogabrielluiz
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@edwinjosechittilappilly
Copy link
Collaborator

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 5, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/backend/base/langflow/inputs/inputs.py (1)

292-303: Duplicate transformation pipeline (see previous comment).

Same rationale as above – please delegate to a shared utility.

🧹 Nitpick comments (2)
src/backend/base/langflow/inputs/inputs.py (1)

237-249: Data-frame-to-markdown logic duplicated – extract a helper.

The exact same cleansing pipeline appears here and in MessageTextInput. Encapsulate it (e.g. langflow.utils.df_to_markdown(df)) to:

  • avoid divergence bugs,
  • make unit tests simpler,
  • keep inputs.py lean.

No functional breakage, but worth an internal refactor.

src/backend/tests/unit/io/test_data_convertion.py (1)

1-3: Typo in filename and module docstring – use “conversion”.

test_data_conversion.py matches conventional spelling and grepping patterns.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 2-2: No name 'inputs' in module 'langflow'

(E0611)


[error] 3-3: No name 'schema' in module 'langflow'

(E0611)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22330ab and abf7a78.

📒 Files selected for processing (2)
  • src/backend/base/langflow/inputs/inputs.py (6 hunks)
  • src/backend/tests/unit/io/test_data_convertion.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/backend/base/langflow/inputs/inputs.py (3)
src/backend/base/langflow/schema/data.py (1)
  • Data (23-275)
src/backend/base/langflow/schema/dataframe.py (1)
  • DataFrame (11-206)
src/backend/base/langflow/schema/message.py (1)
  • Message (38-288)
🪛 Pylint (3.3.7)
src/backend/tests/unit/io/test_data_convertion.py

[error] 2-2: No name 'inputs' in module 'langflow'

(E0611)


[error] 3-3: No name 'schema' in module 'langflow'

(E0611)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Optimize new Python code in this PR
  • GitHub Check: Run Ruff Check and Format
  • GitHub Check: Update Starter Projects
  • GitHub Check: Ruff Style Check (3.13)

Comment on lines +115 to +124
if isinstance(v, DataFrame):
# Convert DataFrame to a list of dictionaries and wrap in a Data object
dict_list = v.to_dict(orient="records")
return Data(data={"results": dict_list})
if isinstance(v, Message):
return Data(data=v.data)
if isinstance(v, dict):
return Data(data=v)
if not isinstance(v, Data):
msg = f"Invalid value type {type(v)} for input {info.data.get('name')}. Expected Data."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Message text gets silently discarded when converting MessageData.

Message.data does not include the text field, therefore the current conversion loses the core payload.

-        if isinstance(v, Message):
-            return Data(data=v.data)
+        if isinstance(v, Message):
+            # Preserve the textual content together with the auxiliary payload
+            return Data(data={"text": v.text, **(v.data or {})})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if isinstance(v, DataFrame):
# Convert DataFrame to a list of dictionaries and wrap in a Data object
dict_list = v.to_dict(orient="records")
return Data(data={"results": dict_list})
if isinstance(v, Message):
return Data(data=v.data)
if isinstance(v, dict):
return Data(data=v)
if not isinstance(v, Data):
msg = f"Invalid value type {type(v)} for input {info.data.get('name')}. Expected Data."
if isinstance(v, DataFrame):
# Convert DataFrame to a list of dictionaries and wrap in a Data object
dict_list = v.to_dict(orient="records")
return Data(data={"results": dict_list})
if isinstance(v, Message):
# Preserve the textual content together with the auxiliary payload
return Data(data={"text": v.text, **(v.data or {})})
if isinstance(v, dict):
return Data(data=v)
if not isinstance(v, Data):
msg = f"Invalid value type {type(v)} for input {info.data.get('name')}. Expected Data."
🤖 Prompt for AI Agents
In src/backend/base/langflow/inputs/inputs.py around lines 115 to 124, when
converting a Message instance to Data, the current code only copies Message.data
and discards the Message.text field, losing important information. Modify the
conversion to include the Message.text field along with Message.data when
creating the Data object, ensuring the text payload is preserved in the
resulting Data.

Comment on lines +130 to +152
input_types: list[str] = ["DataFrame", "Data", "Message"]

@field_validator("value")
@classmethod
def validate_value(cls, v: DataFrame | Data | Message | dict, info) -> DataFrame:
if isinstance(v, Data):
data_dict = v.data
# If data contains only one key and the value is a list of dictionaries, convert to DataFrame
if (
len(data_dict) == 1
and isinstance(next(iter(data_dict.values())), list)
and all(isinstance(item, dict) for item in next(iter(data_dict.values())))
):
return DataFrame(data=next(iter(data_dict.values())))
return DataFrame(data=[v])
if isinstance(v, Message):
return DataFrame(data=[v])
if isinstance(v, dict):
return DataFrame(data=[v])
if not isinstance(v, DataFrame):
msg = f"Invalid value type {type(v)} for input {info.data.get('name')}. Expected DataFrame."
raise ValueError(msg) # noqa: TRY004
return v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

DataFrameInput.validate_value builds unusable frames for Data / Message.

pandas.DataFrame([v]) where v is a Data/Message instance produces a single-column dataframe with an opaque object – breaking every downstream expectation (your own tests access a "key" column).

         if isinstance(v, Data):
@@
-            return DataFrame(data=[v])
+            return DataFrame(data=[v.data])

         if isinstance(v, Message):
-            return DataFrame(data=[v])
+            row = {"text": v.text, **(v.data or {})}
+            return DataFrame(data=[row])

Likewise, validate that a dict with list-of-dict values still passes through the earlier branch.
This fix aligns the method with the unit-test expectations.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
input_types: list[str] = ["DataFrame", "Data", "Message"]
@field_validator("value")
@classmethod
def validate_value(cls, v: DataFrame | Data | Message | dict, info) -> DataFrame:
if isinstance(v, Data):
data_dict = v.data
# If data contains only one key and the value is a list of dictionaries, convert to DataFrame
if (
len(data_dict) == 1
and isinstance(next(iter(data_dict.values())), list)
and all(isinstance(item, dict) for item in next(iter(data_dict.values())))
):
return DataFrame(data=next(iter(data_dict.values())))
return DataFrame(data=[v])
if isinstance(v, Message):
return DataFrame(data=[v])
if isinstance(v, dict):
return DataFrame(data=[v])
if not isinstance(v, DataFrame):
msg = f"Invalid value type {type(v)} for input {info.data.get('name')}. Expected DataFrame."
raise ValueError(msg) # noqa: TRY004
return v
input_types: list[str] = ["DataFrame", "Data", "Message"]
@field_validator("value")
@classmethod
def validate_value(cls, v: DataFrame | Data | Message | dict, info) -> DataFrame:
if isinstance(v, Data):
data_dict = v.data
# If data contains only one key and the value is a list of dictionaries, convert to DataFrame
if (
len(data_dict) == 1
and isinstance(next(iter(data_dict.values())), list)
and all(isinstance(item, dict) for item in next(iter(data_dict.values())))
):
return DataFrame(data=next(iter(data_dict.values())))
return DataFrame(data=[v.data])
if isinstance(v, Message):
row = {"text": v.text, **(v.data or {})}
return DataFrame(data=[row])
if isinstance(v, dict):
return DataFrame(data=[v])
if not isinstance(v, DataFrame):
msg = f"Invalid value type {type(v)} for input {info.data.get('name')}. Expected DataFrame."
raise ValueError(msg) # noqa: TRY004
return v
🤖 Prompt for AI Agents
In src/backend/base/langflow/inputs/inputs.py lines 130 to 152, the
validate_value method incorrectly constructs DataFrames from Data or Message
instances by wrapping them in a list, resulting in single-column DataFrames with
opaque objects. To fix this, modify the method to detect when a Data instance's
data dictionary contains a single key with a list of dictionaries as its value
and convert that list directly into a DataFrame. For Message and dict inputs,
ensure they are converted into DataFrames with proper structure rather than
wrapped as opaque objects. Also, validate that dicts with list-of-dict values
are handled by the earlier branch to maintain consistency with unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants