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(relay): preserve bracketed captured prose (#1253)
Alex Fournier237b918f91a5
diff --git a/crates/switchyard-nemo-relay-plugin/src/span_capture.rs b/crates/switchyard-nemo-relay-plugin/src/span_capture.rsindex 59db88c4b..f9886b005 100644--- a/crates/switchyard-nemo-relay-plugin/src/span_capture.rs+++ b/crates/switchyard-nemo-relay-plugin/src/span_capture.rs@@ -273,8 +273,12 @@ fn redact_captured_text(Some(b'{' | b'[' | b'"')){- let decoded = serde_json::from_str::<Json>(&text).ok()?;- Some(redact_captured_json(decoded, redactor, depth)?.to_string())+ match serde_json::from_str::<Json>(&text) {+ Ok(decoded) => Some(redact_captured_json(decoded, redactor, depth)?.to_string()),+ // Malformed escaped JSON may conceal a configured credential.+ Err(_) if text.contains('\\') => None,+ Err(_) => Some(redactor.text(text)),+ }} else {Some(redactor.text(text))}@@ -746,6 +750,26 @@ mod tests {assert_eq!(response_body["ordinary"], response["ordinary"]);}+ #[test]+ fn captured_payload_redaction_preserves_bracketed_prose() {+ let redactor = ProviderKeyRedactor::new(&["qa-secret".into()]);+ for text in [+ "[Current time: Thursday]",+ "{ordinary prose}",+ "\"Quoted prose",+ ] {+ let body = serde_json::json!({"content": format!("{text} Inspect qa-secret.")});+ let mut span = span_with_payloads(Payloads {+ request: Some(serde_json::json!({"body": body.to_string(), "truncated": false})),+ response: None,+ });+ span.sanitize(&redactor);+ let payload = span.payloads.request.unwrap();+ let decoded: Json = serde_json::from_str(payload["body"].as_str().unwrap()).unwrap();+ assert_eq!(decoded["content"], format!("{text} Inspect [REDACTED]."));+ }+ }+#[test]fn captured_payload_redaction_bounds_structural_and_encoded_depth() {let redactor = ProviderKeyRedactor::new(&["qa-secret".into()]);diff --git a/docs/integrations/nemo_relay.md b/docs/integrations/nemo_relay.mdindex 68be84f67..7c385607e 100644--- a/docs/integrations/nemo_relay.md+++ b/docs/integrations/nemo_relay.md@@ -413,8 +413,10 @@ Payloads can contain sensitive task data. To mask configured provider keys,the plugin decodes the captured JSON, redacts it, and serializes the copy again.JSON strings, such as classifier content and tool arguments, are decoded too.Traversal is limited to 64 levels, including JSON encoded inside strings.-Whitespace and escape spellings may change. If JSON-looking text cannot be-decoded or the depth limit is exceeded, the body is omitted (`body: null`).+Whitespace and escape spellings may change. Ordinary bracketed prose is kept+and redacted as text. If JSON-looking text cannot be decoded and contains+backslash escapes, or the depth limit is exceeded, the body is omitted+(`body: null`). An invalid outer JSON body is also omitted when keys are configured.Captured data passes through Relay's normal eventsanitizers and configured exporters. Personal data and other secrets requiresuitable sanitizers; see Relay's