You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add frontmatter validation examples to schema system docs
Adds a new "Validating frontmatter fields" section with examples for
settings.frontmatter rules including enum constraints, required keys,
and array types. Updates the complete example to include frontmatter
validation. Based on test cases in test_schema_router.py.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|`status?(enum): [active, inactive]`| Observation with constrained value |`- [status] active`|
411
411
412
+
### Validating frontmatter fields
413
+
414
+
Schemas can also validate a note's YAML frontmatter — not just observations and relations. Use `settings.frontmatter` to declare rules for frontmatter keys using the same picoschema syntax:
415
+
416
+
```yaml
417
+
---
418
+
title: Person
419
+
type: schema
420
+
entity: person
421
+
schema:
422
+
name: string, full name
423
+
role?: string, job title
424
+
settings:
425
+
validation: warn
426
+
frontmatter:
427
+
tags?(array): string
428
+
status?(enum): [draft, published, archived]
429
+
---
430
+
```
431
+
432
+
This schema validates two things about each `person` note's frontmatter:
433
+
434
+
-**`tags`** — optional array of strings (e.g., `tags: [engineer, python]`)
435
+
-**`status`** — optional enum that must be one of `draft`, `published`, or `archived`
436
+
437
+
A conforming note:
438
+
439
+
```yaml
440
+
---
441
+
title: Grace Hopper
442
+
type: person
443
+
tags: [computing, compilers]
444
+
status: published
445
+
---
446
+
447
+
# Grace Hopper
448
+
449
+
## Observations
450
+
- [name] Grace Hopper
451
+
- [role] Computer Scientist
452
+
```
453
+
454
+
Validation checks both the body fields (`name`, `role`) and the frontmatter fields (`tags`, `status`):
455
+
456
+
```bash
457
+
$ bm schema validate people/grace-hopper.md
458
+
✓ grace-hopper: valid (0 warnings)
459
+
```
460
+
461
+
If a note has a frontmatter value outside the allowed enum:
462
+
463
+
```yaml
464
+
---
465
+
title: Iris West
466
+
type: person
467
+
status: archived # not in [draft, published]
468
+
---
469
+
```
470
+
471
+
```bash
472
+
$ bm schema validate people/iris-west.md
473
+
⚠ iris-west: frontmatter field 'status' enum mismatch (got 'archived', expected one of: draft, published)
474
+
```
475
+
476
+
If a required frontmatter key is missing (no `?` suffix), validation warns or errors depending on the mode:
477
+
478
+
```yaml
479
+
settings:
480
+
frontmatter:
481
+
status: string # required — no ? suffix
482
+
```
483
+
484
+
```bash
485
+
$ bm schema validate people/hank-pym.md
486
+
⚠ hank-pym: missing required frontmatter field: status
487
+
```
488
+
489
+
::note
490
+
Frontmatter rules use the same picoschema syntax as body fields. Add `?` for optional, `(array)` for lists, and `(enum)` for constrained values.
0 commit comments