Skip to content

fathom.AssertSpec

fathom.AssertSpec

Bases: BaseModel

A fact assertion emitted from a rule's then clause.

Compile-time YAML spec: slot values are strings (CLIPS source text or ?var bindings from the LHS). Materialized values after evaluation are read back via :class:AssertedFact.

Example

spec = AssertSpec(template="decision", slots={"action": "allow"}) spec.template 'decision'

Source code in src/fathom/models.py
class AssertSpec(BaseModel):
    """A fact assertion emitted from a rule's ``then`` clause.

    Compile-time YAML spec: slot values are strings (CLIPS source text or
    ``?var`` bindings from the LHS). Materialized values after evaluation
    are read back via :class:`AssertedFact`.

    Example:
        >>> spec = AssertSpec(template="decision", slots={"action": "allow"})
        >>> spec.template
        'decision'
    """

    template: str
    slots: dict[str, str] = Field(default_factory=dict)

    @field_validator("template")
    @classmethod
    def _template_name_must_be_clips_ident(cls, v: str) -> str:
        return _validate_clips_ident(v, "AssertSpec.template")

    @field_validator("slots")
    @classmethod
    def _slot_values_must_be_safe(cls, v: dict[str, str]) -> dict[str, str]:
        for slot_name, slot_value in v.items():
            _validate_clips_ident(slot_name, "AssertSpec slot")
            _validate_slot_value(slot_value)
        return v