ontocast.tool.facts_validation.gate¶
Document-level validation for the post-aggregation facts gate.
Merge-signature findings, SHACL conformance summary, non-catalog vocabulary telemetry, dangling references, and the gate metrics record.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
FactsValidationReport
¶
Bases: BaseModel
Invariant findings over one aggregated facts graph.
Source code in ontocast/tool/facts_validation/gate.py
Attributes¶
error_findings
property
¶
Error-severity findings, whatever their kind.
findings = Field(default_factory=list)
class-attribute
instance-attribute
¶
model_config = {'arbitrary_types_allowed': True}
class-attribute
instance-attribute
¶
shacl_evaluated = Field(default=None, description="True when SHACL ran, False when shapes were configured but it could not (pyshacl missing, graph over the size guard), None when no shapes were in play. 'No SHACL findings' means nothing without this: it reads identically for 'conforms' and 'never checked'.")
class-attribute
instance-attribute
¶
shacl_violations = Field(default_factory=list, exclude=True, repr=False, description='Raw, unfiltered pyshacl violations, kept so the autofix pass can reuse them instead of re-running validation. Internal: never serialized.')
class-attribute
instance-attribute
¶
Functions:¶
count_shacl_focus_nodes(data_graph, shapes_graph)
¶
Count data-graph nodes any shape actually targets.
This is the denominator conforms is silent about. A validation run over
zero focus nodes reports no violations for the same reason an empty query
returns no rows -- nothing was examined. Reported alongside conforms so
a clean result cannot be read as a passing one when the shapes and the data
never met.
Class targeting follows rdfs:subClassOf because SHACL's
sh:targetClass is subclass-aware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_graph
|
RDFGraph
|
The graph that was validated. |
required |
shapes_graph
|
RDFGraph | None
|
The shapes it was validated against; |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: Number of distinct focus nodes, or |
Source code in ontocast/tool/facts_validation/gate.py
record_facts_gate_metrics(metrics, *, report, repair_result, ontology_context_empty=False)
¶
Write the validation-gate metrics both entry paths share.
The graph pipeline's VALIDATE_FACTS node and the single-unit gate behind
/process_unit run the same checks minus the un-merge repair, and had
drifted into two hand-maintained copies of these writes — so a metric added
to one path was silently absent from the other, and batch dumps stopped
being comparable across entry paths, which is the one thing they exist for.
Merge-specific counters stay with the graph pipeline: they have no meaning
for a single unit.
Takes a plain mapping rather than AgentState so the tool layer stays
ignorant of the state graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
MutableMapping[str, int | float | str | dict]
|
|
required |
report
|
FactsValidationReport
|
Validation report describing the graph that will be served. |
required |
repair_result
|
ShaclRepairResult
|
Outcome of :func: |
required |
ontology_context_empty
|
bool
|
Whether the facts were validated with no
catalog vocabulary at all. The per-term non-catalog check cannot
see this — with no context there is nothing to compare against — so
it is reported here, where an empty context is known to be
unexpected. Only the document path used to report it, which left
|
False
|
Source code in ontocast/tool/facts_validation/gate.py
summarize_conformance(findings, *, shacl_evaluated=None, repairs=(), focus_nodes=None)
¶
Roll findings up into the shape a report or a client can read.
Counting by constraint component is what separates "168 violations" from "two systematic defects": 71 missing-qualifier violations on one shape are one modelling gap, not 71 problems to triage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
findings
|
Sequence[FactsValidationFinding]
|
Residual findings after any repair. |
required |
shacl_evaluated
|
bool | None
|
Whether SHACL actually ran (see
:class: |
None
|
repairs
|
Sequence[GraphRepairRecord]
|
LLM-free repairs the gate applied. |
()
|
focus_nodes
|
int | None
|
Data-graph nodes the shapes actually target, from
:func: |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
empty focus set), counts by severity, by finding kind, by SHACL |
dict
|
constraint component and shape, and the applied repair counts by kind. |
dict
|
|
dict
|
measurement failure rather than a passing grade. |
Source code in ontocast/tool/facts_validation/gate.py
validate_aggregated_facts(graph, ontology_graph, *, shapes_graph=None, fact_namespaces=None, suspect_multi_value_severity='error', functional_min_single_support=3, quantity_fallback_vocabulary=None, shacl_inference='rdfs', shacl_advanced=True, shacl_max_triples=0, key_supported_subjects=None, cross_unit_pairs=None)
¶
Check post-merge invariants over the aggregated facts graph.
Deterministic defense-in-depth behind the merge guards: merge-signature violations here are almost always a bad identity merge, and error-severity findings of those kinds on merged subjects drive the un-merge repair. SHACL findings are reported but never drive it: a constraint violation says a node is under-specified, not that two entities were wrongly identified.
Checks
FUNCTIONAL_VIOLATION: >= 2 distinct objects on a predicate the schema constrains to at most one value (owl:FunctionalPropertyor an OWL max-cardinality-1 restriction).SUSPECT_MULTI_VALUE: >= 2 distinct canonical numeric values on one (subject, predicate); >= 2 mutually irreconcilable short string values on a predicate that is string-single-valued for a dominant majority (distinct names collapsed into one node); or >= 2 IRI objects on a predicate that is single-valued for a dominant majority of other subjects. Severity is configurable — legitimate multi-value modeling exists, bad merges are far more common. The IRI branch additionally acceptscross_unit_pairs, which separates the two by provenance rather than by frequency.DEGENERATE_COREFERENCE: one IRI object shared by >= 2 distinct functional-ish predicates of one subject (collapsed range bounds).SHACL: optional, whenpyshaclis installed and shapes exist.NON_CATALOG_VOCABULARY: warning-only telemetry for terms the ontology context never supplied, which mark a retrieval miss the renderer papered over with a documented fallback.MIXED_OBJECT_KINDS: warning-only telemetry for predicates used with both IRI and literal objects across the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
RDFGraph
|
Aggregated facts graph. |
required |
ontology_graph
|
RDFGraph | None
|
Merged ontology context (functionality harvest). |
required |
shapes_graph
|
RDFGraph | None
|
Optional SHACL shapes graph. |
None
|
fact_namespaces
|
list[str] | None
|
When set, only subjects under these namespaces are reported (ontology entities are not the gate's business). |
None
|
suspect_multi_value_severity
|
str
|
|
'error'
|
functional_min_single_support
|
int
|
Minimum single-valued subjects before a predicate counts as dominantly single-valued. |
3
|
shacl_inference
|
str
|
pyshacl pre-inference mode (see :func: |
'rdfs'
|
shacl_advanced
|
bool
|
Enable SHACL Advanced Features. |
True
|
shacl_max_triples
|
int
|
Skip SHACL above this graph size; 0 disables. |
0
|
cross_unit_pairs
|
Sequence[tuple[str, str]] | None
|
Canonical (subject, predicate) pairs whose IRI objects came from more than one unit. When supplied, an IRI-branch SUSPECT_MULTI_VALUE finding on a pair not listed here is reported as a warning and never vetoes a cluster: a single unit asserting two objects on one predicate is reading one sentence, not the residue of a bad identity decision. None disables the distinction. |
None
|
key_supported_subjects
|
Sequence[str] | None
|
Final URIs of merge clusters backed by natural-key evidence. Irreconcilable string values on these subjects are reported as warnings, not errors: a registry number and a full title can be two names for one key-confirmed record, and an error here would drive the un-merge repair to split a correct merge. |
None
|
Returns:
| Type | Description |
|---|---|
FactsValidationReport
|
Report with all findings, ordered by subject. |
Source code in ontocast/tool/facts_validation/gate.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | |