fix: use strict=False in json.loads for structured output parsing#152
Merged
Conversation
LLM-generated structured output (e.g. thinking fields) can contain literal control characters like \n. After the first JSON decode from the HTTP response, these become raw control characters in Python strings. The second json.loads() in parse_output() then rejects them under default strict=True mode. Fix by passing strict=False to json.loads in all 8 provider parse_output methods.
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
json.loadsstrict mode crashing structured output parsing across all providers\n) causesInvalid control charactererrors on the second JSON decode inparse_output()json.loads(content)→json.loads(content, strict=False)in all 8 providerparse_outputmethodsFiles changed
providers/anthropic/messages/parameters.pyproviders/cohere/chat/parameters.pyproviders/deepseek/chat/parameters.pyproviders/google/generate_content/parameters.pyproviders/google/interactions/parameters.pyproviders/groq/chat/parameters.pyproviders/mistral/chat/parameters.pyproviders/moonshot/chat/parameters.pyWhy not centralized
_transform_outputinclient.pyis a generic mapper dispatcher — adding JSON-specific pre-processing there would couple the dispatcher to one mapper's implementation detail. The fix belongs wherejson.loadsis called.Test plan