Repository navigation
Conversation
Reviewer's GuideImplementationReject Python’s non-standard JSON constants during Schema parsing while preserving the existing invalid-JSON handling and documenting the behavior.
TestsCover rejection of unquoted non-JSON constants and acceptance of valid JSON values, quoted spellings, and configured warning actions.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
chrikrah
left a comment
There was a problem hiding this comment.
@WitBlue6, nothing here blocks a merge from my side. With schema.py back at 1ed8bb7 and your tests kept, 12 of the 18 fail, so they pin the change.
$ cd <ol1866 tree>/sdk/python && python -I run.py $PWD/src tests/test_guard_schema_json.py -q -p no:cacheprovider # head 0f29182, git archive export, openlit.guard.schema.__file__ printed from the tree, Python 3.12
18 passed in 0.02s
$ git show 1ed8bb7:sdk/python/src/openlit/guard/schema.py > src/openlit/guard/schema.py && python -I run.py $PWD/src tests/test_guard_schema_json.py -q -p no:cacheprovider
12 failed, 6 passed in 0.06s
$ python -I probe.py # head again, Schema(json_mode=True).evaluate(text)
'1e999' GuardAction.ALLOW
'{"score": 1e999}' GuardAction.ALLOW
json.dumps(json.loads("1e999")) -> Infinity
# not run: the full SDK suite
non-blocking: 1e999 is valid JSON but parses to inf, so a consumer that runs the output through json.dumps gets Infinity back. Rejecting it would deny RFC-valid text, which is a range policy and not the syntax fix #1865 asks for, so it belongs outside this PR. Should the guard promise finite numbers at all?
Linked issuesChecked at commit 24628dc #1865 Bug: Schema JSON guard accepts non-JSON NaN and Infinity constants · 5 of 5 met
|
Issue number: Closes #1865
Change description:
Reject unquoted
NaN,Infinity, and-Infinityin the Python SDK's Schema guard viajson.loads(parse_constant=...). Python accepts these extensions by default, so a postflight JSON guard currently allows output that a strict downstream JSON consumer rejects. The existing invalid-JSON result retains the configured deny/warn action. Quoted strings and object keys containing those spellings remain valid.Found by code inspection and reproduced offline on main at 1ed8bb7; no production-incident claim. Related #1696 addresses bool-versus-number schema type checking, not JSON parsing; this change does not modify that validation function.
Validation on Python 3.13.7:
python -m pytest tests/test_guard_schema_json.py tests/test_guard_pipeline.py tests/test_guard_integration.py -q: 49 passed.poetry check: exit 0, with existing metadata deprecation warnings.poetry build: built the wheel and source distribution.test_groq.py:21andtest_together.py:19in this installed-provider environment. No live-provider tests were run, and no live API keys or network calls were needed for the guard regressions.Checklist
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution under the terms of the project license.
AI assistance: Codex helped inspect the bug, implement the change and tests, and draft the issue and PR text. The diff and reported local results were reviewed before submission.
Summary by Sourcery
Enforce strict JSON parsing in the Python SDK Schema guard.
Bug Fixes:
Documentation:
Tests: