Repository navigation
Description
Summary
Message.content is a required field during request deserialization. However, OpenAI-compatible clients omit (or send null for) content on assistant messages that carry tool_calls. As a result, the Json<ChatCompletionRequest> extractor rejects the follow-up request of a multi-turn tool-calling conversation with HTTP 422 (Failed to deserialize the JSON body into the target type: messages[N]: missing field 'content') before the handler runs. This breaks any tool-calling loop at the second round.
Impact
- First request (
system+user+tools) succeeds; the model returns atool_callsresponse. - The client appends the assistant
tool_callsmessage plus atoolresult message, then sends the follow-up request. - That follow-up is rejected with 422 because the assistant message has no
contentkey. - Net effect: multi-turn / agentic tool use against mlxcel never completes even a single tool round.
Observed downstream in Backend.AI GO's scheduler and agent tool loops (a Gemma MLX model with tools enabled, served with --jinja). llama-server tolerates the missing content field, so the incompatibility is mlxcel-specific.
Root cause
src/server/types/request.rs (confirmed in v0.0.30; Message struct at ~L274, content at ~L276):
pub struct Message {
pub role: Role,
pub content: MessageContent, // ← required: not Option, no #[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_call_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_calls: Option<Vec<ToolCallInMessage>>,
}MessageContent is an untagged enum (Text(String) | Parts(Vec<ContentPart>)), so a missing key — and also an explicit null — fails to deserialize. axum's Json extractor maps the serde error to HTTP 422.
Reproduction
Against a running mlxcel-server socket (Gemma MLX model, --jinja):
A) assistant tool_calls message WITHOUT content (OpenAI-style) → 422
curl --unix-socket "$SOCK" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
http://localhost/v1/chat/completions -d '{
"model":"...","max_tokens":16,"stream":false,
"messages":[
{"role":"user","content":"hi"},
{"role":"assistant","tool_calls":[{"id":"call_1","type":"function","function":{"name":"get_system_info","arguments":"{}"}}]},
{"role":"tool","tool_call_id":"call_1","content":"mem: 12GB free"}
]}'Result:
Failed to deserialize the JSON body into the target type: messages[1]: missing field `content`
HTTP 422
B) same request WITH content: "" on the assistant message → 200 OK
Adding "content":"" to the assistant tool_calls message makes the request deserialize and the completion succeed normally.
Expected behavior
Per the OpenAI Chat Completions spec, content is optional/nullable for assistant messages that contain tool_calls (the tool calls are the payload; content may be null or absent). The server should accept a missing or null content and treat it as empty.
Suggested fix
Make content optional with a default in Message, e.g.:
#[serde(default)]
pub content: MessageContent,with impl Default for MessageContent { fn default() -> Self { MessageContent::Text(String::new()) } } — or change to content: Option<MessageContent> and treat None as empty in MessageContent::text(), build_chat_messages, and build_raw_json_messages.
Two follow-ups to keep in mind:
build_raw_json_messagesshould still emit a"content"field (empty string when absent) so Jinja chat templates that referencemessage.contentkeep rendering.- Also accept an explicit JSON
null(viaOption<MessageContent>or a custom deserializer), since some clients send"content": nullrather than omitting the key.
Environment
- mlxcel v0.0.30 (same code shape confirmed in v0.0.21)
- Confirmed via live reproduction against a running mlxcel-server Unix socket.
Activity