[PR #15424] [MERGED] fix: improve error message for unknown input item type in responses API #61849

Closed
opened 2026-04-29 16:51:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15424
Author: @sjhddh
Created: 4/8/2026
Status: Merged
Merged: 4/9/2026
Merged by: @drifkin

Base: mainHead: fix/responses-input-item-error


📝 Commits (1)

  • 6be6708 fix: improve error message for unknown input item type in responses API

📊 Changes

2 files changed (+27 additions, -1 deletions)

View changed files

📝 openai/responses.go (+4 -1)
📝 openai/responses_test.go (+23 -0)

📄 Description

Bug

unmarshalResponsesInputItem had two problems in its default error branch:

Wrong variable: The error used typeField.Type instead of itemType. These differ when the shorthand role-based format (e.g. {"role": "user", "content": "..."}) is used — in that case itemType is promoted to "message" while typeField.Type remains "". So if an unhandled type value somehow passed through, the error could show a stale/wrong string.

Unhelpful message on empty type: When both type and role are absent, itemType stays "". The old %s format produced:

unknown input item type: 

That trailing space with nothing after it gives no useful signal.

Fix

default:
    if itemType == "" {
        return nil, fmt.Errorf("input item missing required 'type' field")
    }
    return nil, fmt.Errorf("unknown input item type: %q", itemType)
  • Uses itemType (the resolved value after shorthand promotion) instead of typeField.Type
  • Uses %q so the unknown value is always quoted and visible
  • Special-cases the empty string with a descriptive message

Tests

Added two test cases to TestUnmarshalResponsesInputItem:

  • missing type field{"content": "hello"} (no type key at all)
  • empty type field{"type": ""} (explicit empty string)

Both verify the error message is "input item missing required 'type' field".

Also tightened the existing unknown item type test to assert the exact quoted error string.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/15424 **Author:** [@sjhddh](https://github.com/sjhddh) **Created:** 4/8/2026 **Status:** ✅ Merged **Merged:** 4/9/2026 **Merged by:** [@drifkin](https://github.com/drifkin) **Base:** `main` ← **Head:** `fix/responses-input-item-error` --- ### 📝 Commits (1) - [`6be6708`](https://github.com/ollama/ollama/commit/6be6708fa18801d96a08557808bf287933f8683a) fix: improve error message for unknown input item type in responses API ### 📊 Changes **2 files changed** (+27 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `openai/responses.go` (+4 -1) 📝 `openai/responses_test.go` (+23 -0) </details> ### 📄 Description ## Bug `unmarshalResponsesInputItem` had two problems in its `default` error branch: **Wrong variable**: The error used `typeField.Type` instead of `itemType`. These differ when the shorthand role-based format (e.g. `{"role": "user", "content": "..."}`) is used — in that case `itemType` is promoted to `"message"` while `typeField.Type` remains `""`. So if an unhandled type value somehow passed through, the error could show a stale/wrong string. **Unhelpful message on empty type**: When both `type` and `role` are absent, `itemType` stays `""`. The old `%s` format produced: ``` unknown input item type: ``` That trailing space with nothing after it gives no useful signal. ## Fix ```go default: if itemType == "" { return nil, fmt.Errorf("input item missing required 'type' field") } return nil, fmt.Errorf("unknown input item type: %q", itemType) ``` - Uses `itemType` (the resolved value after shorthand promotion) instead of `typeField.Type` - Uses `%q` so the unknown value is always quoted and visible - Special-cases the empty string with a descriptive message ## Tests Added two test cases to `TestUnmarshalResponsesInputItem`: - `missing type field` — `{"content": "hello"}` (no type key at all) - `empty type field` — `{"type": ""}` (explicit empty string) Both verify the error message is `"input item missing required 'type' field"`. Also tightened the existing `unknown item type` test to assert the exact quoted error string. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-29 16:51:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#61849