Skip to content

Commit b6fb7db

Browse files
authored
[aisdk] Allow for empty reasoning blocks (observed behavior) (#580)
## Summary Sometimes the model does return an empty reasoning block... Let's let it through instead of failing to decode. Example: https://platform.openai.com/logs/resp_02474882b463981300691523a7eb9481938b7823951cfe62ab I'll add the raw response in a comment to this PR ## How was it tested? Ran testpilot locally. ## Community Contribution License All community contributions in this pull request are licensed to the project maintainers under the terms of the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0). By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the [Community Contribution License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license).
1 parent c5c7c5a commit b6fb7db

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

aisdk/ai/provider/openai/internal/codec/decode.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ func decodeReasoning(item responses.ResponseOutputItemUnion) (*api.ReasoningBloc
110110
}
111111

112112
reasoningItem := item.AsReasoning()
113-
if len(reasoningItem.Summary) == 0 {
114-
return nil, fmt.Errorf("reasoning item has no summary")
115-
}
116113

117114
// For now, we'll concatenate all summary texts with newlines if there are multiple
118115
// Another option would be to return a slice of ReasoningBlocks.
@@ -125,9 +122,9 @@ func decodeReasoning(item responses.ResponseOutputItemUnion) (*api.ReasoningBloc
125122
texts = append(texts, summary.Text)
126123
}
127124

128-
if len(texts) == 0 {
129-
return nil, fmt.Errorf("no valid text found in reasoning summaries")
130-
}
125+
// NOTE: we don't check that the text is non-empty because sometimes the model returns an empty
126+
// reasoning block. That behavior is technically against the API spec, but it's been observed in practice.
127+
// Consider omitting the ReasoningBlock and adding a warning instead.
131128

132129
return &api.ReasoningBlock{
133130
Text: strings.Join(texts, "\n"),

aisdk/ai/provider/openai/internal/codec/decode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ func TestDecodeReasoning(t *testing.T) {
11921192
"id": "reason_123",
11931193
"summary": []
11941194
}`,
1195-
wantErr: "reasoning item has no summary",
1195+
want: &api.ReasoningBlock{},
11961196
},
11971197
{
11981198
name: "empty text in summary",

0 commit comments

Comments
 (0)