fix: handle OpenClaw message format to resolve 422 validation errors#41
Draft
bhargav18 wants to merge 1 commit intoRichardAtCT:mainfrom
Draft
fix: handle OpenClaw message format to resolve 422 validation errors#41bhargav18 wants to merge 1 commit intoRichardAtCT:mainfrom
bhargav18 wants to merge 1 commit intoRichardAtCT:mainfrom
Conversation
OpenClaw sends message formats that don't match the strict OpenAI spec the wrapper previously enforced, causing 422 Unprocessable Content errors. - Accept role 'tool' in Message (tool call result messages) - Allow null/None content (assistant messages mid-tool-call) - Loosen ContentPart to accept any content block type beyond just 'text' - Extract text from tool_result content blocks during normalization - Add extra='ignore' to drop unknown fields (e.g. store, service_tier) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
OpenClaw sends message formats that go beyond the strict OpenAI Chat Completions spec the wrapper previously enforced, resulting in
422 Unprocessable Contenterrors. This PR makes theMessageandContentPartmodels tolerant of those formats while preserving existing behaviour for standard OpenAI clients.Root cause
OpenClaw (and other agentic clients) send:
role: "tool"— tool call result messages returned to the modelcontent: null— assistant messages that made a tool call and have no text content yettool_use,tool_result,image)storeorservice_tierfrom the OpenAI Responses APIChanges
src/models.pyMessage.roleLiteral["system", "user", "assistant"]Literal["system", "user", "assistant", "tool"]Message.contentUnion[str, List[ContentPart]]Optional[Union[str, List[Any]]]ContentPart.typeLiteral["text"]strContentPart.textstr(required)Optional[str]extra="ignore")normalize_contentnow handlesNonecontent (returns"") and extracts text fromtool_resultcontent blocksmodel_config = {"extra": "ignore"}added to bothContentPartandMessageTest plan
poetry run python tests/test_endpoints.py→ 4/4 passedpoetry run python tests/test_basic.py→ 4/4 passed🤖 Generated with Claude Code