[PR #6579] fix(prebuilt): resolve Pydantic validation error for ToolRuntime with custom tool nodes #5138

Closed
opened 2026-02-20 17:51:17 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/6579

State: closed
Merged: No


Fix #6576

When users create custom tool nodes and invoke tools directly with tool.invoke(tool_call['args']), tools with ToolRuntime parameters failed with a Pydantic validation error because runtime was not injected.

Changes:

  • Make ToolRuntime fields default to None to allow instantiation without arguments
  • Add get_pydantic_core_schema to make ToolRuntime optional in pydantic schemas with None default
  • Update documentation to clarify ToolRuntime requires ToolNode for proper injection and document the workaround (runtime: ToolRuntime = None)
  • Add tests for the fix and workaround

Thank you for contributing to LangGraph! Follow these steps to mark your pull request as ready for review. If any of these steps are not completed, your PR will not be considered for review.

  • PR title: Follows the format: {TYPE}({SCOPE}): {DESCRIPTION}
    • Examples:
      • feat(core): add multi-tenant support
      • fix(cli): resolve flag parsing error
      • docs(openai): update API usage examples
    • Allowed {TYPE} values:
      • feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, release
    • Allowed {SCOPE} values (optional):
      • langgraph, docs, cli, checkpoint, checkpoint-postgres, checkpoint-sqlite, prebuilt, scheduler-kafka, sdk-py
    • Once you've written the title, please delete this checklist item; do not include it in the PR.

Description: Fix Pydantic validation error when using custom tool nodes with tools that have ToolRuntime parameters.

When users create custom tool nodes and invoke tools directly with tool.invoke(tool_call['args']), tools with ToolRuntime parameters failed with a "Field required" validation error because runtime was not injected.

Changes:

  • Make ToolRuntime fields default to None to allow instantiation without arguments
  • Add __get_pydantic_core_schema__ to make ToolRuntime optional in pydantic schemas with None default
  • Update documentation to clarify ToolRuntime requires ToolNode for proper injection
  • Document the workaround for direct invocation: runtime: ToolRuntime = None
  • Add tests for the fix and workaround

Issue: Fixes #6576

Dependencies: None

Twitter handle: (add yours if you want a shoutout)

  • Add tests and docs: If you're adding a new integration, you must include:

    1. A test for the integration, preferably unit tests that do not rely on network access,
    2. An example notebook showing its use. It lives in docs/docs/integrations directory.
  • Lint and test: Run make format, make lint and make test from the root of the package(s) you've modified. We will not consider a PR unless these three are passing in CI. See contribution guidelines for more.

Additional guidelines:

  • Make sure optional dependencies are imported within a function.
  • Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests.
  • Most PRs should not touch more than one package.
  • Changes should be backwards compatible.
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6579 **State:** closed **Merged:** No --- Fix #6576 When users create custom tool nodes and invoke tools directly with tool.invoke(tool_call['args']), tools with ToolRuntime parameters failed with a Pydantic validation error because runtime was not injected. Changes: - Make ToolRuntime fields default to None to allow instantiation without arguments - Add __get_pydantic_core_schema__ to make ToolRuntime optional in pydantic schemas with None default - Update documentation to clarify ToolRuntime requires ToolNode for proper injection and document the workaround (runtime: ToolRuntime = None) - Add tests for the fix and workaround Thank you for contributing to LangGraph! Follow these steps to mark your pull request as ready for review. **If any of these steps are not completed, your PR will not be considered for review.** - [x] **PR title**: Follows the format: {TYPE}({SCOPE}): {DESCRIPTION} - Examples: - feat(core): add multi-tenant support - fix(cli): resolve flag parsing error - docs(openai): update API usage examples - Allowed `{TYPE}` values: - feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, release - Allowed `{SCOPE}` values (optional): - langgraph, docs, cli, checkpoint, checkpoint-postgres, checkpoint-sqlite, prebuilt, scheduler-kafka, sdk-py - Once you've written the title, please delete this checklist item; do not include it in the PR. **Description:** Fix Pydantic validation error when using custom tool nodes with tools that have ToolRuntime parameters. When users create custom tool nodes and invoke tools directly with `tool.invoke(tool_call['args'])`, tools with `ToolRuntime` parameters failed with a "Field required" validation error because runtime was not injected. Changes: - Make ToolRuntime fields default to None to allow instantiation without arguments - Add `__get_pydantic_core_schema__` to make ToolRuntime optional in pydantic schemas with None default - Update documentation to clarify ToolRuntime requires ToolNode for proper injection - Document the workaround for direct invocation: `runtime: ToolRuntime = None` - Add tests for the fix and workaround **Issue:** Fixes #6576 **Dependencies:** None **Twitter handle:** (add yours if you want a shoutout) - [x] **Add tests and docs**: If you're adding a new integration, you must include: 1. A test for the integration, preferably unit tests that do not rely on network access, 2. An example notebook showing its use. It lives in `docs/docs/integrations` directory. - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. We will not consider a PR unless these three are passing in CI. See [contribution guidelines](https://github.com/langchain-ai/langgraph/blob/main/CONTRIBUTING.md) for more. Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to `pyproject.toml` files (even optional ones) unless they are **required** for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible.
yindo added the pull-request label 2026-02-20 17:51:17 -05:00
yindo closed this issue 2026-02-20 17:51:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#5138