vellum-ai 0.14.57__py3-none-any.whl → 0.14.58__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ class BaseClientWrapper:
18
18
  headers: typing.Dict[str, str] = {
19
19
  "X-Fern-Language": "Python",
20
20
  "X-Fern-SDK-Name": "vellum-ai",
21
- "X-Fern-SDK-Version": "0.14.57",
21
+ "X-Fern-SDK-Version": "0.14.58",
22
22
  }
23
23
  headers["X-API-KEY"] = self.api_key
24
24
  return headers
@@ -351,6 +351,9 @@ class BaseNode(Generic[StateType], metaclass=BaseNodeMeta):
351
351
  return execution_id
352
352
 
353
353
  if cls.merge_behavior not in {MergeBehavior.AWAIT_ANY, MergeBehavior.AWAIT_ALL}:
354
+ # Keep track of the dependencies that have invoked this node
355
+ # This would be needed while climbing the history in the loop
356
+ state.meta.node_execution_cache._dependencies_invoked[execution_id].add(invoked_by)
354
357
  return execution_id
355
358
 
356
359
  for queued_node_execution_id in state.meta.node_execution_cache._node_executions_queued[cls.node_class]:
@@ -37,6 +37,7 @@ class GuardrailNode(BaseNode[StateType], Generic[StateType]):
37
37
  score: float
38
38
  normalized_score: Optional[float]
39
39
  log: Optional[str]
40
+ reason: Optional[str]
40
41
 
41
42
  def run(self) -> Outputs:
42
43
  try:
@@ -54,10 +55,10 @@ class GuardrailNode(BaseNode[StateType], Generic[StateType]):
54
55
  )
55
56
 
56
57
  metric_outputs = {output.name: output.value for output in metric_execution.outputs}
57
-
58
58
  SCORE_KEY = "score"
59
59
  NORMALIZED_SCORE_KEY = "normalized_score"
60
60
  LOG_KEY = "log"
61
+ REASON_KEY = "reason"
61
62
 
62
63
  score = metric_outputs.get(SCORE_KEY)
63
64
  if not isinstance(score, float):
@@ -87,7 +88,17 @@ class GuardrailNode(BaseNode[StateType], Generic[StateType]):
87
88
  else:
88
89
  log = None
89
90
 
90
- return self.Outputs(score=score, normalized_score=normalized_score, log=log, **metric_outputs)
91
+ if REASON_KEY in metric_outputs:
92
+ reason = metric_outputs.pop(REASON_KEY) or ""
93
+ if not isinstance(reason, str):
94
+ raise NodeException(
95
+ message="Metric execution reason output must be of type 'str'",
96
+ code=WorkflowErrorCode.INVALID_OUTPUTS,
97
+ )
98
+ else:
99
+ reason = None
100
+
101
+ return self.Outputs(score=score, normalized_score=normalized_score, log=log, reason=reason, **metric_outputs)
91
102
 
92
103
  def _compile_metric_inputs(self) -> List[MetricDefinitionInput]:
93
104
  # TODO: We may want to consolidate with prompt deployment input compilation
@@ -102,6 +102,35 @@ def test_run_guardrail_node__normalized_score_null(vellum_client):
102
102
  assert exc_info.value.code == WorkflowErrorCode.INVALID_OUTPUTS
103
103
 
104
104
 
105
+ def test_run_guardrail_node__reason(vellum_client):
106
+ # GIVEN a Guardrail Node
107
+ class MyGuard(GuardrailNode):
108
+ metric_definition = "example_metric_definition"
109
+ metric_inputs = {}
110
+
111
+ # AND we know that the guardrail node will return a reason
112
+ mock_metric_execution = MetricDefinitionExecution(
113
+ outputs=[
114
+ TestSuiteRunMetricNumberOutput(
115
+ name="score",
116
+ value=0.6,
117
+ ),
118
+ TestSuiteRunMetricStringOutput(
119
+ name="reason",
120
+ value="foo",
121
+ ),
122
+ ],
123
+ )
124
+ vellum_client.metric_definitions.execute_metric_definition.return_value = mock_metric_execution
125
+
126
+ # WHEN we run the Guardrail Node
127
+ outputs = MyGuard().run()
128
+
129
+ # THEN the workflow should have completed successfully
130
+ assert outputs.score == 0.6
131
+ assert outputs.reason == "foo"
132
+
133
+
105
134
  def test_run_guardrail_node__api_error(vellum_client):
106
135
  # GIVEN a Guardrail Node
107
136
  class MyGuard(GuardrailNode):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vellum-ai
3
- Version: 0.14.57
3
+ Version: 0.14.58
4
4
  Summary:
5
5
  License: MIT
6
6
  Requires-Python: >=3.9,<4.0
@@ -134,7 +134,7 @@ vellum/client/README.md,sha256=qmaVIP42MnxAu8jV7u-CsgVFfs3-pHQODrXdZdFxtaw,4749
134
134
  vellum/client/__init__.py,sha256=AYopGv2ZRVn3zsU8_km6KOvEHDbXiTPCVuYVI7bWvdA,120166
135
135
  vellum/client/core/__init__.py,sha256=SQ85PF84B9MuKnBwHNHWemSGuy-g_515gFYNFhvEE0I,1438
136
136
  vellum/client/core/api_error.py,sha256=RE8LELok2QCjABadECTvtDp7qejA1VmINCh6TbqPwSE,426
137
- vellum/client/core/client_wrapper.py,sha256=_EpiaQiW5UAD1sRXFFvLrUvOC6rmy_NfC-rEQVH-5vg,1869
137
+ vellum/client/core/client_wrapper.py,sha256=R8Gd1E7CHopB46ObgpI6tGq-bCfkRm3SWdY8w8PzUQU,1869
138
138
  vellum/client/core/datetime_utils.py,sha256=nBys2IsYrhPdszxGKCNRPSOCwa-5DWOHG95FB8G9PKo,1047
139
139
  vellum/client/core/file.py,sha256=d4NNbX8XvXP32z8KpK2Xovv33nFfruIrpz0QWxlgpZk,2663
140
140
  vellum/client/core/http_client.py,sha256=Z77OIxIbL4OAB2IDqjRq_sYa5yNYAWfmdhdCSSvh6Y4,19552
@@ -1548,7 +1548,7 @@ vellum/workflows/inputs/tests/test_inputs.py,sha256=lioA8917mFLYq7Ml69UNkqUjcWbb
1548
1548
  vellum/workflows/logging.py,sha256=_a217XogktV4Ncz6xKFz7WfYmZAzkfVRVuC0rWob8ls,437
1549
1549
  vellum/workflows/nodes/__init__.py,sha256=aVdQVv7Y3Ro3JlqXGpxwaU2zrI06plDHD2aumH5WUIs,1157
1550
1550
  vellum/workflows/nodes/bases/__init__.py,sha256=cniHuz_RXdJ4TQgD8CBzoiKDiPxg62ErdVpCbWICX64,58
1551
- vellum/workflows/nodes/bases/base.py,sha256=Su8FRFwAzF-Q-PP37a5uTg4RyVv6AZZzB26UIdbGY0w,17575
1551
+ vellum/workflows/nodes/bases/base.py,sha256=gXhhqD1DYRPyIDnkUkpLAqb5m2feWZBvxOm5PL3NUqA,17830
1552
1552
  vellum/workflows/nodes/bases/base_adornment_node.py,sha256=Ao2opOW4kgNoYXFF9Pk7IMpVZdy6luwrjcqEwU5Q9V0,3404
1553
1553
  vellum/workflows/nodes/bases/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1554
1554
  vellum/workflows/nodes/bases/tests/test_base_adornment_node.py,sha256=fXZI9KqpS4XMBrBnIEkK3foHaBVvyHwYcQWWDKay7ic,1148
@@ -1611,8 +1611,8 @@ vellum/workflows/nodes/displayable/final_output_node/node.py,sha256=PuQ0RvtAmoSI
1611
1611
  vellum/workflows/nodes/displayable/final_output_node/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1612
1612
  vellum/workflows/nodes/displayable/final_output_node/tests/test_node.py,sha256=E6LQ74qZjY4Xi4avx2qdOCgGhF8pEcNLBh8cqYRkzMI,709
1613
1613
  vellum/workflows/nodes/displayable/guardrail_node/__init__.py,sha256=Ab5eXmOoBhyV4dMWdzh32HLUmnPIBEK_zFCT38C4Fng,68
1614
- vellum/workflows/nodes/displayable/guardrail_node/node.py,sha256=d7C6M6aIZ33GyjIxn24Vd-xyWMGtxm6Hs8nszyl4tNU,5356
1615
- vellum/workflows/nodes/displayable/guardrail_node/test_node.py,sha256=KkLog-bjvPaUZUBciMH25lRHA5pDIrmUxNLVWY6oU34,4526
1614
+ vellum/workflows/nodes/displayable/guardrail_node/node.py,sha256=oBqQ0eAhALkGL64aAqEKP5lmQxvgYMJ2BeDD8cnLJE8,5813
1615
+ vellum/workflows/nodes/displayable/guardrail_node/test_node.py,sha256=SAGv6hSFcBwQkudn1VxtaKNsXSXWWELl3eK05zM6tS0,5410
1616
1616
  vellum/workflows/nodes/displayable/guardrail_node/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1617
1617
  vellum/workflows/nodes/displayable/guardrail_node/tests/test_node.py,sha256=X2pd6TI8miYxIa7rgvs1pHTEreyWcf77EyR0_Jsa700,2055
1618
1618
  vellum/workflows/nodes/displayable/inline_prompt_node/__init__.py,sha256=gSUOoEZLlrx35-tQhSAd3An8WDwBqyiQh-sIebLU9wU,74
@@ -1712,8 +1712,8 @@ vellum/workflows/workflows/event_filters.py,sha256=GSxIgwrX26a1Smfd-6yss2abGCnad
1712
1712
  vellum/workflows/workflows/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1713
1713
  vellum/workflows/workflows/tests/test_base_workflow.py,sha256=fROqff6AZpCIzaSwOKSdtYy4XR0UZQ6ejxL3RJOSJVs,20447
1714
1714
  vellum/workflows/workflows/tests/test_context.py,sha256=VJBUcyWVtMa_lE5KxdhgMu0WYNYnUQUDvTF7qm89hJ0,2333
1715
- vellum_ai-0.14.57.dist-info/LICENSE,sha256=hOypcdt481qGNISA784bnAGWAE6tyIf9gc2E78mYC3E,1574
1716
- vellum_ai-0.14.57.dist-info/METADATA,sha256=pTa-nZ9dKmyVKaYNeWOzaniqxEoeIMGubwYDNT_WB_w,5484
1717
- vellum_ai-0.14.57.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
1718
- vellum_ai-0.14.57.dist-info/entry_points.txt,sha256=HCH4yc_V3J_nDv3qJzZ_nYS8llCHZViCDP1ejgCc5Ak,42
1719
- vellum_ai-0.14.57.dist-info/RECORD,,
1715
+ vellum_ai-0.14.58.dist-info/LICENSE,sha256=hOypcdt481qGNISA784bnAGWAE6tyIf9gc2E78mYC3E,1574
1716
+ vellum_ai-0.14.58.dist-info/METADATA,sha256=0p-sltZKUHnvpKAUPJHAdhM6d_4LGg2R0z5PlgIb3Jg,5484
1717
+ vellum_ai-0.14.58.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
1718
+ vellum_ai-0.14.58.dist-info/entry_points.txt,sha256=HCH4yc_V3J_nDv3qJzZ_nYS8llCHZViCDP1ejgCc5Ak,42
1719
+ vellum_ai-0.14.58.dist-info/RECORD,,