Skip to main content

litellm_rs/config/validation/
cache_validators.rs

1//! Cache and rate limit configuration validators
2//!
3//! This module provides validation implementations for cache and rate limiting
4//! configuration structures including CacheConfig and RateLimitConfig.
5
6use super::trait_def::Validate;
7use crate::config::models::cache::CacheConfig;
8use crate::config::models::rate_limit::RateLimitConfig;
9
10impl Validate for CacheConfig {
11    fn validate(&self) -> Result<(), String> {
12        if self.enabled && self.ttl == 0 {
13            return Err("cache.ttl must be greater than 0 when cache.enabled=true".to_string());
14        }
15
16        Ok(())
17    }
18}
19
20impl Validate for RateLimitConfig {
21    fn validate(&self) -> Result<(), String> {
22        if !self.enabled {
23            return Ok(());
24        }
25
26        if self.effective_rpm() == 0 {
27            return Err("Effective RPM must be greater than 0".to_string());
28        }
29
30        if self.default_tpm == 0 {
31            return Err("Default TPM must be greater than 0".to_string());
32        }
33
34        let unimplemented = self.unimplemented_runtime_field_names();
35        if !unimplemented.is_empty() {
36            return Err(format!(
37                "rate_limit fields [{}] are parsed but not enforced yet; leave them unset until support lands",
38                unimplemented.join(", ")
39            ));
40        }
41
42        Ok(())
43    }
44}