Skip to content

fix(llm): OpenAI API 400 Bad Request on skill documentation#1955

Merged
bug-ops merged 3 commits intomainfrom
fix-1952-openai
Mar 17, 2026
Merged

fix(llm): OpenAI API 400 Bad Request on skill documentation#1955
bug-ops merged 3 commits intomainfrom
fix-1952-openai

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 17, 2026

Summary

Fixes HTTP 400 Bad Request from OpenAI API when querying skills documentation. Root cause: StructuredApiMessage.content serializes empty string "" alongside tool_calls, but OpenAI requires null/absent for this combination.

Changes

  • StructuredApiMessage.content: StringOption<String> with #[serde(skip_serializing_if = "Option::is_none")]
  • convert_messages_structured: emit None when assistant text is empty
  • Tool arguments fallback: unwrap_or_default()unwrap_or_else(|_| "{}".to_owned())
  • Added regression test: convert_messages_structured_assistant_tool_only_content_is_none

Testing

  • All 6128 tests pass
  • Regression test confirms fix (content is None, not "")
  • Code review approved (9/10)
  • LLM serialization gate: pending live OpenAI session test with tool use to confirm no 400 errors

Related

Closes #1952

bug-ops added 2 commits March 17, 2026 23:51
OpenAI API rejects assistant messages with tool_calls when content is ""
(empty string). Changed StructuredApiMessage.content from String to
Option<String> with skip_serializing_if, so tool-only assistant messages
emit content: null (or omit the field), matching the API requirement.

Also changed arguments fallback from unwrap_or_default() ("") to
unwrap_or_else(|_| "{}") so a serialization failure never produces an
invalid empty string.

Closes #1952
@github-actions github-actions bot added bug Something isn't working documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes size/M Medium PR (51-200 lines) and removed bug Something isn't working labels Mar 17, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 17, 2026 23:03
@github-actions github-actions bot added the bug Something isn't working label Mar 17, 2026
@bug-ops bug-ops merged commit 921a728 into main Mar 17, 2026
20 checks passed
@bug-ops bug-ops deleted the fix-1952-openai branch March 17, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(llm): OpenAI API 400 Bad Request on skill documentation

1 participant