Skip to content

Search Tool Parameter updates#1112

Merged
gwarmstrong merged 5 commits intomainfrom
georgea/tavily-updates
Dec 15, 2025
Merged

Search Tool Parameter updates#1112
gwarmstrong merged 5 commits intomainfrom
georgea/tavily-updates

Conversation

@gwarmstrong
Copy link
Collaborator

@gwarmstrong gwarmstrong commented Dec 15, 2025

Summary by CodeRabbit

  • New Features

    • Added num_results parameter (default: 10) to customize search result count
    • Added answer_type parameter (default: "answer") to choose response format: "answer" or "results"
  • Refactor

    • Web-search tool interface updated for improved clarity and flexibility

✏️ Tip: You can customize this high-level summary in your review settings.

…swer_type

Signed-off-by: George Armstrong <georgea@nvidia.com>
Signed-off-by: George Armstrong <georgea@nvidia.com>
Signed-off-by: George Armstrong <georgea@nvidia.com>
Signed-off-by: George Armstrong <georgea@nvidia.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

📝 Walkthrough

Walkthrough

The change renames the MCP tool from "tavily-search" to "web-search" and extends its interface with two new parameters: num_results (default 10) and answer_type (default "answer"). The payload and response handling are updated to use these parameters, with validation added for answer_type to accept only "answer" or "results".

Changes

Cohort / File(s) Change Summary
Tavily Search Tool Enhancement
nemo_skills/mcp/servers/tavily_search_tool.py
Renamed MCP tool from tavily-search to web-search; added num_results and answer_type parameters to the answer function signature with default values and descriptions; updated payload to include num_results; modified response selection to use dynamic answer_type field instead of hardcoded "answer"; added assertion to validate answer_type against allowed values; updated hide_args configuration to expose all three parameters for the web-search tool; propagated num_results and answer_type from config to tool execution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Areas requiring attention:
    • Validation logic: ensure the assertion for answer_type handles edge cases properly
    • Parameter propagation: verify that num_results and answer_type are correctly merged into merged_extra and passed to the external API
    • Tool naming consistency: confirm the rename from "tavily-search" to "web-search" is reflected across all relevant configurations and documentation

Possibly related PRs

  • FEAT Add Tavily Search #1085: Modifies the same MCP tool file and updates the tool's handler/exports in relation to tavily search functionality.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Search Tool Parameter updates' accurately describes the main changes: adding new parameters (num_results, answer_type) to the search tool interface.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch georgea/tavily-updates

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 and usage tips.

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: 3

🧹 Nitpick comments (1)
nemo_skills/mcp/servers/tavily_search_tool.py (1)

62-62: Replace assertion with explicit validation.

Assertions can be disabled with Python's -O flag and are not suitable for input validation in production code. Use an explicit check and raise a ValueError instead.

Apply this diff:

-    assert answer_type in ["answer", "results"], "Invalid answer type. Choose 'answer' or 'results'."
+    if answer_type not in ["answer", "results"]:
+        raise ValueError("Invalid answer_type. Choose 'answer' or 'results'.")

Note: If you adopt the Literal type suggestion from the previous comment, this validation becomes redundant.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c819ca4 and 7a8f7f4.

📒 Files selected for processing (1)
  • nemo_skills/mcp/servers/tavily_search_tool.py (5 hunks)
🧰 Additional context used
🪛 Ruff (0.14.8)
nemo_skills/mcp/servers/tavily_search_tool.py

50-50: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: pre-commit
  • GitHub Check: unit-tests
🔇 Additional comments (3)
nemo_skills/mcp/servers/tavily_search_tool.py (3)

74-74: LGTM!

The num_results parameter is correctly added to the API payload.


111-111: LGTM!

The hide_args configuration correctly reflects the tool rename and includes the new parameters.


132-134: LGTM! The config propagation logic is correct.

The loop correctly merges num_results and answer_type from the config into the extra arguments.

@mcp.tool(name="web-search")
async def answer(
query: Annotated[str, Field(description="Search query.")],
exclude_domains: Annotated[list[str], Field(description="Domains to exclude from the search.")] = [],
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 | 🟡 Minor

Replace mutable default argument with None.

Using a mutable list as a default argument can lead to unexpected behavior if the list is modified. Replace with None and initialize within the function.

Apply this diff:

-    exclude_domains: Annotated[list[str], Field(description="Domains to exclude from the search.")] = [],
+    exclude_domains: Annotated[list[str] | None, Field(description="Domains to exclude from the search.")] = None,

Then update the function body to handle None:

+    if exclude_domains is None:
+        exclude_domains = []
+
     api_url = "https://api.tavily.com/search"

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.14.8)

50-50: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)

🤖 Prompt for AI Agents
In nemo_skills/mcp/servers/tavily_search_tool.py around line 50, replace the
mutable default argument "exclude_domains: Annotated[list[str], Field(...)] =
[]" with "exclude_domains: Annotated[list[str] | None, Field(...)] = None" (or
simply set to None while keeping typing), and then in the function body check if
exclude_domains is None and set it to an empty list (e.g., exclude_domains = []
if exclude_domains is None else exclude_domains) so the default list is created
per-call rather than shared across calls.

Comment on lines +51 to +57
num_results: Annotated[int, Field(description="Number of results to return.")] = 10,
answer_type: Annotated[
str,
Field(
description='Type of results to return. Choose "answer" for a concise answer or "results" for a list of results.'
),
] = "answer",
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 | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cat -n nemo_skills/mcp/servers/tavily_search_tool.py

Repository: NVIDIA-NeMo/Skills

Length of output: 6495


🌐 Web query:

Tavily API search endpoint num_results parameter constraints documentation

💡 Result:

The Search endpoint uses the parameter named max_results (default 5). Constraint: integer in the range 0 ≤ x ≤ 20. Also note related limits: chunks_per_source must be 1–3. Source: Tavily API docs. [1][2]

Sources

  • Tavily Search API reference (parameters and max_results range). [1]
  • Tavily SDK / docs (parameters; chunks_per_source limits). [2]

Fix critical API payload parameter name and add type safety for answer_type.

The code sends "num_results" to the Tavily API payload (line 74), but the API expects "max_results". Additionally, use Literal type for answer_type to enforce valid options at the type level, and add validation for num_results according to Tavily API constraints (0–20).

Update the imports to include Literal:

-from typing import Annotated, Any
+from typing import Annotated, Any, Literal

Fix the payload parameter name:

-        "num_results": num_results,
+        "max_results": num_results,

Use Literal type for answer_type:

     answer_type: Annotated[
-        str,
+        Literal["answer", "results"],
         Field(
             description='Type of results to return. Choose "answer" for a concise answer or "results" for a list of results.'
         ),
     ] = "answer",

Add validation for num_results (API constraint: 0–20):

     """Search the web for a query"""
 
+    if not (0 <= num_results <= 20):
+        return {"error": "num_results must be between 0 and 20"}
+
     api_url = "https://api.tavily.com/search"

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
nemo_skills/mcp/servers/tavily_search_tool.py lines 51-57: the API parameter
name and types are incorrect — change the payload key sent to Tavily from
"num_results" to "max_results" where the request is built (around line 74),
update the function parameter annotation to use typing.Literal for answer_type
(Literal["answer","results"]) and import Literal at top, and add explicit
validation for num_results to ensure it's an int within Tavily's allowed range
0–20 (raise/convert and clamp or raise ValueError) before adding it to the
payload.

Signed-off-by: George Armstrong <georgea@nvidia.com>
@gwarmstrong gwarmstrong merged commit f01ecb0 into main Dec 15, 2025
5 checks passed
@gwarmstrong gwarmstrong deleted the georgea/tavily-updates branch December 15, 2025 21:54
wasiahmad pushed a commit that referenced this pull request Dec 19, 2025
Signed-off-by: George Armstrong <georgea@nvidia.com>
wasiahmad pushed a commit that referenced this pull request Dec 19, 2025
Signed-off-by: George Armstrong <georgea@nvidia.com>

Signed-off-by: wasiahmad <wasiahmad@ucla.edu>
hsiehjackson pushed a commit that referenced this pull request Jan 13, 2026
Signed-off-by: George Armstrong <georgea@nvidia.com>
Signed-off-by: Cheng-Ping Hsieh <chsieh@nvidia.com>
wasiahmad pushed a commit that referenced this pull request Feb 4, 2026
Signed-off-by: George Armstrong <georgea@nvidia.com>
dgtm777 pushed a commit that referenced this pull request Mar 18, 2026
Signed-off-by: George Armstrong <georgea@nvidia.com>
dgtm777 pushed a commit that referenced this pull request Mar 18, 2026
Signed-off-by: George Armstrong <georgea@nvidia.com>
Signed-off-by: dgitman <dgitman@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant