diff --git a/litellm-rust/crates/python-bridge/src/lib.rs b/litellm-rust/crates/python-bridge/src/lib.rs index 9ff33b6df35..715d4215fc2 100644 --- a/litellm-rust/crates/python-bridge/src/lib.rs +++ b/litellm-rust/crates/python-bridge/src/lib.rs @@ -79,7 +79,7 @@ mod _native { let literal = typing.getattr("Literal")?; let row_error_kinds = PyTuple::new( py, - ::VARIANTS + ::VARIANTS .iter() .map(|kind| literal.get_item(<&'static str>::from(*kind))) .collect::>>()?, @@ -227,6 +227,8 @@ mod tests { "no_off_peak_hours".to_owned(), "empty_list".to_owned(), "invalid_date".to_owned(), + "unread_field".to_owned(), + "no_fallback_rules".to_owned(), ]) ); }); diff --git a/litellm-rust/crates/python-bridge/src/model_registry.rs b/litellm-rust/crates/python-bridge/src/model_registry.rs index e010ea45846..a8c3ef79fdc 100644 --- a/litellm-rust/crates/python-bridge/src/model_registry.rs +++ b/litellm-rust/crates/python-bridge/src/model_registry.rs @@ -17,7 +17,7 @@ use serde::Serialize; use sha1::{Digest, Sha1}; use install::BoundDict; -pub(crate) use row_error::{RowError, RowErrorKind, row_error}; +pub(crate) use row_error::{RowError, row_error}; static BUNDLED: LazyLock> = LazyLock::new(|| { let loaded = Catalog::parse(BUNDLED_REGISTRY).expect("the bundled model registry parses"); diff --git a/litellm-rust/crates/python-bridge/src/model_registry/row_error.rs b/litellm-rust/crates/python-bridge/src/model_registry/row_error.rs index 99bd7f1595f..18cc88dc855 100644 --- a/litellm-rust/crates/python-bridge/src/model_registry/row_error.rs +++ b/litellm-rust/crates/python-bridge/src/model_registry/row_error.rs @@ -1,58 +1,5 @@ -use litellm_model_catalog::{Error, Located}; +use litellm_model_catalog::{Located, Rejects}; use pyo3::prelude::*; -use strum::{IntoStaticStr, VariantArray}; - -#[derive(Clone, Copy, Debug, IntoStaticStr, PartialEq, Eq, VariantArray)] -pub(crate) enum RowErrorKind { - #[strum(serialize = "json")] - Json, - #[strum(serialize = "empty")] - Empty, - #[strum(serialize = "below_minimum")] - BelowMinimum, - #[strum(serialize = "shrunk")] - Shrunk, - #[strum(serialize = "not_an_object")] - NotAnObject, - #[strum(serialize = "invalid")] - Invalid, - #[strum(serialize = "unknown_block_key")] - UnknownBlockKey, - #[strum(serialize = "missing_provider")] - MissingProvider, - #[strum(serialize = "unknown_timezone")] - UnknownTimezone, - #[strum(serialize = "alias_shadows_model")] - AliasShadowsModel, - #[strum(serialize = "alias_taken")] - AliasTaken, - #[strum(serialize = "duplicate_price")] - DuplicatePrice, - #[strum(serialize = "suffix_inside_block")] - SuffixInsideBlock, - #[strum(serialize = "tier_range")] - TierRange, - #[strum(serialize = "tier_reversed")] - TierReversed, - #[strum(serialize = "tier_gap")] - TierGap, - #[strum(serialize = "mixed_tier_basis")] - MixedTierBasis, - #[strum(serialize = "not_priced_by_results")] - NotPricedByResults, - #[strum(serialize = "bands_from_two_sources")] - BandsFromTwoSources, - #[strum(serialize = "not_an_off_peak_rate")] - NotAnOffPeakRate, - #[strum(serialize = "no_off_peak_prices")] - NoOffPeakPrices, - #[strum(serialize = "no_off_peak_hours")] - NoOffPeakHours, - #[strum(serialize = "empty_list")] - EmptyList, - #[strum(serialize = "invalid_date")] - InvalidDate, -} #[pyclass(frozen, skip_from_py_object, module = "litellm.rust_bridge._native")] #[derive(Clone, Debug)] @@ -70,48 +17,11 @@ pub(crate) struct RowError { } pub(crate) fn row_error(error: &Located) -> RowError { - let mut path = error.path.split('/').skip(1); - let key = unescape_pointer_segment(path.next().unwrap_or_default()); - let field = path.map(unescape_pointer_segment).collect::>(); - let field = (!field.is_empty()).then(|| field.join("/")); RowError { - key, - field, - kind: <&'static str>::from(error_kind(&error.error)).to_owned(), - rejects: litellm_model_catalog::rejects_row(&error.error), - message: error.error.to_string(), - } -} - -fn unescape_pointer_segment(segment: &str) -> String { - segment.replace("~1", "/").replace("~0", "~") -} - -fn error_kind(error: &Error) -> RowErrorKind { - match error { - Error::Json(_) => RowErrorKind::Json, - Error::Empty => RowErrorKind::Empty, - Error::BelowMinimum { .. } => RowErrorKind::BelowMinimum, - Error::Shrunk { .. } => RowErrorKind::Shrunk, - Error::NotAnObject => RowErrorKind::NotAnObject, - Error::Invalid(_) => RowErrorKind::Invalid, - Error::UnknownBlockKey => RowErrorKind::UnknownBlockKey, - Error::MissingProvider => RowErrorKind::MissingProvider, - Error::UnknownTimezone { .. } => RowErrorKind::UnknownTimezone, - Error::AliasShadowsModel { .. } => RowErrorKind::AliasShadowsModel, - Error::AliasTaken { .. } => RowErrorKind::AliasTaken, - Error::DuplicatePrice { .. } => RowErrorKind::DuplicatePrice, - Error::SuffixInsideBlock { .. } => RowErrorKind::SuffixInsideBlock, - Error::TierRange => RowErrorKind::TierRange, - Error::TierReversed => RowErrorKind::TierReversed, - Error::TierGap { .. } => RowErrorKind::TierGap, - Error::MixedTierBasis => RowErrorKind::MixedTierBasis, - Error::NotPricedByResults => RowErrorKind::NotPricedByResults, - Error::BandsFromTwoSources => RowErrorKind::BandsFromTwoSources, - Error::NotAnOffPeakRate => RowErrorKind::NotAnOffPeakRate, - Error::NoOffPeakPrices => RowErrorKind::NoOffPeakPrices, - Error::NoOffPeakHours => RowErrorKind::NoOffPeakHours, - Error::EmptyList => RowErrorKind::EmptyList, - Error::InvalidDate => RowErrorKind::InvalidDate, + key: error.key().unwrap_or_default(), + field: error.field(), + kind: <&'static str>::from(error.error.kind()).to_owned(), + rejects: error.error.rejects() == Rejects::Row, + message: litellm_error::Report::new(&error.error).to_string(), } } diff --git a/litellm/rust_bridge/_native.pyi b/litellm/rust_bridge/_native.pyi index a599f131b0a..714e137db64 100644 --- a/litellm/rust_bridge/_native.pyi +++ b/litellm/rust_bridge/_native.pyi @@ -42,6 +42,8 @@ RowErrorKind = Literal[ "no_off_peak_hours", "empty_list", "invalid_date", + "unread_field", + "no_fallback_rules", ] @final