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,
.renderers.markdown); 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.
ENTAILS_NOTARY
module-attribute
ENTAILS_NOTARY = EntailsNotary()
DEFAULT_SOLVER_TIMEOUT_MS
module-attribute
DEFAULT_SOLVER_TIMEOUT_MS = 30000
Z3_ALGEBRA
module-attribute
Z3_ALGEBRA = Z3ExpressionAlgebra()
Z3_SEMANTICS
module-attribute
Z3_SEMANTICS = Z3SemanticBackend(
timeout_ms=DEFAULT_SOLVER_TIMEOUT_MS
)
DEFAULT_REASONING_BACKEND
module-attribute
DEFAULT_REASONING_BACKEND = default_reasoning_backend()
ingest_puzzle
module-attribute
ingest_puzzle = ingest
solve_puzzle
module-attribute
solve_puzzle = PuzzleSolver()
Derivation
dataclass
Source code in src/guardrail_calculus/provenance.py
120 121 122 123 | |
premise_ids
instance-attribute
premise_ids
rule
instance-attribute
rule
ProvenanceDag
dataclass
Bases: Generic[ExprT]
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 src/guardrail_calculus/provenance.py
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 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 | |
from_rustworkx
classmethod
from_rustworkx(graph)
Copy, validate, and adopt a raw interoperability graph.
Source code in src/guardrail_calculus/provenance.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
to_rustworkx
to_rustworkx()
Return a mutable copy for explicit interoperability boundaries.
Source code in src/guardrail_calculus/provenance.py
269 270 271 | |
validate
validate()
Establish the complete typed provenance topology at one boundary.
Source code in src/guardrail_calculus/provenance.py
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 | |
fact
fact(fact_id)
Source code in src/guardrail_calculus/provenance.py
345 346 | |
derivation
derivation(derivation_id)
Source code in src/guardrail_calculus/provenance.py
348 349 | |
explanation
explanation(step_id)
Source code in src/guardrail_calculus/provenance.py
351 352 | |
facts
facts()
Source code in src/guardrail_calculus/provenance.py
354 355 | |
derivation_nodes
derivation_nodes()
Source code in src/guardrail_calculus/provenance.py
357 358 359 360 | |
nodes
nodes()
Source code in src/guardrail_calculus/provenance.py
362 363 364 | |
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 src/guardrail_calculus/provenance.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
in_degree
in_degree(fact_id)
Source code in src/guardrail_calculus/provenance.py
386 387 | |
has_edge
has_edge(source, target)
Source code in src/guardrail_calculus/provenance.py
389 390 391 392 393 394 | |
explanation_node_ids
explanation_node_ids(target_id)
Return the target and every provenance node contributing to it.
Source code in src/guardrail_calculus/provenance.py
407 408 409 410 411 412 413 414 415 416 417 | |
derivations
derivations()
Source code in src/guardrail_calculus/provenance.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
reaches_any
reaches_any(source, targets)
True when source is, or has a directed path to, any target.
Source code in src/guardrail_calculus/provenance.py
439 440 441 442 443 444 445 | |
has_derivation
has_derivation(*, conclusion_id, premise_ids, rule)
Source code in src/guardrail_calculus/provenance.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
with_fact
with_fact(node, *, derivation=None, premises=())
Source code in src/guardrail_calculus/provenance.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
with_derivation
with_derivation(derivation, *, premises, conclusion)
Source code in src/guardrail_calculus/provenance.py
506 507 508 509 510 511 512 513 514 515 516 517 | |
with_explanation
with_explanation(explanation, *, premises, check)
Source code in src/guardrail_calculus/provenance.py
519 520 521 522 523 524 525 526 527 528 529 530 | |
explanation_nodes
explanation_nodes(target_id)
Source code in src/guardrail_calculus/provenance.py
532 533 534 535 536 537 538 539 540 541 542 543 | |
slice_for
slice_for(target_id)
Source code in src/guardrail_calculus/provenance.py
545 546 547 548 549 550 | |
DerivationId
dataclass
Source code in src/guardrail_calculus/provenance.py
58 59 60 61 62 63 | |
value
instance-attribute
value
DerivationInput
dataclass
Bases: Generic[ExprT]
Backend-free view constructible only from a consistent unsaturated graph.
Source code in src/guardrail_calculus/provenance.py
134 135 136 137 138 139 140 141 142 | |
established
instance-attribute
established
slot_dimensions
class-attribute
instance-attribute
slot_dimensions = field(default_factory=dict)
DerivationNode
dataclass
Source code in src/guardrail_calculus/provenance.py
108 109 110 111 | |
id
instance-attribute
id
rule
instance-attribute
rule
DerivationProposal
dataclass
Bases: Generic[ExprT]
Source code in src/guardrail_calculus/provenance.py
126 127 128 129 130 131 | |
conclusion
instance-attribute
conclusion
premises
instance-attribute
premises
rule
instance-attribute
rule
source
class-attribute
instance-attribute
source = None
ExplanationInput
dataclass
Bases: Generic[ExprT]
Backend-free view constructible only from a consistent saturated graph.
Source code in src/guardrail_calculus/provenance.py
145 146 147 148 149 150 | |
established
instance-attribute
established
checks
instance-attribute
checks
ExplanationNode
dataclass
Source code in src/guardrail_calculus/provenance.py
114 115 116 117 | |
id
instance-attribute
id
rule
instance-attribute
rule
ExplanationProposal
dataclass
Source code in src/guardrail_calculus/provenance.py
153 154 155 156 157 | |
check_id
instance-attribute
check_id
premises
instance-attribute
premises
rule
instance-attribute
rule
FactId
dataclass
Source code in src/guardrail_calculus/provenance.py
50 51 52 53 54 55 | |
value
instance-attribute
value
FactKind
Bases: str, Enum
Source code in src/guardrail_calculus/provenance.py
74 75 76 77 | |
GIVEN
class-attribute
instance-attribute
GIVEN = 'GIVEN'
DERIVED
class-attribute
instance-attribute
DERIVED = 'DERIVED'
CHECK
class-attribute
instance-attribute
CHECK = 'CHECK'
FactNode
dataclass
Bases: Generic[ExprT]
Source code in src/guardrail_calculus/provenance.py
97 98 99 100 101 102 103 104 105 | |
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 src/guardrail_calculus/provenance.py
69 70 71 | |
id
instance-attribute
id
SourceSpan
dataclass
Source code in src/guardrail_calculus/provenance.py
83 84 85 86 87 88 89 | |
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
CheckResult
dataclass
A classification verdict plus the witnessing models and unsat cores.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1358 1359 1360 1361 1362 1363 1364 1365 1366 | |
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
EntailsNotary
dataclass
The z3 judgement: premises support a conclusion iff they entail it.
The one notary that existed implicitly before the seam — every
add_derived was an inlined entails call. Spelled as an object so
a conclusion type with a different standard of proof (the dialects'
complete-unless-rogue, whose judge is enumeration, not entailment)
can stand in the same slot without the graph changing.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 | |
notarise
notarise(premises, conclusion, semantics)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1160 1161 1162 1163 1164 1165 1166 | |
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 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 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 | |
dag
class-attribute
instance-attribute
dag = field(default_factory=ProvenanceDag[BoolRef])
by_expr
class-attribute
instance-attribute
by_expr = field(default_factory=dict)
slot_dimensions
class-attribute
instance-attribute
slot_dimensions = 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
142 143 144 | |
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
146 147 148 149 150 151 | |
fact
fact(fact_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
170 171 | |
derivation_step
derivation_step(derivation_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
173 174 | |
add_given
add_given(prop_, *, subject_name, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
add_check
add_check(prop_, *, subject_name, check_label, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
add_derived
add_derived(prop_, *, premises, rule, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
apply_derivation
apply_derivation(proposal)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
apply_derivations
apply_derivations(proposals)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
364 365 366 367 368 369 370 371 372 373 | |
established_facts
established_facts()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
440 441 442 443 | |
base_exprs
base_exprs()
The established facts, plus every mapped slot's declared invariant.
The invariants are not facts anyone authored, so they stay out of
established_facts (and therefore out of the explanation DAG); they
are the same standing assumptions the wire path conjoins into every
analysis base, so a witness can never assign a slot a value its
dimension forbids, and a check the declaration alone entails comes back
VERIFIED rather than UNKNOWN.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |
derivation_input
derivation_input()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
460 461 462 463 464 465 466 | |
explanation_input
explanation_input(checks)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
468 469 470 471 472 473 474 475 476 477 478 479 | |
check_consistent
check_consistent()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
481 482 483 484 485 486 487 488 489 490 | |
saturate
saturate()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
492 493 494 495 496 497 498 499 500 501 502 | |
classify
classify(check)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
504 505 506 507 508 509 510 | |
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
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 | |
explanation_for
explanation_for(target)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
543 544 | |
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
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 | |
explain_check
explain_check(check)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
apply_explanation
apply_explanation(proposal)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
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 | |
FactGraphExplanationBackend
dataclass
Use shared semantic equivalence to propose check explanations.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 | |
explain
explain(input_, semantics)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 | |
ForwardDerivationBackend
dataclass
Current Python fixed-point rules behind the derivation interface.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 | |
derive
derive(input_)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1277 1278 1279 1280 1281 1282 1283 | |
IngestedPuzzle
dataclass
Bases: Generic[PuzzleT]
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1351 1352 1353 1354 1355 | |
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
911 912 913 914 | |
source
instance-attribute
source
offset
instance-attribute
offset
PuzzleSolver
dataclass
Configured callable that solves puzzles with one reasoning backend.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 | |
backend
class-attribute
instance-attribute
backend = field(default_factory=default_reasoning_backend)
graph_factory
class-attribute
instance-attribute
graph_factory = None
ingest
ingest(puzzle)
Parse a puzzle without attaching this solver's backend.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 | |
ReasoningBackend
dataclass
Composite, graph-independent reasoning capabilities.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 | |
semantics
class-attribute
instance-attribute
semantics = Z3_SEMANTICS
algebra
class-attribute
instance-attribute
algebra = Z3_ALGEBRA
notary
class-attribute
instance-attribute
notary = ENTAILS_NOTARY
derivation
class-attribute
instance-attribute
derivation = ForwardDerivationBackend()
explanation
class-attribute
instance-attribute
explanation = FactGraphExplanationBackend()
max_rounds
class-attribute
instance-attribute
max_rounds = 20
SolveResult
dataclass
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
693 694 695 696 697 698 699 700 701 | |
status
instance-attribute
status
model
class-attribute
instance-attribute
model = None
core
class-attribute
instance-attribute
core = ()
steps_used
class-attribute
instance-attribute
steps_used = 0
SolveStatus
Bases: str, Enum
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
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'
INTERRUPTED
class-attribute
instance-attribute
INTERRUPTED = 'INTERRUPTED'
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
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 | |
puzzle
instance-attribute
puzzle
graph
instance-attribute
graph
check_tokens
instance-attribute
check_tokens
Z3ExpressionAlgebra
dataclass
The z3 spelling of :class:ExpressionAlgebra.
Thin on purpose: each method is one of the module-level helpers the graph
used to call directly, so behaviour is identical and the functions stay
independently usable. ingress is as_z3_bool — the one place the
authored frontend's booleans become stored BoolRef values.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 | |
ingress
ingress(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1128 1129 | |
normalise
normalise(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1131 1132 | |
key
key(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1134 1135 | |
render
render(expr, slots)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1137 1138 | |
invariants
invariants(slots)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1140 1141 | |
Z3SemanticBackend
dataclass
Default semantic backend using Z3's solver and unsat cores.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | |
solver_factory
class-attribute
instance-attribute
solver_factory = field(default=Solver, repr=False)
timeout_ms
class-attribute
instance-attribute
timeout_ms = None
rlimit
class-attribute
instance-attribute
rlimit = None
solve
solve(assertions)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
860 861 862 863 864 865 866 867 | |
Consistent
Source code in src/guardrail_calculus/reasoning_contract.py
45 46 | |
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 src/guardrail_calculus/reasoning_contract.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
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 src/guardrail_calculus/reasoning_contract.py
92 93 94 95 96 97 98 99 100 101 102 | |
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 src/guardrail_calculus/reasoning_contract.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
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
61 62 63 64 65 66 67 | |
derive
derive(input_)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
64 65 66 67 | |
DerivationNotary
Bases: Protocol[ExprT_contra, SemanticsT_contra]
Judge whether premises genuinely support a proposed conclusion.
Phase 7b's insertion-gate seam. A graph refuses any step its notary
does not prove, and its re-audit re-asks the same judge — the gate is
the graph's, the judgement the backend's. For z3 expressions the judge
is entails (guardrail_solver.reasoning.EntailsNotary); a
different conclusion type brings its own — the dialects'
complete-unless-rogue needs enumeration of the graph for rogue
facts, which no entails call can decide. Answers the three-valued
:class:Entailment, never a bool: "the solver gave up" must not read
as either verdict.
Source code in src/guardrail_calculus/reasoning_contract.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
notarise
notarise(premises, conclusion, semantics)
Source code in src/guardrail_calculus/reasoning_contract.py
254 255 256 257 258 259 | |
Evidence
Phantom evidence carried by a graph's static type.
Source code in src/guardrail_calculus/reasoning_contract.py
57 58 | |
ExplanationBackend
Bases: Protocol
Propose explanation edges without mutating the fact graph.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
70 71 72 73 74 75 76 77 | |
explain
explain(input_, semantics)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
73 74 75 76 77 | |
ExpressionAlgebra
Bases: Protocol[IngressT_contra, ExprT]
Everything a graph does to an expression that is not a solver query.
Phase 7b's keying seam. FactGraph used to call as_z3_bool,
simplify, expr_key, render_fact and slot_invariant_terms
directly, which is precisely what kept the graph z3-bound after the
vocabulary stopped being so: identity, normalisation, ingress and
rendering are operations on the expression type, so they belong to the
backend that owns that type. The z3 spelling lives in
guardrail_solver.reasoning.Z3ExpressionAlgebra; a dialect backend
supplies its own over an AST-derived proposition type, and a graph
never needs to know which.
Two parameters because ingress and storage may be different types: what
an algebra accepts (the z3 algebra takes the solver's Boolish_Bound
union of authored spellings) is not what it stores (BoolRef). Where
nothing wider than the stored type exists to lower from, the two
coincide — the dialect algebra is [DialectProp, DialectProp] and
its ingress is identity.
Source code in src/guardrail_calculus/reasoning_contract.py
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 | |
ingress
ingress(expr)
Lower an authored or raw proposition into the stored type.
Source code in src/guardrail_calculus/reasoning_contract.py
206 207 208 | |
normalise
normalise(expr)
Canonicalise a stored expression; feeds :meth:key and display.
Source code in src/guardrail_calculus/reasoning_contract.py
210 211 212 | |
key
key(expr)
The identity under which a graph deduplicates this expression.
Source code in src/guardrail_calculus/reasoning_contract.py
214 215 216 | |
render
render(expr, slots)
Default human text for a fact nobody captioned.
Source code in src/guardrail_calculus/reasoning_contract.py
218 219 220 | |
invariants
invariants(slots)
Standing assumptions the mapped slots' declarations imply.
Source code in src/guardrail_calculus/reasoning_contract.py
222 223 224 | |
ReasoningGraphBackend
Bases: Protocol[StateT_co]
The contract a fact-graph engine must satisfy to back PuzzleSolver.
Mirrors FactGraph's own phantom-typestate contract method for
method, not a looser paraphrase of it: which methods are callable in
which Evidence[ConsistencyT, SaturationT] state is a property of the
interface every conforming graph must uphold (checked before
saturated, saturated before its explanation is computed, ...), not an
artifact of FactGraph's own implementation -- so a future
implementation is held to the same illegal-call-sequences-are-a-type-error
guarantee FactGraph already gives its own direct callers, not a
weaker one just because it goes through this seam.
Deliberately looser on one axis: add_given/add_check carry
Prop[Any]/FactToken[Any] rather than FactGraph's own
[E: Boolish_Bound] value-level generic -- an orthogonal precision
axis from the state invariants above, out of scope here.
@runtime_checkable only checks method presence, not signatures --
enough for a lightweight isinstance sanity probe, not a substitute
for real type-checking at the call sites.
.dag's ProvenanceDag return type is Python/rustworkx-shaped as of
this writing: there is no non-Python graph engine yet, so this describes
the one real implementation rather than a speculative abstraction over a
shape nothing has needed yet -- revisit if/when a second one exists.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
nodes
property
nodes
reasoning_backend
property
reasoning_backend
dag
property
dag
add_given
add_given(prop_, *, subject_name, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
109 110 111 112 113 114 115 116 117 | |
add_check
add_check(prop_, *, subject_name, check_label, source=None)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
119 120 121 122 123 124 125 126 | |
with_reasoning_backend
with_reasoning_backend(backend)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
128 129 130 131 | |
check_consistent
check_consistent()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
133 134 135 | |
saturate
saturate()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
137 138 139 | |
explanation_input
explanation_input(checks)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
141 142 143 144 | |
apply_explanation
apply_explanation(proposal)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
146 147 148 149 | |
classify
classify(check)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
151 152 153 154 | |
verify_derivations
verify_derivations()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
156 | |
fact
fact(fact_id)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
158 | |
explanation_for
explanation_for(target)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
160 | |
base_exprs
base_exprs()
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
162 | |
Saturated
Source code in src/guardrail_calculus/reasoning_contract.py
53 54 | |
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
55 56 57 58 | |
solve
solve(assertions)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/types.py
58 | |
Unchecked
Source code in src/guardrail_calculus/reasoning_contract.py
41 42 | |
Unsaturated
Source code in src/guardrail_calculus/reasoning_contract.py
49 50 | |
empty_rustworkx_digraph
empty_rustworkx_digraph()
Source code in src/guardrail_calculus/provenance.py
225 226 | |
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 src/guardrail_calculus/provenance.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
explanation_lines
explanation_lines(dag, target_id)
Render the explanation walk for target_id over any provenance DAG.
Shared by FactGraph.explanation_for and the Rust engine's wrapper
(rust.RustFactGraph), which reconstructs the same ProvenanceDag
shape from its engine snapshot -- one formatting loop, not two.
Source code in src/guardrail_calculus/provenance.py
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 | |
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
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
arith_key
arith_key(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1003 1004 | |
as_bool_ref
as_bool_ref(expr)
Narrow a z3 expression to a boolean, refusing anything else.
isinstance rather than cast: BoolRef is a real class now that z3 is a
followed import, so this can be checked instead of asserted. It was
cast(BoolRef, expr) — a bare "trust me" over object, which is the one
shape that cannot be wrong at the point it is written and cannot be right
anywhere else either.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
880 881 882 883 884 885 886 887 888 889 890 891 | |
as_int
as_int(expr)
The Python value of an integer numeral, or None.
isinstance(expr, IntNumRef) in place of is_int_value plus a cast: the two
agree exactly (verified across numerals, symbols and folded expressions), and
one of them narrows. is_int_value answers bool, so it left the cast to
assert what it had just established.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
898 899 900 901 902 903 904 905 906 907 908 | |
check_with_core
check_with_core(
base,
extra,
*,
solver_factory=Solver,
timeout_ms=None,
rlimit=None
)
Low-level Z3 solve retaining a model, unsat core, or unknown result.
timeout_ms and rlimit bound the solve: a query exceeding either
returns SolveStatus.TIMEOUT rather than running unbounded, so a small
but solver-expensive request cannot exhaust the service. They bound
different things and are set together. timeout measures elapsed time,
so it describes the host; rlimit counts z3's internal steps, so the same
query costs the same everywhere. Only rlimit makes the budget a property
of the request, and only timeout covers the work outside z3.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
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 | |
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
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 | |
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
1405 1406 1407 1408 1409 1410 | |
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
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | |
equality_sides
equality_sides(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
951 952 953 954 955 956 957 958 | |
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
754 755 756 757 758 759 760 761 762 763 764 | |
expr_key
expr_key(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
999 1000 | |
is_eq
is_eq(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
894 895 | |
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
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 | |
parse_constant_equality
parse_constant_equality(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
parse_offset_equality
parse_offset_equality(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
print_core
print_core(core)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1413 1414 1415 | |
render_arith
render_arith(expr)
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1007 1008 | |
render_fact
render_fact(expr, slots=None)
Render a z3 fact as a sentence, driven by declared dimension data.
slots maps slot names to their dimension records (see
FactGraph.slot_dimensions); a mapped slot's constants render through
the dimension's declared DisplayFormat and its offsets carry the
declared displacement unit. Unmapped variables render plainly — this
function assumes no dimension it was not told about.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | |
default_reasoning_backend
cached
default_reasoning_backend()
Build the shared default backend on first use, not at import.
Two callers, two reasons. FactGraph's field default uses it so the
graph dataclass can precede the backend classes in this module. And it is
the module's laziness seam: DEFAULT_REASONING_BACKEND is served
through __getattr__ below rather than built at import, so a module
that only wants the vocabulary never pays for backend construction —
the coupling Phase 7b's split exists to remove.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/_python.py
95 96 97 98 99 100 101 102 103 104 105 106 | |
explanation_proposals_from_matches
explanation_proposals_from_matches(matches)
Reconstruct ExplanationProposals from a structural engine's match
output (check_id/premise_id pairs). The rule text is deliberately
distinct from FactGraphExplanationBackend's "check is equivalent to a
known fact": the structural engine matched normalised shapes, not full
semantic equivalence, and the provenance record should say so.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/records.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
linear_records
linear_records(nodes)
Flatten facts into opaque, JSON-ready records a structural engine can
compare by key, plus a lookup resolving each key back to its live
ArithRef.
Shared by RustDerivationBackend/RustExplanationBackend: the shape
is identical for DerivationInput.established and
ExplanationInput.established/.checks -- a check is just another
FactNode. Only the caller's use of the records differs. A structural
engine only ever compares key/target_key/source_key for
equality -- it never needs to interpret the ArithRef they stand for,
which is why crossing the FFI boundary as opaque strings is sufficient.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/records.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
proposals_from_records
proposals_from_records(
proposals, lookup, slot_dimensions=None
)
Reconstruct DerivationProposals from a structural engine's flat,
opaque-keyed output, resolving each key back to the live ArithRef it
came from. The engine itself never constructs or returns a z3 expression.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/records.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
dag_to_d3_html
dag_to_d3_html(
dag, *, element_id="reasoning-d3", library="cytoscape"
)
Render a provenance DAG as a self-contained HTML snippet.
The other half of dag_to_d3_payload. That one landed without this, which
left the promise it was added for only half kept: a client holding a
service response could compute the payload but not the page, and the one
consumer that wants a page -- a notebook cell -- is exactly the client that
has no FactGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
ProvenanceDag[ExprT]
|
The provenance DAG 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
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 | |
dag_to_d3_payload
dag_to_d3_payload(dag, *, library='cytoscape')
Build the JSON-able payload (meta/nodes/links) for a provenance DAG.
The DAG is all the renderer ever reads — rows come from the node kinds and
links from the edges — so this, not
graph_to_d3_payload, is
the primitive. It is also what makes from_wire_explanation_dag's
promise ("the renderers can walk it") literally true: a client holding
nothing but a service response's WireExplanationDag can rebuild the DAG
and render it, with no engine, no z3 and no FactGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
ProvenanceDag[ExprT]
|
The provenance DAG 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
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 | |
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
|
ReasoningGraphBackend[StateT]
|
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
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 | |
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
|
ReasoningGraphBackend[StateT]
|
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
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 | |
algebra_table
algebra_table(rules)
An | Operation | Result | table of a dimension's closure rules.
Signature-sorted for a deterministic build. The rules are whatever the dimension's declared structure derived, so the table cannot list an operator the algebra does not actually admit.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
318 319 320 321 322 323 324 325 326 327 328 | |
checks_verdict_table
checks_verdict_table(solved)
A | Check | Proposition | Verdict | table for every check in a puzzle.
Classifies each check against the solved graph's own base facts, so the verdicts are produced here rather than restated: the caller supplies only which puzzle to solve. Checks are label-sorted for a deterministic build.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
classification_table
classification_table(rows)
A | Proposition | Verdict | Model | table for classified candidates.
Each row is (proposition source, response). The model column is the
assignment the classifier returned -- a satisfying example, deliberately
not labelled "counterexample" the way the invariant table's column is, since
a classification's model witnesses whichever of the two questions was
answered first. Rendered by the same :func:render_assignments every other
result table uses, so an absent model reads as none rather than as a
blank cell.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
coverage_block
coverage_block(response)
A coverage response as a fenced text block.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
231 232 233 234 235 236 237 238 239 | |
decision_block
decision_block(response)
A decision response as a fenced text block.
Overlaps read as prose rather than as raw tuples: an index pair alone does not say what went wrong, and the witness is the part a reader acts on.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
invariant_table
invariant_table(rows)
A | Precondition | Verdict | Counterexample | table.
Each row is (precondition source, response). A precondition of
"(none)" renders as emphasised prose rather than code, since an absent
precondition is not a snippet a reader could copy.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
normalized_block
normalized_block(ir)
Normalized IR as a fenced text block: what each slot resolved to.
The counts and mappings come off the IR itself, so this reports what the normalizer inferred rather than what a page expected it to infer.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
331 332 333 334 335 336 337 338 339 340 341 342 343 | |
rejection_table
rejection_table(rows)
A | Expression | Rejected with | table of real, raised exceptions.
Each row is (expression source, the exception it raised). Only the
message's first line is shown, truncated: some rejections quote the whole
operand record, and a table cell carrying a repr of an entire dimension
declaration communicates less than its first clause does. Truncation is
presentation -- the type and the leading text are the exception's own, so a
page cannot claim a rejection the library did not make.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
render_assignment
render_assignment(value)
One witness/counterexample value, rendered for a documentation reader.
Rationals become exact fractions (1/5, or just 3 when the
denominator is 1) rather than decimals, strings are quoted so an empty or
space-carrying value is still visible, and everything else falls back to
str.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
render_assignments
render_assignments(values)
A whole witness/counterexample mapping, key-sorted for determinism.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
204 205 206 207 208 209 210 211 | |
verdict_badge
verdict_badge(status)
A verdict as a badge-classed inline code span (attr_list syntax).
Raises KeyError for an unrecognised verdict rather than emitting an
unstyled word: a silently unstyled badge on a published page is exactly the
kind of quiet drift routing docs through this module is meant to prevent.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
verdict_status_name
verdict_status_name(status)
The wire name of a verdict, accepting either an enum or a bare string.
Reads .value before falling back, which is load-bearing rather than
defensive: Status is a str subclass, so an isinstance(status, str)
check passes for a real verdict and would hand back the member itself --
whose str() is "Status.VERIFIED", not "VERIFIED". Verified
directly against Status rather than assumed.
Source code in packages/guardrail-solver/src/guardrail_solver/reasoning/renderers/markdown.py
152 153 154 155 156 157 158 159 160 161 162 163 164 | |
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
|
ReasoningGraphBackend[StateT]
|
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
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 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 | |
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[StateT]
|
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
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 | |
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
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
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
248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
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
213 214 215 216 217 218 219 220 221 | |