ANTHROPIC_JSON: allow control characters in JSON strings if strict=False #644
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.
Addresses #612.
These changes merge Pydantic's non-strict semantics with those of
json.loads
for ANTHROPIC_JSON mode only. In the event that the client passes in strict=False, control characters will also be allowed in JSON strings in ANTHROPIC_JSON mode.I didn't apply this to any other modes deliberately. I think Claude is uniquely bad at this right now. This might be a change you can simply revert down the line.
I'm happy to apply this other modes if you think it'd help.
Summary:
Allows control characters in JSON strings within ANTHROPIC_JSON mode when
strict
is set toFalse
, with tests validating this behavior.Key points:
parse_anthropic_json
in/instructor/function_calls.py
to allow control characters in JSON strings whenstrict=False
./tests/test_function_calls.py
to cover new functionality.Generated with ❤️ by ellipsis.dev