Skip to content

fix(core): prevent tool descriptions from inheriting parent class doc…#36693

Closed
SaVi (SaVi456) wants to merge 1 commit intolangchain-ai:masterfrom
SaVi456:fix/docstring-inheritance
Closed

fix(core): prevent tool descriptions from inheriting parent class doc…#36693
SaVi (SaVi456) wants to merge 1 commit intolangchain-ai:masterfrom
SaVi456:fix/docstring-inheritance

Conversation

@SaVi456
Copy link
Copy Markdown

Summary

  • Fixes core: docstrings shouldn't inherit from parents #32066 — child classes without their own docstring silently inherited the parent's via Python's MRO, causing misleading tool descriptions in function-calling APIs
  • Adds _get_own_doc() helper in langchain_core/utils/pydantic.py that checks __dict__ directly instead of traversing the MRO
  • Applies the fix at all description-resolution sites in structured.py, convert.py, and pydantic.py

Test plan

  • 7 new unit tests covering inherited docstring scenarios
  • All 209 existing tests in test_tools.py pass (0 regressions)
  • All 10 tests in test_pydantic.py pass
  • All 31 tests in test_function_calling.py pass
  • Linting and formatting clean

Disclaimer: This contribution was primarily authored by Claude Opus 4.6 (Anthropic) via Claude Code.

…strings

Child classes without their own docstring silently inherited the parent's
via Python's MRO, causing misleading tool descriptions in function-calling
APIs. Add _get_own_doc() helper that checks __dict__ directly instead of
traversing the MRO, and apply it at all description-resolution sites.

Closes #32066

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix size: S 50-199 LOC labels Apr 13, 2026
@github-actions
Copy link
Copy Markdown

This PR has been automatically closed because you are not assigned to the linked issue.

External contributors must be assigned to an issue before opening a PR for it. Please:

  1. Comment on the linked issue to request assignment from a maintainer
  2. Once assigned, your PR will be reopened automatically

Maintainers: reopen this PR or remove the missing-issue-link label to bypass this check.

@github-actions github-actions bot closed this Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external fix For PRs that implement a fix missing-issue-link new-contributor size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: docstrings shouldn't inherit from parents

1 participant