From e43d8ea8b057ae318fde5002714b2bc353dda953 Mon Sep 17 00:00:00 2001 From: Hiroshi Morishige Date: Sat, 15 Aug 2026 18:31:17 +0900 Subject: [PATCH] fix: preserve JSON object key order in proxied payloads serde_json's default Map is BTreeMap-backed, so every JSON object that passes through the router is re-serialized with alphabetized keys. Object key order is semantic for response_format.json_schema: order-enforcing structured-output backends (vLLM/xgrammar) use the properties declaration order as the generation order, so reordering silently changes what downstream models are forced to generate. Enable serde_json's preserve_order feature so payloads are forwarded with keys in the order the client sent them. Array order was already preserved. Signed-off-by: Hiroshi Morishige --- Cargo.lock | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3d0ea85f6..2e7c27eed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2122,6 +2122,7 @@ version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ + "indexmap", "itoa", "memchr", "serde", diff --git a/Cargo.toml b/Cargo.toml index 07d133bb3..a0a57d964 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ parking_lot = "0.12" rand = "0.10" reqwest = { version = "0.13.4", default-features = false, features = ["json", "rustls", "stream"] } serde = { version = "1", features = ["derive"] } -serde_json = "1" +serde_json = { version = "1", features = ["preserve_order"] } switchyard-libsy = { path = "crates/libsy", version = "0.2.0" } switchyard-llm-client = { path = "crates/libsy-llm-client", version = "0.2.0" } switchyard-protocol = { path = "crates/protocol", version = "0.2.0" }