#[non_exhaustive]pub struct ToolFailure {
pub kind: ToolFailureKind,
pub message: String,
pub retryable: Option<bool>,
pub code: Option<String>,
pub http_status: Option<u16>,
}Expand description
A structured, model-independent description of a tool execution failure.
This is the “machine-visible” half of a failed tool call. The model-visible
text lives separately on ToolExecutionResult::model_output; this carries
the classification a hook or policy acts on. Build one with the per-kind
constructors (which pre-fill a sensible retryable default)
and refine it with the builder setters:
use rig_core::tool::{ToolFailure, ToolFailureKind};
let failure = ToolFailure::not_found("user 42 does not exist")
.with_http_status(404)
.with_code("USER_NOT_FOUND");
assert_eq!(failure.kind, ToolFailureKind::NotFound);
assert_eq!(failure.retryable, Some(false));
assert_eq!(failure.http_status, Some(404));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.kind: ToolFailureKindThe standard classification of the failure.
message: StringA human-readable description of what went wrong. This is not automatically shown to the model — it is metadata for logs and policies.
retryable: Option<bool>Whether retrying the call could plausibly succeed. None means unknown.
code: Option<String>An optional machine-readable error code (e.g. a provider error code).
http_status: Option<u16>An optional HTTP status code, when the failure originated from an HTTP call.
Implementations§
Source§impl ToolFailure
impl ToolFailure
Sourcepub fn new(kind: ToolFailureKind, message: impl Into<String>) -> Self
pub fn new(kind: ToolFailureKind, message: impl Into<String>) -> Self
Construct a failure of the given kind with message. retryable,
code, and http_status start unset — use the builder setters or a
per-kind constructor to fill them.
Sourcepub fn invalid_args(message: impl Into<String>) -> Self
pub fn invalid_args(message: impl Into<String>) -> Self
An InvalidArgs failure.
Sourcepub fn permission_denied(message: impl Into<String>) -> Self
pub fn permission_denied(message: impl Into<String>) -> Self
A PermissionDenied failure.
Sourcepub fn rate_limited(message: impl Into<String>) -> Self
pub fn rate_limited(message: impl Into<String>) -> Self
A RateLimited failure.
Sourcepub fn with_retryable(self, retryable: bool) -> Self
pub fn with_retryable(self, retryable: bool) -> Self
Set whether the failure is retryable.
Sourcepub fn with_http_status(self, status: u16) -> Self
pub fn with_http_status(self, status: u16) -> Self
Set the originating HTTP status code.
Trait Implementations§
Source§impl Clone for ToolFailure
impl Clone for ToolFailure
Source§fn clone(&self) -> ToolFailure
fn clone(&self) -> ToolFailure
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ToolFailure
impl Debug for ToolFailure
Source§impl Display for ToolFailure
impl Display for ToolFailure
impl Eq for ToolFailure
Source§impl Error for ToolFailure
impl Error for ToolFailure
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for ToolFailure
impl PartialEq for ToolFailure
impl StructuralPartialEq for ToolFailure
Auto Trait Implementations§
impl Freeze for ToolFailure
impl RefUnwindSafe for ToolFailure
impl Send for ToolFailure
impl Sync for ToolFailure
impl Unpin for ToolFailure
impl UnsafeUnpin for ToolFailure
impl UnwindSafe for ToolFailure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
impl<T> DebuggableStorage for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.