#[non_exhaustive]pub struct OnToolErrorContext {
pub tool_name: String,
pub tool_args: Value,
pub error: String,
pub metadata: Value,
}Expand description
Context passed to HookPoint::OnToolError hooks.
§Error contract
A Rust tool signals failure in one of two ways, and only one of them reaches this hook:
- Returning
Err(ToolError)is a hard error. The model sees exactlyToolError::to_string()(the human-readablemessage), and this hook fires. Any structuredmetadataattached to theToolError— which is never shown to the model — is surfaced here onmetadataso host code can branch on it. - Returning
Ok(ToolOutput)is a soft result: it is delivered to thePostToolCallhook instead, carrying its ownresultstring andmetadata.
This makes success and error handling symmetric: both
PostToolCallContext and OnToolErrorContext carry structured
metadata alongside their model-facing payload.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.tool_name: StringName of the tool that errored.
tool_args: ValueArguments the tool received.
error: StringThe error message — exactly what the model sees
(ToolError::to_string()).
metadata: ValueStructured metadata attached to the originating
ToolError, if any.
This is the error-path counterpart to
PostToolCallContext::metadata. It is populated from the
ToolError’s metadata map and is never sent to the model — it
exists purely for hooks, policies, and logging. Defaults to
serde_json::Value::Null when the error carried no metadata.
Implementations§
Source§impl OnToolErrorContext
impl OnToolErrorContext
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Whether the error denotes a registry-lookup miss, i.e. the model asked for a tool that isn’t registered.
This mirrors ToolError::is_not_found:
it inspects metadata for the
ERROR_KIND_KEY marker set to
KIND_NOT_REGISTERED,
letting hosts distinguish a routing miss from a genuine handler failure
without matching on message strings.
Trait Implementations§
Source§impl Clone for OnToolErrorContext
impl Clone for OnToolErrorContext
Source§fn clone(&self) -> OnToolErrorContext
fn clone(&self) -> OnToolErrorContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more