rig_agent/completion.rs
1//! Runtime errors for the classic agent runtime, plus the portable completion contracts.
2//!
3//! ```
4//! use rig_agent::completion::StructuredOutputError;
5//! let error = StructuredOutputError::EmptyResponse;
6//! assert!(error.provider_response_body().is_none());
7//! ```
8
9use thiserror::Error;
10
11pub use rig_core::completion::*;
12
13pub use crate::run::response::PromptError;
14
15crate::run::response::forward_provider_response_helpers!(
16 StructuredOutputError,
17 Prompt,
18 "prompt error"
19);
20
21/// Why a typed run produced no value.
22#[derive(Debug, Error)]
23pub enum StructuredOutputError {
24 /// The underlying run failed.
25 #[error(transparent)]
26 Prompt(#[from] PromptError),
27 /// The accepted output did not deserialize into the requested type.
28 #[error("structured output does not match the requested type: {error}")]
29 Deserialization {
30 /// The model's output that was parsed.
31 output: String,
32 /// Why it did not parse.
33 error: serde_json::Error,
34 },
35 /// The model returned no accepted content.
36 #[error("the model returned no structured output")]
37 EmptyResponse,
38}
39
40#[cfg(test)]
41mod provider_response_tests;