Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/modelplane/evaluator/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ class FailedDAGOutput(_DAGOutput):
error: Exception


class NodeExecutionError(Exception):
def __init__(self, node_name: str, original_error: Exception):
self.node_name = node_name
self.original_error = original_error
super().__init__(
f"Error while executing node '{node_name}': {original_error}"
)


class Composer:
"""DAG of ComposerNodes.

Expand Down Expand Up @@ -225,9 +234,10 @@ def _run_traced(
try:
output = self._run_node(node, ctx)
except Exception as e:
wrapped_error = NodeExecutionError(node.name, e)
return (
FailedDAGOutput(
node_outputs=node_outputs, total_cost=total_cost, error=e
node_outputs=node_outputs, total_cost=total_cost, error=wrapped_error
),
traversed_edges,
)
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/evaluator/test_safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from modelgauge.prompt import TextPrompt
from modelgauge.sut import SUTResponse

from modelplane.evaluator.dag import Composer, FailedDAGOutput
from modelplane.evaluator.dag import Composer, FailedDAGOutput, NodeExecutionError
from modelplane.evaluator.safety import AnnotatorArbiter, Safety, SafetyDAGAnnotator
from modelplane.evaluator.verdict import Verdict

Expand Down Expand Up @@ -50,13 +50,14 @@ def test_safety_dag_with_bad_node(sample_ctx, threshold_arbiter):
)
dag_output = dag.run(sample_ctx)
assert isinstance(dag_output, FailedDAGOutput)
assert str(dag_output.error) == "I'm afraid I can't do that, Dave."
assert str(dag_output.error.original_error) == "I'm afraid I can't do that, Dave."

dag_annotator = SafetyDAGAnnotator("safety_annotator", dag)
with pytest.raises(
type(dag_output.error), match="I'm afraid I can't do that, Dave."
):
NodeExecutionError, match="Error while executing node 'failing_node': I'm afraid I can't do that, Dave."
) as e:
dag_annotator.process(
prompt=TextPrompt(text=sample_ctx.prompt),
response=SUTResponse(text=sample_ctx.response),
)
assert type(e.value.original_error) == type(dag_output.error)
Loading