feat(core): GovernanceCallbackHandler for tool execution authorization#35529
Open
Devon Generally (devongenerally-png) wants to merge 2 commits intolangchain-ai:masterfrom
Open
Conversation
Adds a callback handler that enforces deterministic governance policies on tool calls via the PROPOSE/DECIDE/PROMOTE pattern: - PROPOSE: Converts tool calls into structured intents with SHA-256 hash - DECIDE: Evaluates intents against user-defined policy rules (no LLM) - PROMOTE: Allows approved calls, raises ToolExecutionDenied for denied Includes hash-chained witness logging for audit trails and 24 unit tests covering policy evaluation, constraint checking, chain integrity, and tamper detection. Uses raise_error=True (default) so denied tools propagate as exceptions via the existing handle_event mechanism — no core changes required. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Merging this PR will not alter performance
|
WitnessLog previously reset prev_hash to genesis on every init, breaking the hash chain when appending to an existing log file. Now reads the last entry's hash from the file on startup. Adds test verifying chain integrity across handler restarts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Adds
GovernanceCallbackHandler— a callback handler that enforces deterministic governance policies on tool calls using the existingon_tool_start/raise_errormechanism. No core changes required.What it does
Implements a three-phase authorization pipeline for tool calls:
on_tool_startinvocation into a structured intent object with a SHA-256 content hashToolExecutionDeniedfor denied calls (propagated viaraise_error=True)Policy format
Witness logging
Optional hash-chained audit trail (
witness_pathparameter). Each entry links to the previous via SHA-256, making tampering detectable. Includesverify_witness_log()utility for independent chain verification.Changes
libs/core/langchain_core/callbacks/governance.py— handler implementationlibs/core/tests/unit_tests/callbacks/test_governance.py— 24 unit testsDesign decisions
raise_error = Trueby default — the handler must be able to block tool execution. This uses the existinghandle_eventexception propagation, requiring zero changes to the callback manager.deny. Unknown tools require explicit policy approval.Test plan
For a more complete standalone implementation with YAML policy files and adversarial test coverage, see Governance-Guard.