Skip to content

Sanitize null reasoning_content and add --sanitize-null-content flag for strict OpenAI-compatible endpoints - #737

Closed
philippeback wants to merge 2 commits into
cecli-dev:mainfrom
philippeback:fix/sanitize_tool_calls
Closed

philippeback wants to merge 2 commits into
cecli-dev:mainfrom
philippeback:fix/sanitize_tool_calls

Conversation

@philippeback

@philippeback philippeback commented Nov 11, 2026 •

Copy link
Copy Markdown

Summary

Some OpenAI-compatible inference servers (e.g. llama-server, Lemonade Server, vLLM, Aphrodite, LM Studio, Ollama) strictly validate message fields and fail when content or reasoning_content is null:

  • 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 whenever ModelResponse.model_dump() serialized an assistant tool-call turn that emitted no reasoning tokens, because "reasoning_content" was already present in msg with value None, bypassing "reasoning_content" not in msg checks).
  • Other strict OpenAI-compatible endpoints reject assistant tool-call messages where "content": null with HTTP 400 or 422.

This PR:

  1. Coerces null (None) reasoning_content on assistant messages to "" by default across the coder message history and request/payload pipeline so "reasoning_content": null is never sent on the wire.
  2. Adds a --sanitize-null-content CLI flag and configuration option that converts null content (and reasoning_content) values in messages to empty strings "".

Changes

  • Assistant reasoning_content Handling:
    • Updated Coder.add_assistant_reply_to_cur_messages in cecli/coders/base_coder.py to check if not msg.get("reasoning_content"): and default to self.partial_response_reasoning_content or "".
    • Updated add_reasoning_content() in cecli/helpers/requests.py and _coerce_reasoning_content() in cecli/helpers/llms/domains/chat.py to coerce "reasoning_content": None on assistant messages to "".
  • CLI & Configuration: Added --sanitize-null-content / --no-sanitize-null-content in cecli/args.py (supporting CLI, config file, and env var CECLI_SANITIZE_NULL_CONTENT), wired through main.py and ModelSettings.
  • LLM Runtime Knob & Interceptor: Added SANITIZE_NULL_CONTENT and set_sanitize_null_content() in cecli/helpers/llms/runtime.py and an async _strip_null_content_hook in make_client() for /chat/completions requests (sanitizing both content and reasoning_content).
  • Domain Payload Adapter & Request Pipeline: Added _sanitize_null_content() in cecli/helpers/llms/domains/chat.py and sanitize_null_content() in cecli/helpers/requests.py.
  • Tests: Added TestSanitizeNullContent in tests/test_requests.py covering content and reasoning_content sanitization, default chat_payload coercion of reasoning_content: None, parser gating, and the httpx request hook.

@philippeback

Copy link
Copy Markdown
Author

Plot deepened as we have 500 server errors...
the exact culprit: llama-server (behind Lemonade) actually tolerates "content": null on tool-call turns, but throws 500 Failed to parse messages: [json.exception.type_error.302]
type must be string, but is null when an assistant message carries "reasoning_content": null.

@philippeback philippeback changed the title Add --sanitize-null-content flag to sanitize null message content for strict OpenAI-compatible endpoints Sanitize null reasoning_content and add --sanitize-null-content flag for strict OpenAI-compatible endpoints Nov 11, 2026
@dwash96

dwash96 commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

I actually already added:
da98439

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants