Repository navigation
Sanitize null reasoning_content and add --sanitize-null-content flag for strict OpenAI-compatible endpoints - #737
Closed
philippeback wants to merge 2 commits into
Closed
philippeback wants to merge 2 commits into
philippeback wants to merge 2 commits into
Conversation
… strict OpenAI-compatible endpoints
Author
|
Plot deepened as we have 500 server errors... |
Collaborator
|
I actually already added: to v1.12.2 which should just fix this deeper in the llm communication chain of events and adding the reasoning_content shim if present might be the only difference here |
dwash96
added a commit
that referenced
this pull request
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some OpenAI-compatible inference servers (e.g.
llama-server, Lemonade Server, vLLM, Aphrodite, LM Studio, Ollama) strictly validate message fields and fail whencontentorreasoning_contentisnull:llama-server/ Lemonade Server throws HTTP 500 (Failed to parse messages: [json.exception.type_error.302] type must be string, but is null) when an assistant message contains"reasoning_content": null(which occurred wheneverModelResponse.model_dump()serialized an assistant tool-call turn that emitted no reasoning tokens, because"reasoning_content"was already present inmsgwith valueNone, bypassing"reasoning_content" not in msgchecks)."content": nullwith HTTP 400 or 422.This PR:
null(None)reasoning_contenton assistant messages to""by default across the coder message history and request/payload pipeline so"reasoning_content": nullis never sent on the wire.--sanitize-null-contentCLI flag and configuration option that convertsnullcontent(andreasoning_content) values in messages to empty strings"".Changes
reasoning_contentHandling:Coder.add_assistant_reply_to_cur_messagesincecli/coders/base_coder.pyto checkif not msg.get("reasoning_content"):and default toself.partial_response_reasoning_content or "".add_reasoning_content()incecli/helpers/requests.pyand_coerce_reasoning_content()incecli/helpers/llms/domains/chat.pyto coerce"reasoning_content": Noneon assistant messages to"".--sanitize-null-content/--no-sanitize-null-contentincecli/args.py(supporting CLI, config file, and env varCECLI_SANITIZE_NULL_CONTENT), wired throughmain.pyandModelSettings.SANITIZE_NULL_CONTENTandset_sanitize_null_content()incecli/helpers/llms/runtime.pyand an async_strip_null_content_hookinmake_client()for/chat/completionsrequests (sanitizing bothcontentandreasoning_content)._sanitize_null_content()incecli/helpers/llms/domains/chat.pyandsanitize_null_content()incecli/helpers/requests.py.TestSanitizeNullContentintests/test_requests.pycoveringcontentandreasoning_contentsanitization, defaultchat_payloadcoercion ofreasoning_content: None, parser gating, and the httpx request hook.