feat(langchain, core): add provenance-based execution guard for side-effecting tools#35299
Draft
NITIN Madan (Nitin75408) wants to merge 1 commit intolangchain-ai:masterfrom
Draft
feat(langchain, core): add provenance-based execution guard for side-effecting tools#35299NITIN Madan (Nitin75408) wants to merge 1 commit intolangchain-ai:masterfrom
NITIN Madan (Nitin75408) wants to merge 1 commit intolangchain-ai:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Fixes #34469
Adds an optional, deterministic provenance guard that prevents side-effecting tools from executing with hallucinated arguments. The invariant: no tool with side_effects=True should execute unless every argument can be traced to a value from a prior trusted tool output or user input in the same session.
Changes:
Add side_effects: bool = False field to BaseTool in langchain-core for first-class side-effect classification
Expose side_effects parameter on the tool decorator across all overload signatures
Implement ProvenanceMiddleware using the wrap_tool_call hook — scans message history for trusted text (successful ToolMessage outputs + HumanMessage inputs), blocks execution if any argument value can't be found via substring match, returns error ToolMessage without executing
Export ProvenanceMiddleware from langchain.agents.middleware
Design decisions worth reviewing:
Provenance is stateless — rebuilt from message history each call, no custom state schema needed
Enforcement uses substring matching (str(value) in combined_trusted_text) — simple, deterministic, no heuristics
Trivial values (booleans, None, strings shorter than min_value_length) are skipped
Fully opt-in: side_effects defaults to False, middleware must be explicitly added. Zero behavior change for existing users
include_user_inputs (default True) and min_value_length (default 3) are configurable
Verification:
make format, make lint, make test pass for both libs/core (1650 passed) and libs/langchain_v1 (793 passed)
4 new tests in libs/core for side_effects on the tool decorator
13 new tests in libs/langchain_v1 covering: blocked execution without provenance, allowed execution with provenance, non-side-effecting tools unaffected, backward compat without middleware, user input as provenance (enabled/disabled), trivial value skipping, partial provenance blocking, full read-then-write flow, async variants