Repository navigation
fix(validation): reject a schema file that is valid JSON but not a schema - #542
Merged
jbonofre merged 1 commit intoOct 9, 2026
Merged
Conversation
…hema --schema pointing at a JSON file whose top-level value is neither an object nor a boolean got past json.loads and then raised AttributeError from inside referencing -- "'list' object has no attribute 'get'" -- a traceback naming neither the schema nor the file it came from. main() now checks the parsed schema against the Draft 2020-12 metaschema and reports the first problem with the path to it, in the same form as a model diagnostic. That also covers an object whose keywords have the wrong shape: a string "required" used to make the validator demand one property per character, reporting four missing-property errors against the model for a mistake in the schema. true and false stay valid schemas and behave as before.
There was a problem hiding this comment.
🟢 Approval recommended
The implementation correctly addresses the failure modes and provides focused regression coverage.
0 open findings
What changed in this PR
Adds early JSON Schema validation so malformed schemas produce actionable CLI errors instead of tracebacks or misleading model diagnostics.
Changes:
- Validates schemas against the Draft 2020-12 metaschema.
- Reports invalid schema locations and preserves boolean-schema support.
- Adds integration coverage for invalid roots, malformed keywords, and boolean schemas.
| File | Description |
|---|---|
validation/validate.py |
Adds schema validation and clear error reporting. |
validation/test_validate.py |
Tests invalid and boolean schema behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
jbonofre
self-requested a review
October 9, 2026 03:33
Merged
5 tasks done
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
Follow up from: #534 (review)
--schemapointing at a file whose top-level JSON value is neither an object nor a boolean gets pastjson.loadsand then raises from insidereferencing, naming neither the schema nor the file it came from.Currently, with
--schemaat a file holding[]:File ".../referencing/jsonschema.py", line 50, in _dollar_id
return contents.get("$id")
AttributeError: 'list' object has no attribute 'get'
main()now checks the parsed schema against the Draft 2020-12 metaschema and reportsthe problem with the path to it, in the same
" -> "formvalidate_schemaalreadyuses for model diagnostics:
Two notes on scope:
check_schemaalso catches a schema that is an object but whose keywords aremalformed. That is the same single call, and the extra case is a real misreport: on
main,{"required": "name"}iterates the string and demands four properties'n','a','m','e'of the model, blaming the model for a mistake in theschema. A bare
isinstance(schema, (dict, bool))check would address only theliteral traceback and leave that in place.
trueandfalseare legal JSON Schemas and keep working —trueacceptseverything,
falsefails through the normal[Schema]path. A test pins both, sothe check is not narrowed into rejecting non-objects.
Related Issues
Checklist
Specification
core-spec/and follow the existing structureOntology
ontology/are consistent with spec changesConverters
converters/is updated to reflect spec or ontology changes.github/labeler.ymlis updated with the new pathValidation
validation/are updated if the spec changedDocumentation
docs/is updated to reflect any user-facing changesCONTRIBUTING.mdis updated if the contribution process changedExamples
examples/are added or updated for any new spec constructs or converter supportTests
pytest/ CI green)Compliance
NOTICEand/orLICENSEhave been updated per ASF policy