mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
refactor(python-bridge): report row errors from the catalog's own kind and policy
RowError takes its kind from ErrorKind, rejects from Error::rejects, key and field from Located, and renders its message with Report so a JSON cause is kept. The bridge's hand-copied RowErrorKind enum and pointer parsing are gone, and RowErrorKind gains unread_field and no_fallback_rules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb9a261d61
commit
9f1de4e4f0
4 changed files with 12 additions and 98 deletions
|
|
@ -79,7 +79,7 @@ mod _native {
|
|||
let literal = typing.getattr("Literal")?;
|
||||
let row_error_kinds = PyTuple::new(
|
||||
py,
|
||||
<crate::model_registry::RowErrorKind as strum::VariantArray>::VARIANTS
|
||||
<litellm_model_catalog::ErrorKind as strum::VariantArray>::VARIANTS
|
||||
.iter()
|
||||
.map(|kind| literal.get_item(<&'static str>::from(*kind)))
|
||||
.collect::<PyResult<Vec<_>>>()?,
|
||||
|
|
@ -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(),
|
||||
])
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<Arc<Contents>> = LazyLock::new(|| {
|
||||
let loaded = Catalog::parse(BUNDLED_REGISTRY).expect("the bundled model registry parses");
|
||||
|
|
|
|||
|
|
@ -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::<Vec<_>>();
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ RowErrorKind = Literal[
|
|||
"no_off_peak_hours",
|
||||
"empty_list",
|
||||
"invalid_date",
|
||||
"unread_field",
|
||||
"no_fallback_rules",
|
||||
]
|
||||
|
||||
@final
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue