Fail closed for high-risk tools without explicit confirmation policy#4626
Fail closed for high-risk tools without explicit confirmation policy#4626davidahmann wants to merge 1 commit intogoogle:mainfrom
Conversation
Summary of ChangesHello @davidahmann, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the safety boundaries of tool execution by introducing a "fail-closed" policy for high-risk tools. Previously, such tools could execute without explicit confirmation if a policy was missing or permissive. The changes ensure that any tool designated as high-risk will now explicitly error out if a clear confirmation policy is not defined, thereby preventing unintended or unsafe operations and reducing potential blast radius. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Implemented high-risk tool fail-closed behavior for FunctionTool and MCP tools when explicit confirmation policy is not enabled, with focused unit coverage for both paths. This contribution was informed by patterns from Wrkr. Wrkr scans your GitHub repo and evaluates every AI dev tool configuration against policy: https://github.com/Clyra-AI/wrkr |
There was a problem hiding this comment.
Code Review
This pull request successfully implements the "fail closed" behavior for high-risk tools by adding an is_high_risk flag. The changes ensure that high-risk tools will return an error if a confirmation policy is not explicitly enabled, which enhances safety. The implementation is consistent across FunctionTool and MCPTool, and the new behavior is well-tested. My main feedback is to extract the duplicated error message into a shared constant to improve maintainability.
| 'error': ( | ||
| 'This high-risk tool requires an explicit confirmation policy.' | ||
| ' Set require_confirmation=True or provide a callable policy' | ||
| ' that returns True.' | ||
| ) |
There was a problem hiding this comment.
This error message is duplicated in src/google/adk/tools/mcp_tool/mcp_tool.py and also hardcoded in the corresponding test files (tests/unittests/tools/test_function_tool.py and tests/unittests/tools/mcp_tool/test_mcp_tool.py). To improve maintainability and avoid inconsistencies, it's best to define this string as a constant in a shared module (e.g., a new src/google/adk/tools/constants.py) and import it in all places where it's used. This ensures that any future changes to the message only need to be made in one place.
Problem
High-risk tools can execute when confirmation policy is missing or permissive, which weakens safety boundaries and increases blast radius for tool-invocation mistakes.
Why now
Issue #4625 requests fail-closed behavior for high-risk tooling so unsafe operations are blocked unless explicit confirmation policy exists.
What changed
is_high_risksupport forFunctionTooland MCP tools.Validation
uv run pyink --check --diff src/google/adk/tools/function_tool.py src/google/adk/tools/mcp_tool/mcp_tool.py src/google/adk/tools/mcp_tool/mcp_toolset.py tests/unittests/tools/test_function_tool.py tests/unittests/tools/mcp_tool/test_mcp_tool.py(pass)uv run pytest tests/unittests/tools/test_function_tool.py tests/unittests/tools/mcp_tool/test_mcp_tool.py -k 'high_risk_without_confirmation_policy or require_confirmation'(pass)Refs #4625