Repository navigation
Conversation
Reviewer's GuideImplementationDocument the actual
TestsCover JSON-only mode, invalid JSON rejection, and unchanged default schema validation.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoHonor Schema guard json_mode when validating JSON output
AI Description
Merge Risk
|
Code Review by Qodo
1. Schema checks are silently skipped when json_mode is set
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="sdk/python/src/openlit/guard/schema.py" line_range="109-110" />
<code_context>
explanation=f"Output is not valid JSON: {exc}",
)
+ if self._json_mode:
+ return GuardResult(guard_name=self.name)
+
if self._schema:
</code_context>
<issue_to_address>
**String false bypasses schema checks**
When `json_mode` comes from an unparsed configuration value such as the environment string `"false"`, `self._json_mode` is truthy for the string `"false"`, so `evaluate()` returns ALLOW without checking the schema and accepts schema-mismatched output.
Validate that `json_mode` is a boolean at construction, or explicitly parse supported string values before storing it.
</issue_to_address>
### Comment 2
<location path="sdk/python/src/openlit/guard/schema.py" line_range="109-110" />
<code_context>
explanation=f"Output is not valid JSON: {exc}",
)
+ if self._json_mode:
+ return GuardResult(guard_name=self.name)
+
if self._schema:
</code_context>
<issue_to_address>
**Invalid JSON passes the guard**
When JSON-only mode receives `NaN`, `Infinity`, or `-Infinity`, `json.loads` accepts these non-standard constants, so `evaluate()` reaches the JSON-mode ALLOW return and callers see invalid JSON pass the guard.
Reject non-standard constants during JSON parsing before returning ALLOW.
</issue_to_address>
### Comment 3
<location path="sdk/python/src/openlit/guard/schema.py" line_range="109" />
<code_context>
explanation=f"Output is not valid JSON: {exc}",
)
+ if self._json_mode:
+ return GuardResult(guard_name=self.name)
+
</code_context>
<issue_to_address>
**Valid JSON is denied on schema mismatch**
When a TypeScript caller enables `jsonMode` and supplies parseable JSON that does not match the schema, typeScript `Schema.evaluate()` still validates `_schema` instead of returning ALLOW after parsing, so callers see a schema-mismatch denial.
Make TypeScript `Schema.evaluate()` return ALLOW after successful parsing when `jsonMode` is enabled, before validating the schema.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: sdk/python/src/openlit/guard/schema.py:110, sdk/python/src/openlit/guard/schema.py:110, sdk/python/src/openlit/guard/schema.py:109
| if self._json_mode: | ||
| return GuardResult(guard_name=self.name) |
There was a problem hiding this comment.
🟡 Medium · String false bypasses schema checks
When json_mode comes from an unparsed configuration value such as the environment string "false", self._json_mode is truthy for the string "false", so evaluate() returns ALLOW without checking the schema and accepts schema-mismatched output.
Validate that json_mode is a boolean at construction, or explicitly parse supported string values before storing it.
Prompt for AI agents
In `sdk/python/src/openlit/guard/schema.py` at lines 109-110:
**String false bypasses schema checks**
When `json_mode` comes from an unparsed configuration value such as the environment string `"false"`, `self._json_mode` is truthy for the string `"false"`, so `evaluate()` returns ALLOW without checking the schema and accepts schema-mismatched output.
Validate that `json_mode` is a boolean at construction, or explicitly parse supported string values before storing it.| if self._json_mode: | ||
| return GuardResult(guard_name=self.name) |
There was a problem hiding this comment.
🟡 Medium · Invalid JSON passes the guard
When JSON-only mode receives NaN, Infinity, or -Infinity, json.loads accepts these non-standard constants, so evaluate() reaches the JSON-mode ALLOW return and callers see invalid JSON pass the guard.
Reject non-standard constants during JSON parsing before returning ALLOW.
Prompt for AI agents
In `sdk/python/src/openlit/guard/schema.py` at lines 109-110:
**Invalid JSON passes the guard**
When JSON-only mode receives `NaN`, `Infinity`, or `-Infinity`, `json.loads` accepts these non-standard constants, so `evaluate()` reaches the JSON-mode ALLOW return and callers see invalid JSON pass the guard.
Reject non-standard constants during JSON parsing before returning ALLOW.103a705 to
5cb16aa
Compare
Issue number: #1999
Change description:
The
Schemaguard docstring documentedjson : boolbut the actual parameter wasjson_mode, stored and never read:evaluate()always applied schema validation, and the documented keyword raisedTypeError. The docstring now matches the parameter, andjson_mode=Truereturns a clean ALLOW after successful JSON parsing (invalid JSON is still rejected). Default behavior is unchanged.Checklist
Base fails the new ALLOW case; with the fix
test_guard_schema.pyis 14 passed and the full guard suite is 81 passed. Ruff findings are pre-existing on base. Provider live tests were not run (no credentials); this is an offline guard-unit fix.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.
Summary by Sourcery
Fix Schema guard JSON-only mode so it validates parseability without enforcing a schema.
Bug Fixes:
json_mode=Truein the Schema guard by allowing valid JSON without applying schema validation, while continuing to reject invalid JSON and preserving default schema validation behavior.Enhancements:
json_modeparameter.Tests: