Skip to content

Commit e7e26cd

Browse files
committed
fix: warn on unsupported request parameters instead of rejecting
Change validate_no_unsupported_fields to log a warning instead of returning an error when unknown fields are present. This improves compatibility with clients that send extra parameters like add_special_tokens, prompt_cache_key, request_id, or chat_template. https://claude.ai/code/session_01EoHsvxn4B3WMuJkwP5f6od
1 parent aaa8a56 commit e7e26cd

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

lib/llm/src/http/service/openai.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,17 +2786,9 @@ mod tests {
27862786
assert!(request.unsupported_fields.contains_key("documents"));
27872787
assert!(request.unsupported_fields.contains_key("chat_template"));
27882788

2789+
// Unsupported fields should now produce a warning but not an error
27892790
let result = validate_chat_completion_fields_generic(&request);
2790-
assert!(result.is_err());
2791-
if let Err(error_response) = result {
2792-
assert_eq!(error_response.0, StatusCode::BAD_REQUEST);
2793-
let msg = &error_response.1.message;
2794-
assert!(msg.contains("Unsupported parameter"));
2795-
// Verify all fields appear in the error message
2796-
assert!(msg.contains("add_special_tokens"));
2797-
assert!(msg.contains("documents"));
2798-
assert!(msg.contains("chat_template"));
2799-
}
2791+
assert!(result.is_ok());
28002792
}
28012793

28022794
#[test]
@@ -2819,16 +2811,9 @@ mod tests {
28192811
);
28202812
assert!(request.unsupported_fields.contains_key("response_format"));
28212813

2814+
// Unsupported fields should now produce a warning but not an error
28222815
let result = validate_completion_fields_generic(&request);
2823-
assert!(result.is_err());
2824-
if let Err(error_response) = result {
2825-
assert_eq!(error_response.0, StatusCode::BAD_REQUEST);
2826-
let msg = &error_response.1.message;
2827-
assert!(msg.contains("Unsupported parameter"));
2828-
// Verify both fields appear in error message
2829-
assert!(msg.contains("add_special_tokens"));
2830-
assert!(msg.contains("response_format"));
2831-
}
2816+
assert!(result.is_ok());
28322817
}
28332818

28342819
#[tokio::test]

lib/llm/src/protocols/openai/chat_completions.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,4 +426,29 @@ mod tests {
426426
assert_eq!(output_options.skip_special_tokens, Some(skip_value));
427427
}
428428
}
429+
430+
#[test]
431+
fn test_unsupported_fields_warn_not_error() {
432+
use crate::engines::ValidateRequest;
433+
434+
let json_str = json!({
435+
"model": "test-model",
436+
"messages": [{"role": "user", "content": "Hello"}],
437+
"add_special_tokens": true,
438+
"prompt_cache_key": "key123",
439+
"request_id": "req-456",
440+
"chat_template": "custom"
441+
});
442+
let request: NvCreateChatCompletionRequest =
443+
serde_json::from_value(json_str).expect("Failed to deserialize request");
444+
445+
// These fields should be captured as unsupported
446+
assert!(request.unsupported_fields.contains_key("add_special_tokens"));
447+
assert!(request.unsupported_fields.contains_key("prompt_cache_key"));
448+
assert!(request.unsupported_fields.contains_key("request_id"));
449+
assert!(request.unsupported_fields.contains_key("chat_template"));
450+
451+
// Validation should succeed (warn, not error)
452+
assert!(ValidateRequest::validate(&request).is_ok());
453+
}
429454
}

lib/llm/src/protocols/openai/validate.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ pub const MAX_REPETITION_PENALTY: f32 = 2.0;
9797
// Shared Fields
9898
//
9999

100-
/// Validates that no unsupported fields are present in the request
100+
/// Validates unsupported fields in the request.
101+
/// Instead of rejecting requests with unsupported fields, this now logs a warning
102+
/// and allows the request to proceed. This improves compatibility with clients
103+
/// that send extra parameters (e.g. add_special_tokens, prompt_cache_key,
104+
/// request_id, chat_template).
101105
pub fn validate_no_unsupported_fields(
102106
unsupported_fields: &std::collections::HashMap<String, serde_json::Value>,
103107
) -> Result<(), anyhow::Error> {
@@ -106,7 +110,7 @@ pub fn validate_no_unsupported_fields(
106110
.keys()
107111
.map(|s| format!("`{}`", s))
108112
.collect();
109-
anyhow::bail!("Unsupported parameter(s): {}", fields.join(", "));
113+
tracing::warn!("Ignoring unsupported parameter(s): {}", fields.join(", "));
110114
}
111115
Ok(())
112116
}

0 commit comments

Comments
 (0)