Harden OpenAI-compatible JSON responses and ensure json_object prompt hint#1368
Merged
nicoloboschi merged 1 commit intovectorize-io:mainfrom May 4, 2026
Conversation
Ensure json_object calls include a user-message json hint, and convert malformed success responses into clear ProviderResponseError failures instead of crashing on missing choices/content. This avoids opaque retain extraction TypeErrors and prevents deterministic provider error payloads from being retried as generic chunk failures.
liling
pushed a commit
to liling/hindsight
that referenced
this pull request
May 5, 2026
Ensure json_object calls include a user-message json hint, and convert malformed success responses into clear ProviderResponseError failures instead of crashing on missing choices/content. This avoids opaque retain extraction TypeErrors and prevents deterministic provider error payloads from being retried as generic chunk failures. Co-authored-by: Reese <reesevader@hotmail.co.uk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two OpenAI-compatible provider edge cases in structured JSON calls:
response_format={"type":"json_object"}requests include a lowercasejsonhint in a user messageProviderResponseErrors instead of crashing onresponse.choices[0]Some OpenAI-compatible gateways enforce JSON mode’s “messages must contain json” requirement against the user/input message, and may return an error payload with
choices: null. Previously this could become a genericTypeError: 'NoneType' object is not subscriptable, causing opaque retain extraction failures and wasted retries.Changes
Return valid json only.Testing
uv run pytest -q tests/test_openai_compatible_response_hardening.py