Skip to content

Go SDK panic: index out of range in ChatCompletion handler #1958

@YueSun233133

Description

@YueSun233133
  • This is actually a bug report in Go SDK.

What Model are you using?

  • gpt-4.1-nano-2025-04-14

Describe the bug
pkg/instructor/providers/openai/chat.go line 157 throws a panic

runtime panic: runtime error: index out of range [0] with length 0

To Reproduce
Just normal call, this issue happens from time to time, not able to reproduce manually, it looks like none was return by llm engine

messages := []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: systemPrompt,
},
}
if userPrompt != "" {
messages = append(messages, openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleUser,
Content: userPrompt,
})
}
resp, err = client.CreateChatCompletion(
ctx,
openai.ChatCompletionRequest{
Model: model,
Messages: messages,
},
&out,
)

Expected behavior
Panic should be handled gracefully

Screenshots

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions