Let an incomplete entity be saved and report what it still needs - #219
Merged
Conversation
A required field described what a valid entity carries, but was enforced when one was built, so an agent reading a source document was refused an entity whose title it had not reached yet and lost the fields it had. Required now guides rather than blocks: absence is allowed and reported, a value that breaks the profile's rules is still refused, and the published JSON Schema keeps declaring the required fields so a consumer can enforce what it likes.
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.
requireddescribed what a valid entity carries, but it was enforced when one was built. An agent reading a source document was therefore refused an entity whosetitleit had not reached yet, and lost the fields it did have. Metadata is gathered a piece at a time; the point ofrequiredis to guide an incomplete record towards a correct one, not to prevent the incomplete record existing.The rule now
unique_idthat breaks its pattern raises, as before).Three things this surfaced
The description had gone silent. With nothing Pydantic-required, the generated JSON Schema listed no required fields at all, a description contradicting the profile.
EntityBaseModel.model_json_schemanow restores the list fromspec_required_fields()and unwraps the "or null" for those fields, so the type reads as the profile declares it.The UI stopped warning. The incomplete-draft warning was produced by catching the rejection. With nothing rejected, an incomplete entity saved silently, the opposite of guiding the user. Both the create and update paths now look for missing required fields via
missing_required_fieldsinstead of catching them, so the "Saved draft ... (incomplete)" warning still appears.String to entity coercion.
_coerce_string_to_entitycounted Pydantic-required fields to decide whether a bare string should become an entity. With none required that count is always 0, which would have made it coerce far more widely. It now reads the spec's list via__spec_required__.Tests
Eight tests encoded the old blocking contract and were rewritten to the new one, including
test_no_parent_still_requires_the_reference: a parent-child edge is carried by the tree, so a Study created on its own saves and validation reports the missing back-reference if the profile asks for one. Full suite: 2685 passed.Docs
docs/specification/system-specification.mdgains a "Required fields" section stating the rule and the three obligations it places on implementations; two passages claiming requiredness is enforced at model construction were corrected.docs/api/schema-specs.mdgains the same with a worked example. Docstrings updated onFieldSpec.required,get_required_fields,RequiredFieldsRule, and the agent'sget_required_fieldstool.Compatibility
An entity that used to be refused now saves. Pre-1.0, so this ships as a minor bump.