Return the validated decision, or ``None`` and the failure reason.
(
record: RouteRecord | GuardrailRecord,
model: type[ChoiceDecision] | type[NoulDecision],
)
| 471 | |
| 472 | |
| 473 | def _parse_decision( |
| 474 | record: RouteRecord | GuardrailRecord, |
| 475 | model: type[ChoiceDecision] | type[NoulDecision], |
| 476 | ) -> tuple[ChoiceDecision | NoulDecision | None, str]: |
| 477 | """Return the validated decision, or ``None`` and the failure reason.""" |
| 478 | if record.error is not None: |
| 479 | return None, f"recorded error: {record.error}" |
| 480 | if record.decision is None: |
| 481 | return None, "missing decision" |
| 482 | try: |
| 483 | return model.model_validate(record.decision), "" |
| 484 | except ValidationError as e: |
| 485 | first = e.errors()[0] |
| 486 | location = ".".join(str(part) for part in first["loc"]) or "decision" |
| 487 | return None, f"invalid {model.__name__}: {location}: {first['msg']}" |
| 488 | |
| 489 | |
| 490 | def _classify_route( |
no test coverage detected