Skip to content

Commit e241ec3

Browse files
Merge pull request aden-hive#179 from PatrickChen928/main
feat: add nullable_output_keys, fix: aden-hive#178
2 parents f30f42a + 5fbaae5 commit e241ec3

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

core/framework/graph/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ async def execute(
317317
output=result.output,
318318
expected_keys=node_spec.output_keys,
319319
check_hallucination=True,
320+
nullable_keys=node_spec.nullable_output_keys,
320321
)
321322
if not validation.success:
322323
self.logger.error(f" ✗ Output validation failed: {validation.error}")

core/framework/graph/node.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ class NodeSpec(BaseModel):
163163
output_keys: list[str] = Field(
164164
default_factory=list, description="Keys this node writes to shared memory or output"
165165
)
166+
nullable_output_keys: list[str] = Field(
167+
default_factory=list,
168+
description="Output keys that can be None without triggering validation errors"
169+
)
166170

167171
# Optional schemas for validation and cleansing
168172
input_schema: dict[str, dict] = Field(

core/framework/graph/validator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def validate_output_keys(
102102
output: dict[str, Any],
103103
expected_keys: list[str],
104104
allow_empty: bool = False,
105+
nullable_keys: list[str] | None = None,
105106
) -> ValidationResult:
106107
"""
107108
Validate that all expected keys are present and non-empty.
@@ -110,11 +111,13 @@ def validate_output_keys(
110111
output: The output dict to validate
111112
expected_keys: Keys that must be present
112113
allow_empty: If True, allow empty string values
114+
nullable_keys: Keys that are allowed to be None
113115
114116
Returns:
115117
ValidationResult with success status and any errors
116118
"""
117119
errors = []
120+
nullable_keys = nullable_keys or []
118121

119122
if not isinstance(output, dict):
120123
return ValidationResult(
@@ -127,7 +130,8 @@ def validate_output_keys(
127130
elif not allow_empty:
128131
value = output[key]
129132
if value is None:
130-
errors.append(f"Output key '{key}' is None")
133+
if key not in nullable_keys:
134+
errors.append(f"Output key '{key}' is None")
131135
elif isinstance(value, str) and len(value.strip()) == 0:
132136
errors.append(f"Output key '{key}' is empty string")
133137

@@ -273,6 +277,7 @@ def validate_all(
273277
expected_keys: list[str] | None = None,
274278
schema: dict[str, Any] | None = None,
275279
check_hallucination: bool = True,
280+
nullable_keys: list[str] | None = None,
276281
) -> ValidationResult:
277282
"""
278283
Run all applicable validations on output.
@@ -282,6 +287,7 @@ def validate_all(
282287
expected_keys: Optional list of required keys
283288
schema: Optional JSON schema
284289
check_hallucination: Whether to check for hallucination patterns
290+
nullable_keys: Keys that are allowed to be None
285291
286292
Returns:
287293
Combined ValidationResult
@@ -290,7 +296,7 @@ def validate_all(
290296

291297
# Validate keys if provided
292298
if expected_keys:
293-
result = self.validate_output_keys(output, expected_keys)
299+
result = self.validate_output_keys(output, expected_keys, nullable_keys=nullable_keys)
294300
all_errors.extend(result.errors)
295301

296302
# Validate schema if provided

0 commit comments

Comments
 (0)