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(routing): warn when a custom classifier has one completion target (#752)

Elyas Mehtabuddin7573a69d2fc7
diff --git a/crates/switchyard-runner/src/algorithm.rs b/crates/switchyard-runner/src/algorithm.rs
index b3935a04c..c0630f199 100644
--- a/crates/switchyard-runner/src/algorithm.rs
+++ b/crates/switchyard-runner/src/algorithm.rs
@@ -1076,6 +1076,7 @@ fn build_subagent_router_config(
error,
)
})?;
+ warn_single_target_classifier(route_name, &config.models);
let mut classifier_config = CustomClassifierConfig::new(
config.prompt,
response_schema,
@@ -1206,6 +1207,7 @@ fn build_algorithm(
)
},
)?;
+ warn_single_target_classifier(route_name, &config.models);
let mut classifier_config = CustomClassifierConfig::new(
config.prompt,
response_schema,
@@ -1427,6 +1429,15 @@ fn default_classifier_max_output_tokens() -> u64 {
TaskClassifierConfig::default().max_output_tokens
}
+fn warn_single_target_classifier(route_name: &str, models: &CategoryModelConfig) {
+ if models.routing_names().len() < 2 {
+ tracing::warn!(
+ route = route_name,
+ "custom classifier has only one routing target; judge calls add cost without a routing choice. Use passthrough or add another completion target in routes.<name>, or in routes.<name>.subagents for a subagent classifier."
+ );
+ }
+}
+
fn resolve_target_model_id(
route_name: &str,
name: &str,
diff --git a/crates/switchyard-server/tests/cli.rs b/crates/switchyard-server/tests/cli.rs
index f72c45858..f7ce56ad3 100644
--- a/crates/switchyard-server/tests/cli.rs
+++ b/crates/switchyard-server/tests/cli.rs
@@ -43,3 +43,51 @@ target = "invalid"
);
Ok(())
}
+
+// A judge adds no routing choice when every completion category names the same target.
+#[test]
+fn dry_run_warns_when_custom_classifier_has_one_target() -> TestResult {
+ let directory = tempfile::tempdir()?;
+ let config = directory.path().join("routes.toml");
+ for (targets, warning_count) in [("[\"answer\"]", 1), ("[\"answer\", \"second\"]", 0)] {
+ fs::write(
+ &config,
+ format!(
+ r#"
+schema_version = 1
+[llm_clients.upstream]
+format = "openai_chat"
+base_url = "http://127.0.0.1:1/v1"
+[targets]
+judge = {{ id = "judge", llm_client = "upstream" }}
+answer = {{ id = "answer", llm_client = "upstream" }}
+second = {{ id = "second", llm_client = "upstream" }}
+[routes.custom]
+id = "custom"
+type = "llm_classifier"
+mode = "custom"
+models = {{ judge = ["judge"], any = {targets}, efficient = ["answer"] }}
+default_target = "efficient"
+prompt = "Choose efficient."
+response_schema = '{{"type":"object","properties":{{"target":{{"type":"string"}}}},"required":["target"],"additionalProperties":false}}'
+policy = {{ type = "target_selector", selector = "/target" }}
+"#
+ ),
+ )?;
+ let output = Command::new(env!("CARGO_BIN_EXE_switchyard-server"))
+ .args(["--config", config.to_string_lossy().as_ref(), "--dry-run"])
+ .env("RUST_LOG", "warn")
+ .output()?;
+ assert!(output.status.success());
+ let stdout = String::from_utf8(output.stdout)?;
+ let stderr = String::from_utf8(output.stderr)?;
+ assert!(stdout.contains("server OK: custom"));
+ let logs = format!("{stdout}{stderr}");
+ assert_eq!(
+ logs.matches("only one routing target").count(),
+ warning_count,
+ "{logs}"
+ );
+ }
+ Ok(())
+}