openai-go icon indicating copy to clipboard operation
openai-go copied to clipboard

Invalid JSON returned by Structured Outputs response with error == nil

Open jonny-d opened this issue 6 months ago • 1 comments

I am getting invalid JSON strings return using Structured Outputs. Unfortunately I cannot share the example because it contains private information. The code I am using is based on the Structured Outputs example in this repo.

The line below returns a nil error

chat, err := client.Chat.Completions.New(...)

Then when I try to unmarshal the data I get an “Unexpected end of JSON input” error from the line below

err = json.Unmarshal([]byte(chat.Choices[0].Message.Content), &...)

Inspecting the string chat.Choices[0].Message.Content I can see that it cuts off in the middle of generating a string value, before a closing brace.

jonny-d avatar Jun 09 '25 20:06 jonny-d

Upon further inspection it look like the issue is that my response exceeds the output token limit of 16,384.

Though I think this should be indicated by the error from client.Chat.Completions.New(...)

jonny-d avatar Jun 09 '25 20:06 jonny-d