Python SDK: add ToolError exception to surface tool failures to the LLM#1404
Open
idryzhov wants to merge 1 commit into
Open
Python SDK: add ToolError exception to surface tool failures to the LLM#1404idryzhov wants to merge 1 commit into
idryzhov wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a first-class way for tool handlers to intentionally return an LLM-visible failure message via a new ToolError exception.
Changes:
- Introduces
ToolErrorexception type to represent intentional, user-facing tool failures. - Updates tool invocation wrapper to catch
ToolErrorand surface its message verbatim to the LLM. - Adds a unit test asserting
ToolErrorpropagation behavior and_from_exceptionsemantics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/copilot/tools.py | Adds ToolError and special-case handling to return an LLM-visible failure ToolResult. |
| python/copilot/init.py | Exports ToolError as part of the public package API. |
| python/test_tools.py | Adds coverage ensuring ToolError is surfaced to the LLM as intended. |
Tool handlers can now raise ToolError("message") to return a structured
failure result whose message is intentionally forwarded to the LLM as
text_result_for_llm.
This simplifies handler code: a tool that wants to signal a recoverable
failure to the LLM can simply 'raise ToolError("...")' instead of having
to construct and return a full ToolResult(result_type="failure", ...)
manually. The raise-and-return paths now look symmetric for success and
failure.
Other exception types continue to be caught and hidden behind the generic
'Invoking this tool produced an error' message for security.
6f21043 to
e801a04
Compare
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.
Tool handlers can now raise
ToolError("message")to return a structured failure result whose message is intentionally forwarded to the LLM astext_result_for_llm.This simplifies handler code: a tool that wants to signal a recoverable failure to the LLM can simply
raise ToolError("...")instead of having to construct and return a fullToolResult(result_type="failure", ...)manually. The raise-and-return paths now look symmetric for success and failure.Other exception types continue to be caught and hidden behind the generic
Invoking this tool produced an errormessage for security.