From 8ee5bf2c38528770620d33ead1d1042c6758287b Mon Sep 17 00:00:00 2001 From: Umesh Yadav <23421535+imumesh18@users.noreply.github.com> Date: Wed, 16 Jul 2025 21:14:08 +0530 Subject: [PATCH] open_router: Fix tool_choice getting serialized to null (#34532) Closes #34314 This PR resolves an issue where serde(untagged) caused Rust None values to serialize as null, which OpenRouter's Mistral API (when tool_choice is present) incorrectly interprets as a defined value, leading to a 400 error. By replacing serde(untagged) with serde(snake_case), None values are now correctly omitted from the serialized JSON, fixing the problem. P.S. A separate PR will address serde(untagged) usage for other providers, as null is not expected for them either. Release Notes: - Fix ToolChoice getting serialized to null on OpenRouter --- crates/open_router/src/open_router.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/open_router/src/open_router.rs b/crates/open_router/src/open_router.rs index 4128426a7f..3e6e406d98 100644 --- a/crates/open_router/src/open_router.rs +++ b/crates/open_router/src/open_router.rs @@ -153,11 +153,12 @@ pub struct RequestUsage { } #[derive(Debug, Serialize, Deserialize)] -#[serde(untagged)] +#[serde(rename_all = "lowercase")] pub enum ToolChoice { Auto, Required, None, + #[serde(untagged)] Other(ToolDefinition), }