Reasoning (guardrail_solver.reasoning)
The explanation DAG, the SMT helpers, the forward derivation rules, puzzle solving, and Mermaid rendering. See How reasoning works for the narrative.
reasoning
The reasoning engine, re-exported as a stable public surface.
The engine lives in :mod:._python, with rendering split out into
:mod:.renderers (.renderers.mermaid, .renderers.d3); this package
keeps the public import path (guardrail_solver.reasoning.X) stable so a
sibling backend can be slotted in behind it later without touching callers.
DEFAULT_REASONING_BACKEND
module-attribute
DEFAULT_REASONING_BACKEND = ReasoningBackend()
DEFAULT_SOLVER_TIMEOUT_MS
module-attribute
DEFAULT_SOLVER_TIMEOUT_MS = 30000
Z3_SEMANTICS
module-attribute
Z3_SEMANTICS = Z3SemanticBackend(
timeout_ms=DEFAULT_SOLVER_TIMEOUT_MS
)
ingest_puzzle
module-attribute
ingest_puzzle = ingest
solve_puzzle
module-attribute
solve_puzzle = PuzzleSolver()
CheckResult
dataclass
A classification verdict plus the witnessing models and unsat cores.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1528 1529 1530 1531 1532 1533 1534 1535 1536 | |
status
instance-attribute
status
true_model
instance-attribute
true_model
false_model
instance-attribute
false_model
true_core
instance-attribute
true_core
false_core
instance-attribute
false_core
Consistent
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
30 31 | |
Derivation
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
146 147 148 149 | |
premise_ids
instance-attribute
premise_ids
rule
instance-attribute
rule
DerivationBackend
Bases: Protocol
Propose one round of derived facts from an immutable graph snapshot.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
56 57 58 59 60 61 62 | |
derive
derive(input_)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
59 60 61 62 | |
DerivationId
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
84 85 86 87 88 89 | |
value
instance-attribute
value
DerivationInput
dataclass
Backend-free view constructible only from a consistent unsaturated graph.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
152 153 154 155 156 | |
established
instance-attribute
established
DerivationNode
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
134 135 136 137 | |
id
instance-attribute
id
rule
instance-attribute
rule
DerivationProposal
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
100 101 102 103 104 105 | |
conclusion
instance-attribute
conclusion
premises
instance-attribute
premises
rule
instance-attribute
rule
source
class-attribute
instance-attribute
source = None
Entailment
Bases: Enum
A three-valued entailment verdict.
Deliberately a plain Enum, not IntEnum: a verdict must not be
collapsible to bool — being three-valued is the whole point. Always
compare with is (result is Entailment.PROVED); never use it in a
boolean context, where "the solver gave up" would silently read as success.
The values form a conjunction lattice in which REFUTED is absorbing
(one countermodel refutes the whole) and PROVED is the identity
(an all-proved conjunction is proved), with UNDECIDED between. The
ordering is expressed directly in :meth:conjunction, not smuggled into
integer values.
PROVED— the premises entail the conclusion (¬conclusionunsat).REFUTED— a countermodel exists (premises ∧ ¬conclusionsat); the entailment is definitely false, not merely unproven. The witnessing model lives on theSolveResult/classifypath, not here.UNDECIDED— the solver could not decide (an encoding/theory limit).
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | |
REFUTED
class-attribute
instance-attribute
REFUTED = 'REFUTED'
UNDECIDED
class-attribute
instance-attribute
UNDECIDED = 'UNDECIDED'
PROVED
class-attribute
instance-attribute
PROVED = 'PROVED'
meet
meet(other)
Binary Kleene conjunction (∧) — the monoid op behind conjunction.
REFUTED is absorbing, PROVED is the identity, UNDECIDED sits
between. Raises on a non-Entailment rather than returning
NotImplemented (this is a plain method, not an operator dunder, so
NotImplemented would silently leak as a value).
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 | |
conjunction
classmethod
conjunction(results)
Fold meet over obligations that must all hold.
REFUTED is the absorbing element, so this short-circuits: given a
generator of solver calls, it stops at the first countermodel instead of
running the rest. The empty conjunction is PROVED (vacuous truth).
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | |
Evidence
dataclass
Phantom evidence carried by a graph's static type.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
42 43 44 | |
ExplanationBackend
Bases: Protocol
Propose explanation edges without mutating the fact graph.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
65 66 67 68 69 70 71 72 | |
explain
explain(input_, semantics)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
68 69 70 71 72 | |
ExplanationInput
dataclass
Backend-free view constructible only from a consistent saturated graph.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
159 160 161 162 163 164 | |
established
instance-attribute
established
checks
instance-attribute
checks
ExplanationNode
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
140 141 142 143 | |
id
instance-attribute
id
rule
instance-attribute
rule
ExplanationProposal
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
167 168 169 170 171 | |
check_id
instance-attribute
check_id
premises
instance-attribute
premises
rule
instance-attribute
rule
FactGraph
dataclass
Bases: Generic[StateT]
Facts, derivation steps, and checks in one typed provenance DAG.
Derivations are represented as:
premise fact -> derivation step -> conclusion fact
This preserves multi-premise rules and allows a single semantic fact to have
several independent derivations without overloading edge labels or a single
rule attribute on the conclusion fact.
Checks remain candidate propositions, not established facts. They cannot be
premises; they are sinks. A known fact can point directly into a check when
explain_check establishes an explicit explanation step.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
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 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 | |
dag
class-attribute
instance-attribute
dag = field(default_factory=ProvenanceDag)
by_expr
class-attribute
instance-attribute
by_expr = field(default_factory=dict)
next_index
class-attribute
instance-attribute
next_index = 1
next_derivation_index
class-attribute
instance-attribute
next_derivation_index = 1
reasoning_backend
class-attribute
instance-attribute
reasoning_backend = field(
default_factory=default_reasoning_backend,
compare=False,
repr=False,
)
nodes
property
nodes
derivation_nodes
property
derivation_nodes
derivations
property
derivations
empty
classmethod
empty()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
550 551 552 | |
with_reasoning_backend
with_reasoning_backend(backend)
Return an equal immutable graph using backend operationally.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
554 555 556 557 558 559 | |
fact
fact(fact_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
567 568 | |
derivation_step
derivation_step(derivation_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
570 571 | |
add_given
add_given(prop_, *, subject_name, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |
add_check
add_check(prop_, *, subject_name, check_label, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 | |
add_derived
add_derived(prop_, *, premises, rule, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
apply_derivation
apply_derivation(proposal)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
apply_derivations
apply_derivations(proposals)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
747 748 749 750 751 752 753 754 755 756 | |
established_facts
established_facts()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
807 808 809 810 | |
base_exprs
base_exprs()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
812 813 | |
derivation_input
derivation_input()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
815 816 817 818 | |
explanation_input
explanation_input(checks)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
820 821 822 823 824 825 826 827 828 829 830 831 | |
check_consistent
check_consistent()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
833 834 835 836 837 838 839 840 841 842 | |
saturate
saturate()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
844 845 846 847 848 849 850 851 852 853 854 | |
classify
classify(check)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
856 857 858 859 860 861 862 | |
verify_derivations
verify_derivations()
Re-check every stored derivation against the solver.
Derivations are already entails-verified at insertion time in
add_derived; this is an opt-in audit for callers who want to
re-establish that guarantee (e.g. over a deserialized graph), not
something the solving pipeline runs per round.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | |
explanation_for
explanation_for(target)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | |
explanation_subgraph_for
explanation_subgraph_for(target)
Return the minimal ancestor subgraph explaining target.
This is the graph-shaped counterpart to explanation_for. It keeps
the same immutable graph wrapper, but restricts the DAG to the target
fact plus all graph nodes that feed into it, including derivation steps.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 | |
explain_check
explain_check(check)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 | |
apply_explanation
apply_explanation(proposal)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 | |
FactGraphExplanationBackend
dataclass
Use shared semantic equivalence to propose check explanations.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 | |
explain
explain(input_, semantics)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 | |
FactId
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
76 77 78 79 80 81 | |
value
instance-attribute
value
FactKind
Bases: str, Enum
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
108 109 110 111 | |
GIVEN
class-attribute
instance-attribute
GIVEN = 'GIVEN'
DERIVED
class-attribute
instance-attribute
DERIVED = 'DERIVED'
CHECK
class-attribute
instance-attribute
CHECK = 'CHECK'
FactNode
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
123 124 125 126 127 128 129 130 131 | |
id
instance-attribute
id
kind
instance-attribute
kind
expr
instance-attribute
expr
text
instance-attribute
text
subject
class-attribute
instance-attribute
subject = None
check_label
class-attribute
instance-attribute
check_label = None
source
class-attribute
instance-attribute
source = None
FactToken
dataclass
Bases: Generic[ExprT]
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
95 96 97 | |
id
instance-attribute
id
ForwardDerivationBackend
dataclass
Current Python fixed-point rules behind the derivation interface.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 | |
derive
derive(input_)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1459 1460 1461 1462 1463 1464 1465 | |
IngestedPuzzle
dataclass
Bases: Generic[PuzzleT]
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1521 1522 1523 1524 1525 | |
puzzle
instance-attribute
puzzle
graph
instance-attribute
graph
check_tokens
instance-attribute
check_tokens
LinearOffset
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1232 1233 1234 1235 | |
source
instance-attribute
source
offset
instance-attribute
offset
ProvenanceDag
dataclass
Typed boundary around the heterogeneous provenance rustworkx DAG.
rustworkx has no freeze() equivalent, so immutability is by convention,
not by runtime guard: every mutating method below builds a fresh
.copy() (via to_rustworkx) and never touches self._graph or
self._index_by_id in place.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 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 | |
from_rustworkx
classmethod
from_rustworkx(graph)
Copy, validate, and adopt a raw interoperability graph.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
191 192 193 194 195 196 197 198 199 200 201 202 | |
to_rustworkx
to_rustworkx()
Return a mutable copy for explicit interoperability boundaries.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
204 205 206 | |
validate
validate()
Establish the complete typed provenance topology at one boundary.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
fact
fact(fact_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
277 278 | |
derivation
derivation(derivation_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
280 281 | |
explanation
explanation(step_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
283 284 | |
facts
facts()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
286 287 | |
derivation_nodes
derivation_nodes()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
289 290 291 292 | |
nodes
nodes()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
294 295 296 297 298 299 | |
edges
edges()
Yield edges grouped by source in node-creation order.
rx.PyDiGraph.edge_list() orders by raw edge-insertion time, which
depends on incidental construction order rather than graph content —
two structurally equivalent graphs built in a different sequence (or
via a different backend) could yield edges differently, changing
renderer output for no semantic reason. Iterating nodes in creation
order, then each node's own successors, is canonical: it depends only
on stable node identity (assigned once, at creation), not on when an
edge happened to be added.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
in_degree
in_degree(fact_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
321 322 | |
has_edge
has_edge(source, target)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
324 325 326 327 328 329 | |
explanation_node_ids
explanation_node_ids(target_id)
Return the target and every provenance node contributing to it.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
342 343 344 345 346 347 348 349 350 351 352 | |
derivations
derivations()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
has_derivation
has_derivation(*, conclusion_id, premise_ids, rule)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
with_fact
with_fact(node, *, derivation=None, premises=())
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
with_derivation
with_derivation(derivation, *, premises, conclusion)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
428 429 430 431 432 433 434 435 436 437 438 439 | |
with_explanation
with_explanation(explanation, *, premises, check)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
441 442 443 444 445 446 447 448 449 450 451 452 | |
explanation_nodes
explanation_nodes(target_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
slice_for
slice_for(target_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
469 470 471 472 473 474 475 476 | |
PuzzleSolver
dataclass
Configured callable that solves puzzles with one reasoning backend.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 | |
backend
class-attribute
instance-attribute
backend = DEFAULT_REASONING_BACKEND
ingest
ingest(puzzle)
Parse a puzzle without attaching this solver's backend.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 | |
ReasoningBackend
dataclass
Composite, graph-independent reasoning capabilities.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 | |
semantics
class-attribute
instance-attribute
semantics = Z3_SEMANTICS
derivation
class-attribute
instance-attribute
derivation = ForwardDerivationBackend()
explanation
class-attribute
instance-attribute
explanation = FactGraphExplanationBackend()
max_rounds
class-attribute
instance-attribute
max_rounds = 20
Saturated
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
38 39 | |
SemanticBackend
Bases: Protocol
One complete decision primitive from which logical queries are derived.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
50 51 52 53 | |
solve
solve(assertions)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
53 | |
SolveResult
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1032 1033 1034 1035 1036 | |
status
instance-attribute
status
model
class-attribute
instance-attribute
model = None
core
class-attribute
instance-attribute
core = ()
SolveStatus
Bases: str, Enum
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1008 1009 1010 1011 1012 1013 1014 | |
SAT
class-attribute
instance-attribute
SAT = 'SAT'
UNSAT
class-attribute
instance-attribute
UNSAT = 'UNSAT'
UNKNOWN
class-attribute
instance-attribute
UNKNOWN = 'UNKNOWN'
TIMEOUT
class-attribute
instance-attribute
TIMEOUT = 'TIMEOUT'
SolvedPuzzle
dataclass
Bases: Generic[PuzzleT]
A puzzle after ingestion, consistency check, saturation, and attach.
graph is the final explanation DAG; check_tokens maps each check
label to the fact recording that candidate proposition.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 | |
puzzle
instance-attribute
puzzle
graph
instance-attribute
graph
check_tokens
instance-attribute
check_tokens
SourceSpan
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
114 115 116 117 118 119 120 | |
uri
instance-attribute
uri
start_line
instance-attribute
start_line
start_col
instance-attribute
start_col
end_line
instance-attribute
end_line
end_col
instance-attribute
end_col
Unchecked
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
26 27 | |
Unsaturated
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
34 35 | |
Z3SemanticBackend
dataclass
Default semantic backend using Z3's solver and unsat cores.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 | |
solver_factory
class-attribute
instance-attribute
solver_factory = field(default=Solver, repr=False)
timeout_ms
class-attribute
instance-attribute
timeout_ms = None
solve
solve(assertions)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1199 1200 1201 1202 1203 1204 1205 | |
all_equivalent
all_equivalent(*predicates, backend=None)
Are all predicates provably equivalent to one another?
Entailment is a preorder, so mutual equivalence of a set is "every element
lies in one strongly-connected component". Establishing that does not
require all N·(N−1) ordered pairs: because the PROVED fragment of
entailment is transitive (A⊨B ∧ B⊨C ⟹ A⊨C — a theorem, independent of
the solver), a single covering cycle p₀ ⊨ p₁ ⊨ … ⊨ p₀ proves it in
N solver calls rather than N². conjunction short-circuits on the
first REFUTED link, so a definite mismatch costs even less.
Fewer than two predicates are vacuously equivalent (PROVED), with no
solver call. equivalent is the binary case.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 | |
arith_key
arith_key(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1324 1325 | |
as_bool_ref
as_bool_ref(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1218 1219 | |
as_int
as_int(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1226 1227 1228 1229 | |
check_with_core
check_with_core(
base, extra, *, solver_factory=Solver, timeout_ms=None
)
Low-level Z3 solve retaining a model, unsat core, or unknown result.
timeout_ms bounds the solve: a query that exceeds it returns
SolveStatus.TIMEOUT rather than running unbounded, so a small but
solver-expensive request cannot exhaust the service.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 | |
classify
classify(base, check, *, backend=None)
Classify check against base as VERIFIED/FALSIFIED/UNKNOWN/…
Runs the solver twice — once asserting the check, once its negation — and
maps the (satisfiable, refutable) pair to a :class:Status. This is the
engine puzzle mode and the workflow coverage analysis both build on.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 | |
classify_check
classify_check(base, check)
Classify a proposition with the default reasoning backend.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1575 1576 1577 1578 1579 1580 | |
empty_rustworkx_digraph
empty_rustworkx_digraph()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
174 175 | |
entails
entails(premises, conclusion, *, backend=None)
Classify whether premises entail conclusion without losing unknown.
A SAT result for premises ∧ ¬conclusion is a countermodel, so it
maps to REFUTED (definitely not entailed), not a mere proof failure.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | |
equality_sides
equality_sides(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1272 1273 1274 1275 1276 1277 1278 1279 | |
equivalent
equivalent(a, b, *, backend=None)
Logical equivalence of two predicates.
The binary case of :func:all_equivalent — the 2-cycle a ⊨ b ⊨ a.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | |
expr_key
expr_key(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1320 1321 | |
is_eq
is_eq(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1222 1223 | |
linear_offset
linear_offset(expr)
Parse simplify(expr) as source + offset for a single symbolic source.
Only addition needs handling: Z3's simplify normalises subtraction into
addition of negated terms. Anything else (pure constants, multiple
symbolic terms) returns None, and callers simply derive nothing from it.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 | |
parse_constant_equality
parse_constant_equality(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 | |
parse_offset_equality
parse_offset_equality(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 | |
print_core
print_core(core)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1595 1596 1597 | |
print_model
print_model(model, subject_names)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 | |
render_arith
render_arith(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1328 1329 | |
render_fact
render_fact(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 | |
to_wire_explanation_dag
to_wire_explanation_dag(dag)
Project dag into the portable, z3-free explanation-DAG wire form.
A faithful, order-stable read: node/edge order matches dag.nodes() /
dag.edges() exactly, so two equivalent DAGs always project to the
same wire form regardless of graph backend.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
graph_to_d3_html
graph_to_d3_html(
graph, *, element_id="reasoning-d3", library="cytoscape"
)
Render a FactGraph explanation DAG as a self-contained HTML snippet.
Returns a <div> plus inline <script> that loads the chosen
library from a CDN and draws the graph client-side. See
D3Library and the module docstring
for the trade-off between the two styles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
FactGraph[Any]
|
The graph to render. |
required |
element_id
|
str
|
The HTML id attribute for the container div element. |
'reasoning-d3'
|
library
|
D3Library
|
The chosen rendering library. |
'cytoscape'
|
Returns:
| Type | Description |
|---|---|
str
|
Self-contained HTML snippet string. |
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/d3.py
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 | |
graph_to_d3_payload
graph_to_d3_payload(graph, *, library='cytoscape')
Build the JSON-able payload (meta/nodes/links) for a graph.
library picks the payload shape to build (see D3Library
and the module docstring): "cytoscape" (the default) omits per-node
positions (Cytoscape computes them client-side); "d3" includes a
fixed x/y/width per node computed here in Python.
The name is kept as d3_payload for backwards compatibility with
existing callers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
FactGraph[Any]
|
The FactGraph to build the payload for. |
required |
library
|
D3Library
|
The chosen rendering library. |
'cytoscape'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the keys "meta", "nodes", and "links" with graph representation data. |
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/d3.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 | |
graph_to_mermaid
graph_to_mermaid(
graph,
*,
focus=None,
grouping="flat",
include_config=True,
include_clicks=True
)
Render a FactGraph using semantic rows.
Rows are: - Givens - Reasoning - Derived facts - Checks
Nodes are arranged left-to-right within their semantic row where the
layout engine allows it. grouping picks how rows and the
focus/peripheral split are conveyed visually — see MermaidGrouping
and the module docstring for the trade-off between the two styles.
When focus is supplied, the focused fact and all provenance ancestors
are the vivid, prominent group; unrelated graph material is muted and
placed beneath it.
Derivations remain explicit
premise fact -> reasoning step -> conclusion fact
Explanation steps are collapsed
known fact -. rule .-> check
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
FactGraph[Any]
|
The FactGraph to render. |
required |
focus
|
MermaidFocus
|
The node/fact to focus on. |
None
|
grouping
|
MermaidGrouping
|
The grouping/layout style. |
'flat'
|
include_config
|
bool
|
Whether to include default Mermaid config markers. |
True
|
include_clicks
|
bool
|
Whether to include hyperlink actions for clickable nodes. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The generated Mermaid graph string. |
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/mermaid.py
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 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 | |
graph_to_mermaid_markdown
graph_to_mermaid_markdown(
graph,
*,
focus=None,
grouping="flat",
include_config=True,
include_clicks=True
)
Render a FactGraph as a fenced Mermaid Markdown block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
FactGraph[Any]
|
The FactGraph to render. |
required |
focus
|
MermaidFocus
|
The node/fact to focus on. |
None
|
grouping
|
MermaidGrouping
|
The grouping/layout style. |
'flat'
|
include_config
|
bool
|
Whether to include default Mermaid config markers. |
True
|
include_clicks
|
bool
|
Whether to include hyperlink actions for clickable nodes. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The fenced Mermaid Markdown block string. |
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/mermaid.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | |
mermaid_fact_declaration
mermaid_fact_declaration(node, *, include_subject)
Declare a fact using Mermaid's native Markdown wrapping.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/mermaid.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
mermaid_fact_label
mermaid_fact_label(node, *, include_subject)
Render a natively wrapping label without internal provenance ids.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/mermaid.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
mermaid_graph_node_id
mermaid_graph_node_id(node_id)
Return the Mermaid id corresponding to a provenance graph node.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/mermaid.py
221 222 223 224 225 226 227 228 229 | |