Skip to content

feat: Better multi-file consistency for File Component#8625

Merged
erichare merged 61 commits into
mainfrom
feat-file-output-changes
Jun 26, 2025
Merged

feat: Better multi-file consistency for File Component#8625
erichare merged 61 commits into
mainfrom
feat-file-output-changes

Conversation

@erichare
Copy link
Copy Markdown
Collaborator

@erichare erichare commented Jun 18, 2025

This pull request makes output changes to the File Component to be more intuitive in both the single and multi file case.

Summary by CodeRabbit

  • New Features

    • File input fields now support real-time refresh, providing immediate updates when file selections change.
    • The File component dynamically adjusts its outputs based on the number of files selected: multiple files show a "Raw Files" output, while a single file displays both "Structured File" and "Raw File" outputs.
  • Enhancements

    • Improved responsiveness and clarity in the UI for file-related components across multiple starter projects.
    • Default output selections have been added to relevant nodes for a smoother user experience.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 18, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 18, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change updates the FileComponent in both backend code and multiple starter project configurations. It enables real-time refresh on the file path input and introduces a method to dynamically adjust output ports based on the number of files selected. Node metadata is also updated in several starter project JSON files for output selection consistency.

Changes

File(s) Change Summary
src/backend/base/langflow/components/data/file.py Adds deep copy of base inputs, enables real_time_refresh on "path", and introduces update_outputs for dynamic output adjustment.
src/backend/base/langflow/initial_setup/starter_projects/Document Q&A.json Updates FileComponent code to match backend changes, adjusts node metadata for output selection.
src/backend/base/langflow/initial_setup/starter_projects/Portfolio Website Code Generator.json Updates FileComponent code to enable real-time refresh and dynamic outputs, no other logic changes.
src/backend/base/langflow/initial_setup/starter_projects/Text Sentiment Analysis.json Updates FileComponent as above; adds "selected_output" fields to Prompt and LanguageModelComponent nodes.
src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json Updates FileComponent as above, with dynamic output logic and real-time refresh on file path input.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant FileComponent

    User->>Frontend: Selects file(s) via FileInput ("path")
    Frontend->>FileComponent: Triggers update_outputs on "path" change
    FileComponent->>Frontend: Returns updated node outputs (based on file count)
    User->>Frontend: Initiates processing
    Frontend->>FileComponent: Calls process_files with selected files
    FileComponent->>Frontend: Returns processed file(s) output
Loading

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • edwinjosechittilappilly
  • Yukiyukiyeah
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feat-file-output-changes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 auto-generate unit tests to generate unit tests for 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.

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.

@erichare erichare requested a review from rodrigosnader June 18, 2025 21:52
@erichare erichare marked this pull request as draft June 18, 2025 21:53
@dosubot dosubot Bot added the enhancement New feature or request label Jun 18, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 18, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 18, 2025
@erichare erichare changed the title feat: First pass at output changes for file component feat: Better multi-file consistency for File Component Jun 20, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 20, 2025
@erichare erichare marked this pull request as ready for review June 24, 2025 15:15
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
Copy link
Copy Markdown
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: 1

🔭 Outside diff range comments (6)
src/backend/base/langflow/initial_setup/starter_projects/Text Sentiment Analysis.json (2)

308-336: update_outputs mis-classifies single path strings as “multiple files”.

len(self.path) > 1 is truthy for every non-empty string (e.g. "/tmp/file.txt"len(..)=14).
Consequently, a single file given as a string will be treated as a multi-file selection, hiding the “Structured File / Raw File” outputs.

-            if len(self.path) > 1:
+            # Detect true “multi-file” only when the incoming value is a list
+            if isinstance(field_value, list) and len(field_value) > 1:

Leverage the already-provided field_value instead of the potentially stale self.path.
This avoids UI confusion and keeps the dynamic-output feature reliable.


340-390: Parallel-processing threshold & deprecation toggle are drifting.

use_multithreading is flagged [Deprecated] yet the concurrency logic still depends on it, forcing users to set two different knobs (use_multithreading=True and concurrency_multithreading>1) to enable parallelism.
Consider simplifying:

  1. Drop the boolean entirely and infer intent from concurrency_multithreading.
  2. Or keep the flag but ignore the integer when it’s <=1.
-        concurrency = 1 if not self.use_multithreading else max(1, self.concurrency_multithreading)
+        # Treat any value >1 in `concurrency_multithreading` as the single source of truth
+        concurrency = max(1, self.concurrency_multithreading)

Reduces user friction and cleans up the deprecated path sooner.

src/backend/base/langflow/initial_setup/starter_projects/Portfolio Website Code Generator.json (1)

1867-1889: update_outputs uses stale self.path and mis-detects single vs. multi-file cases

update_outputs relies on len(self.path) while the new field_value containing the current value of the path is passed as an argument.
If the method is triggered before the path attribute is updated (which is usually the case in build-config hooks), the length check is performed on the previous value, leading to an incorrect set of outputs.

-            # Add outputs based on the number of files in the path
-            if len(self.path) > 1:
+            # Prefer `field_value` (freshest value) and gracefully fallback
+            paths = field_value or self.path
+            # Handle both list-of-files and single-string cases
+            file_count = len(paths) if isinstance(paths, (list, tuple)) else 1
+
+            if file_count > 1:

This also fixes the subtle bug where a single file given as a string with more than one character ("a", "b", …) is treated as “multiple files”.

src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json (2)

2475-2496: update_outputs relies on self.path instead of the incoming field_value

update_outputs is triggered by the front-end each time a field changes and you already receive field_name & field_value.
Using self.path here is racy:

• When the user first picks a file, the attribute may not yet be updated, so len(self.path) could still be 0 → no outputs rendered.
• If path is a string (single file path) its len() counts characters, not the number of files, so every non-empty path is treated as “multiple files”.

-        if field_name == "path":
+        if field_name == "path":
             # Start with empty outputs
             frontend_node["outputs"] = []

-            # Add outputs based on the number of files in the path
-            if len(self.path) > 1:
+            # Decide based on the *new* value coming from the UI
+            file_count = len(field_value) if isinstance(field_value, list) else 1
+
+            if file_count > 1:
                 frontend_node["outputs"].append(
                     Output(display_name="Raw Files", name="dataframe", method="load_files"),
                 )
             else:
                 frontend_node["outputs"].append(
                     Output(display_name="Structured File", name="dataframe", method="load_files"),
                 )
                 frontend_node["outputs"].append(
                     Output(display_name="Raw File", name="message", method="load_files_message"),
                 )

This guarantees deterministic behaviour and correct single-vs-multi file detection.


2543-2560: Concurrency flag logic is backwards‐compatible but confusing

concurrency = 1 if not self.use_multithreading else max(1, self.concurrency_multithreading)

  1. The new guidance is to ignore use_multithreading and rely solely on concurrency_multithreading; however this keeps the old flag alive, forcing users to set two inputs for parallelism.
  2. With the default concurrency_multithreading = 1, the component never crosses the parallel_processing_threshold = 2, so even when use_multithreading=True nothing happens.

Recommend:

-        concurrency = 1 if not self.use_multithreading else max(1, self.concurrency_multithreading)
+        # honour new field first, fall back to deprecated flag for BC
+        concurrency = max(1, self.concurrency_multithreading)
+
+        # `use_multithreading` kept only for BC: if users untick it, force sequential
+        if not self.use_multithreading:
+            concurrency = 1

and document this in the component description.

src/backend/base/langflow/initial_setup/starter_projects/Document Q&A.json (1)

835-870: update_outputs uses self.path instead of the just-edited value – can desync UI & backend

update_outputs is invoked while the “path” field is being changed, but the component attribute (self.path) has not yet been mutated.
If the user switches from one file to many (or vice-versa) the length check will be performed on the stale value and the frontend may receive the wrong port list.

-        if field_name == "path":
+        if field_name == "path":
             # Start with empty outputs
             frontend_node["outputs"] = []

-            if len(self.path) > 1:
+            files = field_value if isinstance(field_value, (list, tuple)) else [field_value]
+            if len(files) > 1:

Leaning on field_value guarantees we evaluate against the new selection and sidesteps any mutation-order edge-cases.

🧹 Nitpick comments (5)
src/backend/base/langflow/components/data/file.py (1)

60-70: Enhance robustness with defensive programming.

Consider adding defensive checks to handle edge cases more gracefully:

 def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:  # noqa: ARG002
     """Dynamically show only the relevant output based on the number of files processed."""
     if field_name == "path":
         # Start with empty outputs
         frontend_node["outputs"] = []

         # Add outputs based on the number of files in the path
-        if len(self.path) > 1:
+        path_length = len(self.path) if self.path else 0
+        if path_length > 1:
             frontend_node["outputs"].append(
                 Output(display_name="Raw Files", name="dataframe", method="load_files"),
             )
-        else:
+        elif path_length == 1:
             frontend_node["outputs"].append(
                 Output(display_name="Structured File", name="dataframe", method="load_files"),
             )
             frontend_node["outputs"].append(
                 Output(display_name="Raw File", name="message", method="load_files_message"),
             )
+        # If path_length == 0, outputs remain empty which is appropriate

     return frontend_node
src/backend/base/langflow/initial_setup/starter_projects/Portfolio Website Code Generator.json (2)

1889-1906: Output names & display names are inconsistent with the methods they call

For the multi-file branch an output is registered as
Output(display_name="Raw Files", name="dataframe", method="load_files")

load_files returns a DataFrame/structured table, not a raw byte/string blob, whereas the display name claims “Raw”. Conversely the single-file branch calls load_files_message (which is the raw path) but labels the first output “Structured File”.

Consider aligning naming with behaviour:

- Output(display_name="Raw Files", name="dataframe", method="load_files"),
+ Output(display_name="Structured Files", name="dataframe", method="load_files"),- Output(display_name="Structured File", name="dataframe", method="load_files"),
- Output(display_name="Raw File", name="message", method="load_files_message"),
+ Output(display_name="Structured File", name="dataframe", method="load_files"),
+ Output(display_name="Raw Content", name="message", method="load_files_message"),

This avoids confusing the UI/JSON consumers.


1920-1955: concurrency logic still depends on deprecated use_multithreading flag

concurrency = 1 if not self.use_multithreading else max(1, self.concurrency_multithreading)

This silently ignores a user-provided concurrency_multithreading > 1 whenever the (now deprecated) flag is false. Since the UI surfaces “Processing Concurrency” as the canonical switch, drop the flag and rely solely on concurrency_multithreading:

- concurrency = 1 if not self.use_multithreading else max(1, self.concurrency_multithreading)
+ concurrency = max(1, self.concurrency_multithreading)

You can keep backward-compatibility by mapping use_multithreading=Trueconcurrency_multithreading = max(2, concurrency_multithreading) during migration.

src/backend/base/langflow/initial_setup/starter_projects/Document Q&A.json (2)

835-870: Port display names don’t match their semantic role

When multiple files are chosen the code adds

Output(display_name="Raw Files", name="dataframe", method="load_files")

Yet load_files returns a structured DataFrame, not raw text. Conversely for single-file mode “Structured File” is used for the same dataframe output, while “Raw File” maps to the message port.

The mismatch is confusing in the UI. Consider:

-Output(display_name="Raw Files", name="dataframe", method="load_files")
+Output(display_name="Structured Files", name="dataframe", method="load_files")

(or flip the port names) so users immediately understand which handle carries structured vs. raw content.


835-870: Deprecated use_multithreading gate still drives concurrency

concurrency_multithreading is ignored unless the deprecated flag is True:

concurrency = 1 if not self.use_multithreading else max(1, self.concurrency_multithreading)

Users setting only concurrency_multithreading > 1 will be puzzled that parallelism never kicks in.
Either:

  1. Drop the boolean and treat concurrency_multithreading > 1 as the single source of truth, or
  2. Flip the default of use_multithreading to True and mark the field as hidden.

This keeps behaviour aligned with the “[Deprecated]” label while preventing silent performance regressions.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a3e205 and cdb9850.

📒 Files selected for processing (5)
  • src/backend/base/langflow/components/data/file.py (3 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Document Q&A.json (6 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Portfolio Website Code Generator.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Text Sentiment Analysis.json (4 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`src/backend/base/langflow/components/**/*`: Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/.

src/backend/base/langflow/components/**/*: Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/.

  • src/backend/base/langflow/components/data/file.py
`src/backend/**/components/**/*.py`: In your component class, set the 'icon' attribute to a string matching the frontend icon mapping exactly (case-sensitive).

src/backend/**/components/**/*.py: In your component class, set the 'icon' attribute to a string matching the frontend icon mapping exactly (case-sensitive).

  • src/backend/base/langflow/components/data/file.py
🔇 Additional comments (4)
src/backend/base/langflow/components/data/file.py (2)

1-2: LGTM - Necessary imports added for new functionality.

The imports for deepcopy and Any are correctly added to support the new input modification logic and type annotations.


53-72: Verify dynamic output behavior for edge cases.

The update_outputs method looks well-implemented for the main use cases, but there are a few considerations:

  1. The method accesses self.path without null checking
  2. Empty file lists might cause unexpected behavior

Please run the following script to verify how this method handles edge cases:

#!/bin/bash
# Description: Search for similar update_outputs implementations and FileInput usage patterns
# Expected: Find patterns for handling edge cases in similar methods

# Search for other update_outputs methods to understand common patterns
ast-grep --pattern 'def update_outputs($_, $_, $_) { $$$ }'

# Search for FileInput real_time_refresh usage
rg -A 3 -B 3 "real_time_refresh"

# Search for path attribute usage in FileComponent
rg -A 2 -B 2 "self\.path" src/backend/base/langflow/components/data/
src/backend/base/langflow/initial_setup/starter_projects/Vector Store RAG.json (1)

2508-2542: Nested process_file breaks parallel execution if parallel_load_data uses multiprocessing

process_file is declared inside process_files. A nested (local) function is not picklable, so any multiprocessing or process-based executor inside parallel_load_data will fail with a PicklingError.

Two safe fixes:

@@
-class FileComponent(BaseFileComponent):
+class FileComponent(BaseFileComponent):
     ...
+    # --- helpers -----------------------------------------------------------
+
+def _process_single_file(file_path: str, *, silent_errors: bool = False) -> Data | None:
+    """Standalone helper so it can be pickled / used by process pools."""
+    from langflow.base.data.utils import parse_text_file_to_data  # local import to avoid circulars
+    try:
+        return parse_text_file_to_data(file_path, silent_errors=silent_errors)
+    except Exception as e:
+        return e  # propagate error for caller to handle
+
 class FileComponent(BaseFileComponent):
@@
-        def process_file(file_path: str, *, silent_errors: bool = False) -> Data | None:
-            ...
+        # use the top-level helper

or switch parallel_load_data to a thread pool exclusively.

Confirm the implementation of parallel_load_data before this ships.

src/backend/base/langflow/initial_setup/starter_projects/Document Q&A.json (1)

415-417: Nice addition – explicit selected_output greatly improves default UX

The new selected_output entries for ChatInput, File, Prompt, OpenAIModel and Parser nodes remove ambiguity in multi-port components and ensure the graph wires up predictably.

Also applies to: 1033-1035, 1191-1193, 1586-1588, 1761-1763

Comment thread src/backend/base/langflow/components/data/file.py
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 24, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
@FawadAkhtar110
Copy link
Copy Markdown

@FawadAkhtar110

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

Labels

DO NOT MERGE Don't Merge this PR enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants