Skip to content

fix: use json.RawMessage for Instructions field in OpenAIResponsesResponse#4260

Merged
Calcium-Ion merged 1 commit intoQuantumNous:mainfrom
linbin524:fix/responses-instructions-type
Apr 15, 2026
Merged

fix: use json.RawMessage for Instructions field in OpenAIResponsesResponse#4260
Calcium-Ion merged 1 commit intoQuantumNous:mainfrom
linbin524:fix/responses-instructions-type

Conversation

@linbin524
Copy link
Copy Markdown
Contributor

@linbin524 linbin524 commented Apr 15, 2026

Problem

When proxying /v1/responses requests 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.Instructions is defined as string, but the OpenAI Responses API spec allows this field to be null, a string, or potentially other JSON types. Go's json.Unmarshal fails when trying to decode null into a string field, causing the entire response deserialization to fail.

Root Cause

In dto/openai_response.go, the OpenAIResponsesResponse struct defines:

Instructions       string             `json:"instructions"`

Other fields in the same struct (Status, ToolChoice, Truncation, PreviousResponseID, User, Metadata) already use json.RawMessage to handle polymorphic JSON values. The Instructions field was the only one left as string.

Notably, the request-side struct in dto/openai_request.go (line 828) already defines Instructions as json.RawMessage — this fix makes the response-side consistent with the request-side.

Fix

Change Instructions from string to json.RawMessage in OpenAIResponsesResponse, matching the pattern used by all other polymorphic fields in the same struct.

Impact

  • One-line change, no behavioral difference for valid string values
  • Fixes 500 errors when upstream returns "instructions": null
  • Aligns response DTO with request DTO

Summary by CodeRabbit

  • No user-facing changes
    • Internal technical adjustment to data handling.

…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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6907087d-9b46-4c82-ae06-7c3fc555f34b

📥 Commits

Reviewing files that changed from the base of the PR and between 8c8661d and 4184059.

📒 Files selected for processing (1)
  • dto/openai_response.go

Walkthrough

The Instructions field in the OpenAIResponsesResponse struct is changed from a string type to json.RawMessage type, altering how the field is decoded from JSON and represented in memory while maintaining the same struct tag.

Changes

Cohort / File(s) Summary
Type Change
dto/openai_response.go
OpenAIResponsesResponse.Instructions field type changed from string to json.RawMessage to preserve raw JSON representation during decoding.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A string once held instructions tight,
Now raw JSON keeps formats right!
No parsing delays, just JSON pure—
The rabbit approves, that's for sure! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: converting the Instructions field from string to json.RawMessage in OpenAIResponsesResponse.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Calcium-Ion Calcium-Ion merged commit ee7cedd into QuantumNous:main Apr 15, 2026
2 checks passed
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