Skip to content

fix: bound web search result content - #14470

Open
Oxygen56 wants to merge 6 commits into
langflow-ai:mainfrom
Oxygen56:fix/14469-bound-web-search-results
Open

fix: bound web search result content#14470
Oxygen56 wants to merge 6 commits into
langflow-ai:mainfrom
Oxygen56:fix/14469-bound-web-search-results

Conversation

@Oxygen56

@Oxygen56 Oxygen56 commented Aug 8, 2026

Copy link
Copy Markdown

Fixes #14469

Summary

  • add advanced limits for web search result count (default 5) and scraped page content (default 4,000 characters)
  • apply both bounds before returning Web mode results to downstream agents
  • add regression coverage for result and content limits

Root Cause

Web mode iterated over every DuckDuckGo result and returned the full extracted text of each linked page. Repeated tool calls therefore accumulated unbounded page content in the agent context.

Verification

  • focused Web Search test file with cached compatible dependencies: 29 passed, 4 skipped, 2 deselected
  • targeted limit regression tests: 2 passed
  • Ruff check, Ruff format check, and Git whitespace check passed for the changed files

Notes for Reviewers

  • The limits apply only to Web mode; News and RSS behavior is unchanged.
  • Generated starter-project and component-index updates are handled by the repository's existing autofix workflow.
  • The exact locked project environment was unavailable locally, so CI remains the authoritative full-suite validation.

Summary by CodeRabbit

  • New Features

    • Added configurable limits for the number of web-search results and the amount of page content returned.
    • Provided conservative defaults of 5 results and 4,000 characters.
    • Marked these controls as advanced options.
  • Bug Fixes

    • Prevented web searches from returning more results or content than configured.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9557c67b-a062-43f9-8aec-a1155ea97b1d

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The Web Search component adds advanced max_results and max_content_length inputs. It limits fetched results and truncates scraped page content. Tests verify defaults, fetch counts, and returned content lengths.

Changes

Web search limits

Layer / File(s) Summary
Configure web search limits
src/lfx/src/lfx/components/data_source/web_search.py, src/backend/tests/unit/components/data_source/test_web_search.py
The component exposes advanced integer limits with defaults of 5 results and 4000 content characters. Tests verify both inputs and defaults.
Enforce result and content limits
src/lfx/src/lfx/components/data_source/web_search.py, src/backend/tests/unit/components/data_source/test_web_search.py
The component clamps limits to nonnegative values, processes only the configured number of results, and truncates each scraped content value. Tests verify two fetched results and 12-character content limits.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WebSearchComponent
  participant ParsedResults
  participant ResultPages
  WebSearchComponent->>ParsedResults: select up to max_results
  WebSearchComponent->>ResultPages: fetch selected pages
  ResultPages-->>WebSearchComponent: return scraped content
  WebSearchComponent-->>WebSearchComponent: truncate content to max_content_length
Loading
🚥 Pre-merge checks | ✅ 9
✅ Passed checks (9 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: limiting Web Search result content.
Linked Issues check ✅ Passed The changes implement max_results and max_content_length, limit Web Search payloads, preserve News behavior, and add regression tests [#14469].
Out of Scope Changes check ✅ Passed All changes directly support the linked issue by bounding Web Search results and scraped content with focused regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Test Coverage For New Implementations ✅ Passed Updated backend unit test_web_search.py verifies advanced defaults and regression behavior: only two results are fetched and page content is truncated to 12 characters.
Test Quality And Coverage ✅ Passed Tests verify advanced defaults, cap three mocked results to two fetches, assert exact 12-character truncation, and retain Web/News/RSS and error-path coverage using pytest patterns.
Test File Naming And Structure ✅ Passed The changed backend test uses the expected test_*.py path, a pytest test class, 30 discoverable test methods, descriptive names, fixtures/mocks, and positive plus error/security cases; no frontend...
Excessive Mock Usage Warning ✅ Passed The new regression test mocks only HTTP and page-fetch boundaries; it runs real parsing, result limiting, truncation, and fetch-count assertions. Mock usage is appropriate.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Aug 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/backend/tests/unit/components/data_source/test_web_search.py`:
- Around line 201-239: Add test coverage around
test_perform_web_search_limits_and_content for zero and negative max_results and
max_content_length values. Verify max_results=0 and -1 fetch no result pages,
and max_content_length=0 and -1 return empty content, while preserving the
existing positive-limit assertions and mocks.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 29d3bcf8-f8dc-4e18-aba9-4db17d57f5f3

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec070e and 8454392.

📒 Files selected for processing (2)
  • src/backend/tests/unit/components/data_source/test_web_search.py
  • src/lfx/src/lfx/components/data_source/web_search.py

Comment on lines +201 to +239
@patch.object(WebSearchComponent, "_safe_get_url")
@patch("lfx.components.data_source.web_search.requests.get")
def test_perform_web_search_limits_results_and_content(self, mock_get, mock_safe_get):
"""Web search should bound both fetched result count and returned page text."""
component = WebSearchComponent()
component.query = "test query"
component.max_results = 2
component.max_content_length = 12
component.timeout = 5

mock_response = Mock()
mock_response.text = """
<html>
<div class="result">
<a class="result__a" href="?uddg=https%3A%2F%2Fexample.com%2F1">First</a>
</div>
<div class="result">
<a class="result__a" href="?uddg=https%3A%2F%2Fexample.com%2F2">Second</a>
</div>
<div class="result">
<a class="result__a" href="?uddg=https%3A%2F%2Fexample.com%2F3">Third</a>
</div>
</html>
"""
mock_response.headers = {"content-type": "text/html"}
mock_response.raise_for_status.return_value = None
mock_get.return_value = mock_response

mock_page_response = Mock()
mock_page_response.text = "<html><body>abcdefghijklmnopqrstuvwxyz</body></html>"
mock_page_response.raise_for_status.return_value = None
mock_safe_get.return_value = mock_page_response

with patch("lfx.components.data_source.web_search.get_user_agent", return_value="test-agent"):
result = component.perform_web_search()

assert len(result) == 2
assert mock_safe_get.call_count == 2
assert result["content"].tolist() == ["abcdefghijkl", "abcdefghijkl"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Test zero and negative limits.

The implementation clamps both limits to zero. This test only covers positive values. Add cases for max_results=0, max_results=-1, max_content_length=0, and max_content_length=-1. Assert that a zero result limit fetches no result pages and that a zero content limit returns empty content.

As per coding guidelines, backend tests must cover positive, negative, edge, and error cases.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/backend/tests/unit/components/data_source/test_web_search.py` around
lines 201 - 239, Add test coverage around
test_perform_web_search_limits_and_content for zero and negative max_results and
max_content_length values. Verify max_results=0 and -1 fetch no result pages,
and max_content_length=0 and -1 return empty content, while preserving the
existing positive-limit assertions and mocks.

Source: Coding guidelines

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 8, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 8, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 8, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 8, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 8, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web Search component injects unbounded scraped page content into agent context (no max_results, no content truncation)

1 participant