Skip to content

feat(langchain): add tool error middleware - #11201

Merged
Hunter Lovell (hntrl) merged 4 commits into
mainfrom
feat/tool-error-middleware
Jul 14, 2026
Merged

Hunter Lovell (hntrl) merged 4 commits into
mainfrom
feat/tool-error-middleware

Conversation

@hntrl

Copy link
Copy Markdown
Member

Summary

Ports ToolErrorMiddleware from langchain-ai/langchain#38781 to LangChain.js. The new middleware lets agents selectively convert tool execution failures into model-visible error messages while preserving original exceptions by default.

Changes

  • Add and export toolErrorMiddleware, ToolErrorHandler, and ToolErrorMiddlewareConfig from langchain.
  • Support synchronous or asynchronous error handlers and structured ToolMessage content.
  • Allow handling to be restricted by tool name or tool instance.
  • Propagate unhandled failures and LangGraph control-flow signals unchanged, avoiding disclosure of raw exception details unless the handler explicitly includes them.
  • Add focused coverage for error handling, propagation, filtering, structured content, disclosure control, and graph interrupts.

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a721576

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
langchain Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@open-swe open-swe 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.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment thread libs/langchain/src/agents/middleware/toolError.ts
@hntrl
Hunter Lovell (hntrl) merged commit a8cd4d9 into main Jul 14, 2026
35 checks passed
@hntrl
Hunter Lovell (hntrl) deleted the feat/tool-error-middleware branch July 14, 2026 23:18
Hunter Lovell (hntrl) pushed a commit that referenced this pull request Jul 24, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## langchain@1.5.4

### Patch Changes

- [#11201](#11201)
[`a8cd4d9`](a8cd4d9)
Thanks [@hntrl](https://github.com/hntrl)! - feat(langchain): add
middleware for handling tool execution errors
## @langchain/anthropic@1.5.2

### Patch Changes

- [#11255](#11255)
[`c8bd4c4`](c8bd4c4)
Thanks [@hntrl](https://github.com/hntrl)! - feat(anthropic): add
claude-opus-5 support

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant