feat: add frontmatter validation to schema system#597
Conversation
Add optional frontmatter validation rules to schema notes under `settings.frontmatter`, using the same Picoschema syntax as the `schema` block. This allows schema notes to validate metadata keys like `tags` and `status` in addition to observation/relation content. - Add `frontmatter_fields` to `SchemaDefinition` dataclass - Parse `settings.frontmatter` in `parse_schema_note` via existing `parse_picoschema()` - Add `_validate_frontmatter_field()` helper for presence/enum checks - Pass frontmatter dict through `validate_note()` to schema router - Inline schemas skip frontmatter validation automatically (default `[]`) - 17 new tests: 3 parser, 11 validator, 3 router integration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task in 2m 22s —— View job PR Review: feat: add frontmatter validation to schema systemTasks:
SummaryClean, well-structured addition. The approach of reusing Bug: Empty frontmatter dict skips validation
if frontmatter and schema.frontmatter_fields:This uses truthiness on The stated intent is that The fix is: if frontmatter is not None and schema.frontmatter_fields:In practice the router always injects at least Related: Minor: Doc has stale router path
Actual path is Behavioral note: empty array treated as "present"
if isinstance(value, list):
return FieldResult(field=schema_field, status="present", values=[str(v) for v in value])If Team ChecklistCode Quality & Standards
Testing & Documentation
Basic Memory Architecture
Security & Performance
Compatibility
OverallGood PR. One real bug to fix ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8d7a6688f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/basic_memory/schema/validator.py
Outdated
| # Trigger: schema has frontmatter_fields and caller provided frontmatter dict | ||
| # Why: settings.frontmatter rules validate metadata keys like tags, status | ||
| # Outcome: frontmatter fields produce the same FieldResult/warning/error as content fields | ||
| if frontmatter and schema.frontmatter_fields: |
There was a problem hiding this comment.
Validate empty frontmatter dicts instead of skipping
Change the guard to avoid truthiness checks here: when frontmatter={} is passed, this block is skipped entirely and required settings.frontmatter fields are never marked missing, so strict-mode validation can incorrectly pass. Since validate_note() accepts a frontmatter dict and {} is a valid “no keys present” input, this should run whenever frontmatter is provided (e.g., frontmatter is not None).
Useful? React with 👍 / 👎.
`frontmatter={}` is a valid input where required keys should be flagged
missing. The truthiness check `if frontmatter` skipped validation for
empty dicts, allowing strict-mode to incorrectly pass.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task in 1m 13s —— View job PR Review: feat: add frontmatter validation to schema systemTasks:
Update: Follow-up Commit ReviewThis review covers the follow-up commit Bug Fix: Verified ✅
The guard has been corrected: # Before (buggy)
if frontmatter and schema.frontmatter_fields:
# After (correct)
if frontmatter is not None and schema.frontmatter_fields:This correctly distinguishes New Tests: Complete ✅Two tests were added that close the coverage gap identified in the prior review (
Both tests are correctly structured and cover the semantically distinct Remaining Nit: Stale Doc Path
Actual path is Team ChecklistCode Quality & Standards
Testing & Documentation
Basic Memory Architecture
Security & Performance
Compatibility
OverallThe primary bug from the first review has been fixed correctly, and both new tests accurately cover the |
Summary
settings.frontmattervalidation rules to schema notes, using the same Picoschema syntax as theschemablocktags,status, etc. for presence, enum value membership, and array contentsfrontmatter_fields=[])Schema Note Format
Changes
frontmatter_fieldstoSchemaDefinition, parsesettings.frontmattervia existingparse_picoschema()frontmatterparam tovalidate_note(), add_validate_frontmatter_field()helperfrontmatter=frontmatterto bothvalidate_note()call sitesTest plan
just fast-checkpasses (lint, format, typecheck, impacted tests, smoke)🤖 Generated with Claude Code