Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

fix: Delete an unnecessary callback, fix default log level (#471)

Graham Kingc7c07d52d2d8
diff --git a/crates/libsy/src/algorithms/fall_through.rs b/crates/libsy/src/algorithms/fall_through.rs
index 4aa06c6b4..8bfcd95ca 100644
--- a/crates/libsy/src/algorithms/fall_through.rs
+++ b/crates/libsy/src/algorithms/fall_through.rs
@@ -91,7 +91,6 @@ impl<S: Send> Classifier<S> for DefaultTarget {
/// The generic state type is shared by every processor and classifier in the composition.
pub struct FallThrough<S = ()> {
name: String,
- decision_reason: fn(&str, &Score) -> String,
processors: Vec<Arc<dyn Processor<S>>>,
classifiers: Vec<Arc<dyn Classifier<S>>>,
targets: Vec<ModelId>,
@@ -104,7 +103,6 @@ impl FallThrough<()> {
pub fn new(targets: Vec<ModelId>) -> Self {
Self {
name: "fall_through".to_string(),
- decision_reason: default_decision_reason,
processors: Vec::new(),
classifiers: Vec::new(),
targets,
@@ -122,7 +120,6 @@ where
pub fn new_with_state(targets: Vec<ModelId>) -> Self {
Self {
name: "fall_through".to_string(),
- decision_reason: default_decision_reason,
processors: Vec::new(),
classifiers: Vec::new(),
targets,
@@ -137,12 +134,6 @@ where
self
}
- /// Sets the decision log message for an algorithm assembled from this cascade.
- pub(crate) fn with_decision_reason(mut self, reason: fn(&str, &Score) -> String) -> Self {
- self.decision_reason = reason;
- self
- }
-
/// Appends a processor to the head-of-request chain.
pub fn with_processor(mut self, processor: Arc<dyn Processor<S>>) -> Self {
self.processors.push(processor);
@@ -273,9 +264,9 @@ where
// 3. Resolve the target and log the choice.
algorithm::ensure_model_is_target(&self.targets, &score.target)?;
let target = score.target.clone();
- let message = (self.decision_reason)(&self.name, &score);
- let message = with_routing_tier(message, deciding.routing_tier(&target));
- tracing::info!("{message}");
+ let tier = deciding.routing_tier(&target);
+ tracing::info!(algorithm=self.name, target=%score.target, confidence=score.confidence, tier = ?tier, "Model selected");
+
// 4. Post-decision replay: every processor sees the selection so stateful ones
// can bind it, and may rewrite the outbound request (e.g. add a target prompt).
for processor in &self.processors {
@@ -325,21 +316,6 @@ fn session_id(request: &Request) -> Option<String> {
.map(str::to_string)
}
-fn default_decision_reason(_name: &str, winner: &Score) -> String {
- format!(
- "fall-through selected {} (confidence {:.3})",
- winner.target, winner.confidence
- )
-}
-
-/// Appends the routing tier to a decision log message when the classifier supplies one.
-fn with_routing_tier(message: String, tier: Option<&str>) -> String {
- match tier {
- Some(tier) => format!("{message}; routing tier: {tier}"),
- None => message,
- }
-}
-
#[async_trait]
impl<S> Algorithm for FallThrough<S>
where
diff --git a/crates/libsy/src/algorithms/rand.rs b/crates/libsy/src/algorithms/rand.rs
index e3e04b034..87f89ca61 100644
--- a/crates/libsy/src/algorithms/rand.rs
+++ b/crates/libsy/src/algorithms/rand.rs
@@ -142,16 +142,11 @@ impl Random {
let classifier = Arc::new(RandomClassifier::new(targets.clone(), weights, seed)?);
let inner = FallThrough::<()>::new(targets)
.with_name("random")
- .with_decision_reason(random_decision_reason)
.with_classifier(classifier);
Ok(Self { inner })
}
}
-fn random_decision_reason(_name: &str, winner: &Score) -> String {
- format!("random routing selected target '{}'", winner.target)
-}
-
#[async_trait]
impl Algorithm for Random {
fn name(&self) -> &str {
diff --git a/crates/switchyard-server/src/observability.rs b/crates/switchyard-server/src/observability.rs
index cd3a76462..51da1e66e 100644
--- a/crates/switchyard-server/src/observability.rs
+++ b/crates/switchyard-server/src/observability.rs
@@ -19,7 +19,7 @@ use tracing_subscriber::{EnvFilter, Layer as _};
use crate::{ServerError, ServerResult, metrics};
-const DEFAULT_LOG_FILTER: &str = "switchyard_server=info,libsy=info,opentelemetry=warn";
+const DEFAULT_LOG_FILTER: &str = "info,opentelemetry=warn";
const DEFAULT_SERVICE_NAME: &str = "switchyard-server";
struct Observability {