struct_llm/
error.rs

1//! Error types for struct-llm
2
3use thiserror::Error;
4
5/// Errors that can occur when working with structured LLM outputs
6#[derive(Debug, Error)]
7pub enum Error {
8    /// JSON parsing or serialization error
9    #[error("JSON error: {0}")]
10    Json(#[from] serde_json::Error),
11
12    /// Schema validation failed
13    #[error("Schema validation failed: {0}")]
14    ValidationFailed(String),
15
16    /// No tool calls found in the response
17    #[error("No tool calls found in response")]
18    NoToolCalls,
19
20    /// Tool call name doesn't match expected tool
21    #[error("Tool call '{0}' does not match expected tool '{1}'")]
22    ToolMismatch(String, String),
23
24    /// Invalid response format from provider
25    #[error("Invalid response format from provider: {0}")]
26    InvalidResponseFormat(String),
27
28    /// Missing required field in response
29    #[error("Missing required field: {0}")]
30    MissingField(String),
31}
32
33/// Result type alias for struct-llm operations
34pub type Result<T> = std::result::Result<T, Error>;