Repository navigation
Validate every listed excerpt and every object in a keyed mapping - #154
Conversation
…, #141) #141: a multivalued excerpt slot reached SupportingTextValidator as a list and crashed validate data with TypeError. Each listed excerpt now gets the content check and its own validation, reported at its own [i] path, against references resolved once for the field; an item that is not text is an error instead of a crash. #139: a dict in a multivalued, class-ranged slot is a keyed mapping (inlined_as_list: false), but was validated as one object, so the evidence inside was never visited and a fabricated quote passed with exit 0. Each object in it is now validated at <slot>[<key>], with the key supplied as the identifier when the object omits it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC
|
Claude finished @caufieldjh's task in 1m 18s —— View job Review of PR #154
Both fixes are well scoped. Splitting the excerpt list into 1. A single object in a multivalued slot may now pass silently (likely regression)
# Evidence has no identifier; has_evidence: {multivalued: true, inlined: true}
has_evidence:
reference: PMID:TEST001
supporting_text: totally fabricated quoteBefore this PR, this dict was checked as one Suggestion: treat the dict as a keyed mapping only when the range class has an identifier or key slot. Otherwise keep the old single-instance path. Add a regression test for this shape. 2. A
|
…alues are objects Review follow-up on #139. Every dict in a multivalued class-ranged slot was walked as a keyed mapping, so a single object written without the list had its fields read as keys and was skipped: a fabricated quote in it passed again, where it had been caught before. A dict is now a keyed mapping only if the range class has an identifier or key slot and every value is an object or null; otherwise it is validated as one object. The key also fills a key: true slot now (use_key=True), so evidence keyed by its reference is checked against that reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC
|
Points 1 and 2 are fixed in e0d5951. Both were regressions I introduced, and both are now covered by tests that failed before the fix.
Full suite: 2202 passed. Doctests, mypy and ruff are clean. Generated by Claude Code |
|
Claude finished @caufieldjh's task in 47s —— View job Re-review after
|
…jects Review follow-up on #139. Requiring every value to be an object meant one compact (scalar) entry made a whole mapping read as a single object, and the evidence objects beside it went unchecked again. A dict is now one object only if one of its keys is a slot of the class (or an alias); otherwise, for a class with an identifier or key, it is a keyed mapping and compact entries are skipped one by one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm4PkMsSN3FVpzvBdZYahC
|
Fixed in 677bf65 by switching to your key-based rule.
Full suite: 2203 passed. Doctests, mypy and ruff are clean. Generated by Claude Code |
|
Claude finished @caufieldjh's task in 46s —— View job Re-review after
|
| Shape | Result |
|---|---|
{E1: {...FABRICATED}, E2: "compact"} (the case I raised last time) |
Keyed. E1 is checked and E2 is skipped. The new test_a_compact_entry_does_not_hide_the_objects_beside_it covers this. |
| A class with no identifier, written as one object | get_identifier_slot returns None, so it's one object, as it was before this PR. |
A class with an identifier, written as one object ({id: E1, reference: …}) |
id is a slot, so it's one object. |
A class keyed with key: true on reference (keys are PMIDs) |
Keyed, and the key is filled in. |
E1: null |
Keyed. The value becomes {id: E1}. |
Since a compact entry can now reach _validate_keyed_objects, its if not isinstance(obj, dict): continue branch runs again, and the docstring is accurate again. That resolves the small point about the unreachable branch.
Smaller points (none blocking)
- A key that happens to be a slot name: an identifier spelled like a slot (for example
{reference: {...}, E2: {...}}) would make the whole mapping read as one object. That's very unlikely, and preferring the single-object reading when it's ambiguous is the safer default. No change needed, but a short comment would record that the trade-off was deliberate. - Aliases are handled in one place only:
_is_keyed_mappingtreats aliases as slot names, but_validate_instance(line 321) still matches keys againstclass_slotsonly. So a single object written with alias keys is correctly treated as one object, and then its alias-named fields are skipped. This was already the case before this PR, but the new alias check implies support that the rest of the traversal doesn't have. You could either drop the alias part for consistency or follow it up in an issue. - Missing doctest:
_is_keyed_mappingstill has none. It's small enough to cover with aSchemaViewbuilt from a short YAML string, which CLAUDE.md prefers. This is optional, since the tests through theValidatorcover it. - Formatting:
- The new test adds another line longer than 88 characters (
assert [r.instantiates ...] == ["has_evidence[E1].supporting_text"]). It's worth runningjust formatin case CI checksruff format. - In
docs/troubleshooting.md:762, "…being checked. Before this, the objects…" is still one very long line. Rewrapping it would match the paragraph around it.
- The new test adds another line longer than 88 characters (
Performance and security
- Performance: no concerns.
_is_keyed_mappingnow callsinduced_slotfor each class slot, for every dict in a multivalued, class-ranged slot.SchemaViewcachesinduced_slot, so this is cheap. If it ever shows up in profiling, you could cache the slot and alias set per class. - Security: no concerns.
Test coverage
All the gaps from the two earlier reviews now have tests, including the mixed mapping. The one remaining option is a doctest for _is_keyed_mapping.
Summary: all three rounds of feedback are addressed. #141 and #139 look correct to me from reading the code, and the earlier single-object regressions are covered by tests. I couldn't run the tests in this job, so please make sure CI is green before merging.
· Branch: ccr-65a5480d-pb91sk
|
Thanks. None of these needs a push on its own:
Generated by Claude Code |
Fixes #139. Fixes #141.
The validation plugin handled only some shapes of data. A list of excerpts crashed it, and evidence held in a keyed mapping was never looked at.
#141: a multivalued excerpt slot crashes
validate dataWith
supporting_text: {multivalued: true}, theisinstance(excerpt_value, str)content check skipped lists, and theif not excerpt_valueguard let a non-empty list through. The list then reachedSupportingTextValidator.validateand failed withTypeError: expected string or bytes-like object, got 'list'(fromre.subn).Fix:
_validate_instance, an excerpt slot holding a list is split into its items. Each item is reported at its own path (supporting_text[1]), and a single value is treated as a list of one._excerpt_problem. An item that isn't text is reported as an error rather than crashing.#139: evidence in a keyed mapping is never validated
In the slot traversal, a dict value was always treated as one nested instance. For a multivalued, class-ranged slot with
inlined_as_list: false, the dict maps identifier → object. So the evidence objects inside were never visited, and a fabricated quote passed with exit 0.Fix: a dict in a multivalued, class-ranged slot goes to
_validate_keyed_objects:<slot>[<key>], for examplehas_evidence[E1].supporting_text.nullvalue is an object with only its key.Single-valued slots are unchanged.
Docs
docs/troubleshooting.mdgets a section next to the existing multiple-references one.Tests
tests/test_plugin_value_shapes.pyuses a real schema, the fixture cache, and the LinkMLValidator. It was written first; eight cases failed before the fix (TypeError, or "All validations passed!").supporting_text[0]has_evidence[E1].supporting_textFull suite: 2196 passed. Doctests, mypy and ruff are clean.
Generated by Claude Code