better data models

This commit is contained in:
John Lancaster
2026-06-21 16:53:43 -05:00
parent 34923b51d7
commit 37fa9b6c6f
8 changed files with 261 additions and 525 deletions
+17 -4
View File
@@ -1,8 +1,10 @@
import re
from collections.abc import Mapping
from pathlib import PurePosixPath
from typing import Any
from typing import Literal
import yaml
from pydantic import Field
from pydantic import field_validator
@@ -100,10 +102,21 @@ class PromptFrontmatter(StrictFrozenModel):
return value
class PromptDocumentModel(StrictFrozenModel):
"""Structured representation of a prompt markdown document."""
class StoredPrompt(StrictFrozenModel):
"""Normalized prompt document content with path and frontmatter for storage in the registry."""
prompt_id: str
relpath: str
relpath: PurePosixPath
content: str
frontmatter: PromptFrontmatter
frontmatter: PromptFrontmatter | None = None
@field_validator("frontmatter", mode="before")
@classmethod
def parse_frontmatter_yaml(cls, value: str | None):
if value is None:
return None
try:
data = yaml.safe_load(value)
except yaml.YAMLError as e:
raise ValueError(f"invalid YAML in frontmatter: {e}") from e
return PromptFrontmatter.model_validate(data)