Skip to content

Return error when structured output is truncated due to max_tokens #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Param0rph
Copy link

Summary

This PR improves error handling in ResponseService.New(...) by checking the IncompleteDetails.Reason field. When the reason is "max_tokens", it now returns an explicit error.

This helps users detect truncated structured output responses before attempting to parse invalid or incomplete JSON manually.

Changes

  • Added check for IncompleteDetails.Reason == "max_tokens"
  • Return error with clear message when output is truncated
  • Added integration test in responses_test.go using low MaxOutputTokens

Why

Previously, truncated responses would silently cause downstream json.Unmarshal errors. This change provides a more informative failure path.

Related

Resolves internal issue: unexpected JSON parse failures caused by token limits.

@Param0rph Param0rph requested a review from a team as a code owner June 23, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant