Skip to content

fix(server): tolerate missing/null content in chat messages - #91

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-89-tool-calls-optional-content
May 26, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-89-tool-calls-optional-content

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Multi-turn tool-calling against mlxcel's /v1/chat/completions failed at the second round: OpenAI-compatible clients omit content (or send content: null) on assistant messages that carry tool_calls, but Message.content was a required, non-nullable field, so axum's Json extractor rejected the follow-up request with HTTP 422 (missing field 'content') before the handler ran. llama-server tolerates this, so the incompatibility was mlxcel-specific and broke agentic tool loops at the first tool round.

Fix

  • MessageContent now implements Default → empty text.
  • Message.content uses #[serde(default, deserialize_with = "deserialize_message_content")]: a missing key falls back to the default; an explicit null is mapped to empty content by the custom deserializer; normal string / multimodal content is unaffected.
  • The field stays typed as MessageContent (not Option<…>), so every existing consumer (content.text()) and constructor is untouched.
  • build_raw_json_messages keeps emitting a "content" key — empty string when absent — so Jinja chat templates that reference message.content keep rendering (issue follow-up chore: complete OSS release rollout #1).

Tests

  • request.rs: type-level unit tests — Default is empty text, deserialize with missing field, explicit null, plain string, and multimodal array.
  • chat_request_tests.rs: the issue's exact 3-message reproduction deserializes, and build_raw_json_messages emits "content": "" for a tool_calls message that omitted content.

Verified with cargo fmt --check, cargo clippy --all-targets --features metal,accelerate -- -D warnings, and the targeted test run (9/9 pass).

Fixes #89

OpenAI-compatible clients omit `content` (or send `content: null`) on assistant messages that carry `tool_calls`. Because `Message.content` was a required, non-nullable field, axum's `Json` extractor rejected the follow-up request of any multi-turn tool-calling loop with HTTP 422 (`missing field 'content'`) before the handler ran, breaking agentic tool use. llama-server tolerates this, so the incompatibility was mlxcel-specific.

`MessageContent` now implements `Default` (empty text) and the field uses `#[serde(default, deserialize_with = ...)]`: a missing key falls back to the default, an explicit `null` is mapped to empty content by the custom deserializer, and normal string / multimodal arrays are unaffected. Keeping the field typed as `MessageContent` (not `Option`) leaves every consumer and constructor untouched, and `build_raw_json_messages` keeps emitting a `"content"` key (empty string when absent) so Jinja chat templates that read `message.content` keep rendering.

Adds type-level unit tests (default, missing, null, string, multimodal) and request-level regression tests for the issue's exact reproduction and the empty-content rendering guarantee.
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions area:inference Generation, sampling, decoding (incl. speculative, DRY) status:done Completed labels May 26, 2026
@inureyes
inureyes merged commit e9396f6 into main May 26, 2026
3 checks passed
@inureyes
inureyes deleted the fix/issue-89-tool-calls-optional-content branch May 26, 2026 09:11
inureyes added a commit that referenced this pull request May 26, 2026
Bump version to 0.0.31. Highlights: MiniCPM-V 4.6 and RT-DETRv2 model support plus an Anthropic-style /v1/messages API endpoint (#82, #80, #74); fixes for missing or null chat-message content, Gemma 3n VLM per_layer_inputs, Qwen3.5 MTP verify attention, and batched quantized KV cache mask offsets (#91, #86, #78, #76); and a pinned 1.93.1 Rust toolchain (#87, #90).
@inureyes inureyes added this to the 0.1 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
OpenAI-compatible clients omit `content` (or send `content: null`) on assistant messages that carry `tool_calls`. Because `Message.content` was a required, non-nullable field, axum's `Json` extractor rejected the follow-up request of any multi-turn tool-calling loop with HTTP 422 (`missing field 'content'`) before the handler ran, breaking agentic tool use. llama-server tolerates this, so the incompatibility was mlxcel-specific.

`MessageContent` now implements `Default` (empty text) and the field uses `#[serde(default, deserialize_with = ...)]`: a missing key falls back to the default, an explicit `null` is mapped to empty content by the custom deserializer, and normal string / multimodal arrays are unaffected. Keeping the field typed as `MessageContent` (not `Option`) leaves every consumer and constructor untouched, and `build_raw_json_messages` keeps emitting a `"content"` key (empty string when absent) so Jinja chat templates that read `message.content` keep rendering.

Adds type-level unit tests (default, missing, null, string, multimodal) and request-level regression tests for the issue's exact reproduction and the empty-content rendering guarantee.
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
Bump version to 0.0.31. Highlights: MiniCPM-V 4.6 and RT-DETRv2 model support plus an Anthropic-style /v1/messages API endpoint (lablup#82, lablup#80, lablup#74); fixes for missing or null chat-message content, Gemma 3n VLM per_layer_inputs, Qwen3.5 MTP verify attention, and batched quantized KV cache mask offsets (lablup#91, lablup#86, lablup#78, lablup#76); and a pinned 1.93.1 Rust toolchain (lablup#87, lablup#90).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chat/completions: assistant messages with tool_calls require content → HTTP 422 breaks multi-turn tool use

1 participant