Skip to content

fix(toolbox-langchain): avoid duplicated parameter descriptions#680

Open
WilliamK112 wants to merge 2 commits into
googleapis:mainfrom
WilliamK112:wk/fix-langchain-duplicate-param-descriptions
Open

fix(toolbox-langchain): avoid duplicated parameter descriptions#680
WilliamK112 wants to merge 2 commits into
googleapis:mainfrom
WilliamK112:wk/fix-langchain-duplicate-param-descriptions

Conversation

@WilliamK112

Copy link
Copy Markdown

Fixes googleapis/mcp-toolbox#1327.

LangChain tools currently use the core tool __doc__ as the BaseTool description. The core docstring intentionally appends an Args: section for Python introspection, but LangChain already receives parameter descriptions through args_schema, so the LLM-facing tool description duplicates every parameter description.

This changes the LangChain wrappers to use the core tool's raw _description when available, while preserving a fallback to __doc__ for compatibility with older or mocked tool objects. Regression coverage checks that the LangChain tool description no longer includes Args: while parameter descriptions remain available through args_schema.

Validation:

  • pytest tests/test_client.py tests/test_async_client.py tests/test_tools.py tests/test_async_tools.py
  • black --check src tests
  • isort --check src tests
  • MYPYPATH='./src:../toolbox-core/src' mypy --install-types --non-interactive --cache-dir=.mypy_cache/ -p toolbox_langchain

Note: the full pytest tests suite includes E2E coverage that expects a Toolbox service/version environment, so I used the non-E2E LangChain package test set above for this wrapper change.

@WilliamK112
WilliamK112 requested a review from a team as a code owner June 14, 2026 02:24
@google-cla

google-cla Bot commented Jun 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Yuan325 Yuan325 added the priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. label Jun 22, 2026
@anubhav756
anubhav756 force-pushed the wk/fix-langchain-duplicate-param-descriptions branch from 0ed0c21 to 86be7ae Compare July 9, 2026 12:11
@anubhav756

Copy link
Copy Markdown
Contributor

/gcbrun



def _get_tool_description(core_tool: ToolboxCoreTool) -> str:
description = core_tool._description

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.

in the case the tool lacks the description, would this raise an attribute error or fallback to doc ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It now falls back to __doc__ without raising AttributeError. I changed the lookup to getattr(core_tool, "_description", None) in both sync and async adapters, then use core_tool.__doc__ or "" when the structured description is unavailable. This is covered in 92108fd.

sync_mock.__name__ = "test_tool_name_for_langchain"
sync_mock.__doc__ = tool_schema_dict["description"]
sync_mock._description = tool_schema_dict["description"]
sync_mock.__doc__ = (

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.

Can we add a test to check the fallback to doc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added fallback coverage for both adapters in 92108fd: the sync test removes _description, and the async test sets the underlying description to None; both assert that the LangChain tool uses __doc__. The focused suite passes (30 passed).

@anubhav756
anubhav756 force-pushed the wk/fix-langchain-duplicate-param-descriptions branch from 92108fd to f439261 Compare July 23, 2026 06:58
@anubhav756
anubhav756 requested a review from twishabansal July 23, 2026 06:58
@anubhav756

Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756
anubhav756 requested a review from dishaprakash July 23, 2026 06:59
@anubhav756

anubhav756 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Triggered tests and passing it to Disha since her comments have responses :)

Signed-off-by: WilliamK112 <164879897+WilliamK112@users.noreply.github.com>
@anubhav756
anubhav756 force-pushed the wk/fix-langchain-duplicate-param-descriptions branch from f439261 to 1b293f3 Compare July 23, 2026 06:59
@anubhav756

Copy link
Copy Markdown
Contributor

/gcbrun

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

Labels

priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

why there are duplicate parameters descrption in the tools ?

4 participants