fix: use json.RawMessage for Instructions field in OpenAIResponsesResponse#4260
Conversation
…ponse The Instructions field in OpenAIResponsesResponse was defined as string, but upstream providers may return null or non-string JSON values for this field. This causes json.Unmarshal to fail, resulting in HTTP 500 on /v1/responses endpoint. Other fields in the same struct (Status, ToolChoice, Truncation, etc.) already use json.RawMessage. The request-side DTO (openai_request.go) also defines Instructions as json.RawMessage. This fix aligns the response-side with both patterns. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
When proxying
/v1/responsesrequests to upstream providers, both non-streaming and streaming calls return HTTP 500 if the upstream response contains"instructions": null(or any non-string value).This happens because
OpenAIResponsesResponse.Instructionsis defined asstring, but the OpenAI Responses API spec allows this field to benull, a string, or potentially other JSON types. Go'sjson.Unmarshalfails when trying to decodenullinto astringfield, causing the entire response deserialization to fail.Root Cause
In
dto/openai_response.go, theOpenAIResponsesResponsestruct defines:Other fields in the same struct (
Status,ToolChoice,Truncation,PreviousResponseID,User,Metadata) already usejson.RawMessageto handle polymorphic JSON values. TheInstructionsfield was the only one left asstring.Notably, the request-side struct in
dto/openai_request.go(line 828) already definesInstructionsasjson.RawMessage— this fix makes the response-side consistent with the request-side.Fix
Change
Instructionsfromstringtojson.RawMessageinOpenAIResponsesResponse, matching the pattern used by all other polymorphic fields in the same struct.Impact
"instructions": nullSummary by CodeRabbit