fix: improve error message for unknown input item type in responses API (#15424)
release / setup-environment (push) Has been cancelled
release / windows-depends (amd64, , https://sdk.lunarg.com/sdk/download/1.4.321.1/windows/vulkansdk-windows-X64-1.4.321.1.exe, windows, Vulkan, vulkan) (push) Has been cancelled
release / windows-depends (amd64, -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="-parallel-jobs=4 -Wno-ignored-attributes -Wno-deprecated-pragma" -DCMAKE_CXX_FLAGS="-parallel-jobs=4 -Wno-ignored-attributes -Wno-deprecated-pragma", https:/… (push) Has been cancelled
release / windows-depends (amd64, ["cudart" "nvcc" "cublas" "cublas_dev" "crt" "nvvm" "nvptxcompiler"], 13.0, , https://developer.download.nvidia.com/compute/cuda/13.0.0/local_installers/cuda_13.0.0_windows.exe, windows, CUDA 13) (push) Has been cancelled
release / windows-depends (amd64, ["cudart" "nvcc" "cublas" "cublas_dev" "cufft" "cufft_dev" "nvrtc" "nvrtc_dev" "crt" "nvvm" "nvptxcompiler"], 13.0, https://developer.download.nvidia.com/compute/cudnn/redist/cudnn/windows-x86_64/cudnn-windows-x86_64-9.18.1.3_cu… (push) Has been cancelled
release / windows-depends (amd64, ["cudart" "nvcc" "cublas" "cublas_dev"], 12.8, , https://developer.download.nvidia.com/compute/cuda/12.8.0/local_installers/cuda_12.8.0_571.96_windows.exe, windows, CUDA 12) (push) Has been cancelled
release / windows-depends (amd64, windows, CPU) (push) Has been cancelled
release / darwin-build (push) Has been cancelled
release / windows-build (amd64, x86_64, windows) (push) Has been cancelled
release / windows-build (arm64, aarch64, windows) (push) Has been cancelled
release / windows-app (push) Has been cancelled
release / linux-build (amd64, linux, archive) (push) Has been cancelled
release / linux-build (amd64, linux, rocm) (push) Has been cancelled
release / linux-build (arm64, linux, archive) (push) Has been cancelled
release / docker-build-push (amd64, CGO_CFLAGS CGO_CXXFLAGS GOFLAGS , linux) (push) Has been cancelled
release / docker-build-push (amd64, CGO_CFLAGS CGO_CXXFLAGS GOFLAGS FLAVOR=rocm , linux, -rocm) (push) Has been cancelled
release / docker-build-push (arm64, CGO_CFLAGS CGO_CXXFLAGS GOFLAGS , linux) (push) Has been cancelled
release / docker-merge-push () (push) Has been cancelled
release / docker-merge-push (-rocm) (push) Has been cancelled
release / release (push) Has been cancelled

The default branch in unmarshalResponsesInputItem had two issues:
- It referenced typeField.Type instead of itemType; these differ when the
  shorthand role-based format promotes an empty type to "message", meaning
  an unhandled type would show the wrong value in the error string.
- It used %s formatting, so an empty type field produced the unhelpful
  message "unknown input item type: " with no indication what was missing.

Fix by using itemType (the resolved value) with %q quoting, and add a
dedicated message when itemType is empty (both type and role absent):
"input item missing required 'type' field".

Tests added for the empty-type and missing-type cases.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
7. Sun
2026-04-09 01:41:12 +01:00
committed by GitHub
parent 673726fa0e
commit 612f0a17d3
2 changed files with 27 additions and 1 deletions
+4 -1
View File
@@ -281,7 +281,10 @@ func unmarshalResponsesInputItem(data []byte) (ResponsesInputItem, error) {
} }
return reasoning, nil return reasoning, nil
default: default:
return nil, fmt.Errorf("unknown input item type: %s", typeField.Type) if itemType == "" {
return nil, fmt.Errorf("input item missing required 'type' field")
}
return nil, fmt.Errorf("unknown input item type: %q", itemType)
} }
} }
+23
View File
@@ -253,6 +253,29 @@ func TestUnmarshalResponsesInputItem(t *testing.T) {
if err == nil { if err == nil {
t.Error("expected error, got nil") t.Error("expected error, got nil")
} }
if err != nil && err.Error() != `unknown input item type: "unknown_type"` {
t.Errorf("unexpected error message: %v", err)
}
})
t.Run("missing type field", func(t *testing.T) {
_, err := unmarshalResponsesInputItem([]byte(`{"content": "hello"}`))
if err == nil {
t.Error("expected error for missing type, got nil")
}
if err != nil && err.Error() != "input item missing required 'type' field" {
t.Errorf("unexpected error message: %v", err)
}
})
t.Run("empty type field", func(t *testing.T) {
_, err := unmarshalResponsesInputItem([]byte(`{"type": ""}`))
if err == nil {
t.Error("expected error for empty type, got nil")
}
if err != nil && err.Error() != "input item missing required 'type' field" {
t.Errorf("unexpected error message: %v", err)
}
}) })
} }