Skip to content

Validation

Inspect an ExtractResult against the template's constraints.

validate

validate(
    result: ExtractResult, template: Template
) -> Report

Validate an ExtractResult against a template's constraints.

This is a pure inspection — it does not mutate result. The returned Report carries every error surfaced during extraction (structural and coercion problems) plus any constraint violations found in the canonical data.

Parameters:

Name Type Description Default
result ExtractResult

The output of crease.extract.

required
template Template

The same Template used to produce result.

required

Returns:

Type Description
Report

A Report describing every problem found.

check

check(
    path: str | Path,
    template: Template,
    *,
    engine: Engine | None = None,
) -> tuple[ExtractResult, Report]

Run extract + validate in one call.

Parameters:

Name Type Description Default
path str | Path

Path to the source file.

required
template Template

A loaded crease.Template.

required
engine Engine | None

See crease.extract.

None

Returns:

Type Description
ExtractResult

A tuple (result, report). result always carries a populated

Report

canonical dict (even when there are errors — partial extraction is

tuple[ExtractResult, Report]

the whole point); report carries the full error list.

Report dataclass

Report(errors_list: list[Error] = list())

Result of validating an ExtractResult against its template.

Attributes:

Name Type Description
errors_list list[Error]

The full list of Error records.

The richer API surface (is_valid, errors(), error_count()) is accessed as methods/properties, matching the pydantic idiom.

is_valid property

is_valid: bool

True iff zero errors. The 90% check.

has_structural property

has_structural: bool

True if any error is structural (template can't map the file).

errors

errors() -> list[Error]

Return the full list of errors. Pydantic-shaped.

error_count

error_count() -> int

raise_if_invalid

raise_if_invalid() -> None

If any errors are present, raise ValidationError with the full list.

to_dict

to_dict() -> dict[str, Any]

Serialize to a plain dict suitable for JSON output.