Skip to content

feat(tools): add structured error classification and recovery hints to tool error responses - #23157

Closed
netbrah wants to merge 1 commit into
google-gemini:mainfrom
netbrah:feat/structured-tool-error-feedback-23156
Closed

netbrah wants to merge 1 commit into
google-gemini:mainfrom
netbrah:feat/structured-tool-error-feedback-23156

Conversation

@netbrah

@netbrah netbrah commented Mar 19, 2026 •

Copy link
Copy Markdown

Summary

  • Add structured metadata (error_type, recoverable, hint) to tool error functionResponse.response so the model can distinguish recoverable errors from fatal ones and get actionable guidance
  • Update all three createErrorResponse sites (ToolExecutor, CoreToolScheduler, Scheduler) for consistency
  • Fix contentLength to use serialized response payload size instead of display text length

Details

Before:

{ "error": "Error: File not found: /src/utils/halper.ts" }

After:

{
  "error": "Error: File not found: /src/utils/halper.ts",
  "error_type": "file_not_found",
  "recoverable": true,
  "hint": "Verify the file path exists. Use glob or list_directory to find the correct path."
}

Changes:

  • tool-error.ts — getRecoveryHint() with lookup table mapping 10 ToolErrorType variants to hints
  • tool-executor.ts — structured error fields in ToolExecutor's createErrorResponse()
  • coreToolScheduler.ts — same enhancement to CoreToolScheduler's createErrorResponse()
  • scheduler.ts — same enhancement to Scheduler's createErrorResponse()
  • tool-error.test.ts — 14 tests for isFatalToolError and getRecoveryHint
  • tool-executor.test.ts — 3 tests for structured error response format
  • coreToolScheduler.test.ts — added structured field assertions to policy violation tests

Backward compatible — new fields only appear when errorType is defined. No interface changes, no new dependencies.

How to Validate

```bash
npx -w @google/gemini-cli-core vitest run src/tools/tool-error.test.ts src/scheduler/tool-executor.test.ts src/core/coreToolScheduler.test.ts
```

All 53 tests pass. tsc --noEmit clean.

Fixes #23156

@netbrah
netbrah requested review from a team as code owners March 19, 2026 21:04
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly improves the robustness of tool error handling by providing more detailed and actionable information to the model. By embedding structured metadata like error type, recoverability, and specific hints directly into tool error responses, the system enables more intelligent and adaptive error recovery strategies. This enhancement ensures that the model can distinguish between different error conditions and receive guidance on how to proceed, leading to more resilient and effective tool interactions.

Highlights

  • Structured Error Metadata: Added structured metadata, including error_type, recoverable status, and a hint for recovery, to tool error responses. This allows the model to better interpret and respond to errors.
  • Consistent Error Response Generation: Updated the createErrorResponse implementations across ToolExecutor, CoreToolScheduler, and Scheduler to consistently generate these new structured error fields.
  • Accurate Content Length Calculation: Fixed the contentLength calculation to accurately reflect the size of the serialized JSON response payload, rather than just the display text length.
  • Comprehensive Testing: Introduced new unit tests for isFatalToolError and getRecoveryHint functions, and added assertions to existing tests to validate the presence and correctness of the new structured error fields in various scenarios.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces structured error classification and recovery hints to tool error responses, which is a significant improvement for the model's ability to understand and self-correct from tool failures. The changes are consistently applied across ToolExecutor, CoreToolScheduler, and Scheduler, ensuring a unified approach to error reporting. The update to contentLength calculation to use the serialized response payload size is also a correct and necessary adjustment. Comprehensive test cases have been added for isFatalToolError, getRecoveryHint, and the structured error response format, demonstrating thorough validation of the new functionality.

@netbrah
netbrah force-pushed the feat/structured-tool-error-feedback-23156 branch from 4b323b6 to c80307c Compare March 19, 2026 21:14
@gemini-cli gemini-cli Bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Mar 19, 2026
…o tool error responses

Tool error responses sent to the model were unstructured strings, forcing
the model to infer error category and recovery strategy from natural language.

- Add getRecoveryHint() with lookup table mapping ToolErrorType variants to
  actionable recovery hints
- Include error_type, recoverable, and hint fields in functionResponse.response
  when errorType is available
- Update all three createErrorResponse sites (ToolExecutor, CoreToolScheduler,
  Scheduler) for consistency
- Fix contentLength to use serialized response size instead of display text
- Add test coverage for structured error fields in coreToolScheduler

Backward compatible — new fields only appear when errorType is defined.

Fixes google-gemini#23156

Made-with: Cursor
@gemini-cli

gemini-cli Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

@gemini-cli gemini-cli Bot closed this Apr 3, 2026
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add structured error classification and recovery hints to tool error responses

2 participants