Skip to main content

systemprompt_models/profile/gateway/
error.rs

1//! Failure modes emitted while validating the gateway's references into the
2//! provider registry: duplicate route ids, and a route or `default_provider`
3//! naming a provider absent from `profile.providers`.
4//!
5//! Copyright (c) systemprompt.io — Business Source License 1.1.
6//! See <https://systemprompt.io> for licensing details.
7
8use thiserror::Error;
9
10#[derive(Debug, Error)]
11pub enum GatewayProfileError {
12    #[error("gateway route id '{id}' is declared more than once")]
13    DuplicateRouteId { id: String },
14
15    #[error("gateway route '{route}' provider '{provider}' is not declared in profile.providers")]
16    RouteProviderNotInRegistry { route: String, provider: String },
17
18    #[error("gateway default_provider '{provider}' is not declared in profile.providers")]
19    DefaultProviderNotInRegistry { provider: String },
20
21    #[error("system_prompt override with action 'replace' must set a 'prompt'")]
22    OverrideReplaceMissingPrompt,
23
24    #[error("system_prompt override with action 'strip' must not set a 'prompt'")]
25    OverrideStripWithPrompt,
26
27    #[error("system_prompt override provider '{provider}' is not declared in profile.providers")]
28    OverrideProviderNotInRegistry { provider: String },
29
30    #[error("route `when.min_tools` must be at least 1 (0 matches every request)")]
31    RouteMatchZeroMinTools,
32
33    #[error("route `when` sets `requires_tools: false` but also a positive `min_tools`")]
34    RouteMatchContradictoryTools,
35
36    #[error(
37        "gateway route '{route}' (model_pattern '{pattern}') reaches no priced model: provider \
38         '{provider}' declares no model matching the pattern and the route sets no `pricing:` \
39         override, so every request it dispatches would be billed at zero"
40    )]
41    RouteReachesNoPricedModel {
42        route: String,
43        pattern: String,
44        provider: String,
45    },
46
47    #[error(
48        "gateway route '{route}' can dispatch model '{model}', which has no usable `pricing:` \
49         (input_per_million and output_per_million must both be non-zero, or per_image_cents set)"
50    )]
51    RouteModelUnpriced { route: String, model: String },
52}
53
54pub type GatewayResult<T> = Result<T, GatewayProfileError>;