Skip to content

Commit 98dfda9

Browse files
nhortonclaude
andcommitted
fix: move yaml import to top-level and narrow exception handling
- Move `import yaml` from loop body to module-level (PyYAML is a runtime dep) - Narrow `except Exception` to `(yaml.YAMLError, UnicodeDecodeError)` - Fix doc wording: remove stale "based on file extension" references - Fix extra blank line flagged by ruff Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 412d85f commit 98dfda9

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

doc/job_yml_guidance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ You define quality criteria once, and they apply everywhere. If three workflows
6464

6565
### `json_schema`
6666

67-
Only applies to `file_path` arguments. When set, the framework parses each output file (JSON or YAML based on file extension) and validates it against the schema **before any reviews run**. If validation fails, `finished_step` returns the error immediately -- reviews are skipped entirely. This is a hard gate, not a soft review. Use for structured outputs where format correctness is non-negotiable.
67+
Only applies to `file_path` arguments. When set, the framework parses each output file (JSON or YAML -- both are supported since YAML is a JSON superset) and validates it against the schema **before any reviews run**. If validation fails, `finished_step` returns the error immediately -- reviews are skipped entirely. This is a hard gate, not a soft review. Use for structured outputs where format correctness is non-negotiable.
6868

6969
---
7070

@@ -152,7 +152,7 @@ A map of step_argument names to output configuration. When the agent calls `fini
152152

153153
1. **Completeness**: All required outputs must be present. No unknown output names allowed.
154154
2. **Type validation**: `file_path` values must point to existing files. `string` values must be strings.
155-
3. **JSON schema**: If the step_argument has `json_schema`, file contents are parsed (JSON or YAML based on extension) and validated. Failures are returned immediately; reviews are skipped.
155+
3. **JSON schema**: If the step_argument has `json_schema`, file contents are parsed (JSON or YAML) and validated. Failures are returned immediately; reviews are skipped.
156156
4. **Quality reviews**: Dynamic reviews from the output ref and step_argument, plus .deepreview rules.
157157

158158
**Important**: The agent must provide ALL required outputs on every `finished_step` call, even outputs whose files have not changed since a previous attempt. The framework re-validates everything each time.

src/deepwork/jobs/mcp/quality_gate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import logging
1111
from pathlib import Path
1212

13+
import yaml
14+
1315
from deepwork.deepschema.review_bridge import generate_review_rules as gen_schema_rules
1416
from deepwork.jobs.mcp.schemas import ArgumentValue
1517
from deepwork.jobs.parser import (
@@ -58,11 +60,9 @@ def validate_json_schemas(
5860
if not full_path.exists():
5961
continue
6062
try:
61-
import yaml
62-
6363
content = full_path.read_text(encoding="utf-8")
6464
parsed = yaml.safe_load(content)
65-
except Exception as e:
65+
except (yaml.YAMLError, UnicodeDecodeError) as e:
6666
errors.append(f"Output '{output_name}' file '{path}': failed to parse: {e}")
6767
continue
6868

tests/unit/jobs/mcp/test_quality_gate.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ def test_fails_when_yaml_file_violates_schema(self, tmp_path: Path) -> None:
192192
assert len(errors) == 1
193193
assert "schema validation failed" in errors[0]
194194

195-
196-
197195
# ---------------------------------------------------------------------------
198196
# TestBuildDynamicReviewRules
199197
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)